قالب وردپرس درنا توس
Home / Tips and Tricks / How to create a simple bot in Microsoft Teams – CloudSavvy IT

How to create a simple bot in Microsoft Teams – CloudSavvy IT



Microsoft Teams logo cartoon

One of the most powerful features of Microsoft Teams is the ability to create and connect bots. These bots enable conversational and transactional functions to create more complex tasks in an easier way.

In addition to actually coding a bot for useful tasks, implementing the infrastructure was a challenge. This is because bots usually need web service support configured in a certain way. Therefore, building and testing a bot quickly is more of a challenge.

Microsoft has created a Web App Bot service that powers up all the necessary infrastructure so that you can quickly start developing, testing, and finally releasing that bot for teams. This article will show you how to quickly get started with the Echo-Bot template.

Create a web app bot

The quickest way to create a new Web App Bot is to use the Microsoft Portal Search feature to find the Web App Bot in the marketplace under the Bot Services service.

Find the Web App bot in the marketplace under the Bot Services service

Once you have clicked on the Web App Bot, you will be directed to a wizard that will provide your bot and the required configurations.

  • Bot handle: lctestbot
    • This is a unique handle that must be different from existing bots as it lives on azurewebsites.net.
  • Subscription: {Tenant subscription}
  • Resource group: {Resource group for the bot}
  • Place: {Place where the bot should be placed}
  • Price-level: $ 1 (1k Premium Msgs / Unit)
    • There is also a 10k option.
  • App name: lctestbot
  • Bot template: Echo Bot (C #)
  • App Service Plan / Location: lctestbot/Central US
    • By default, you have to click on it to create a new location.
  • Application knowledge: On
  • Place of application knowledge: Central USA
    • It is recommended that this coincides with where you can find the bot.
  • Microsoft App ID and Password: Automatically generate the app ID and password
    • This is recommended so that Azure can manage this unless you have a reason to use a specific app ID and password.

    Web App Bot Assistant

You need to make sure that two providers are registered for your subscription: Microsoft.Storage and Microsoft.BotService. These are located under your subscription → Resource provider. The first time you load Web App Bot, you may find that Microsoft.BotService is not registered. However, if you get out and re-enter it will most likely work. This service registers itself automatically the first time it is loaded and takes a moment.

Create a web app bot

Once the Web App Bot has been built, you will have access to the configuration pages for the bot. In this example, we’ll make a simple change to the existing source code, run the build script again, test it, and then test it in a Teams client.

Build your web app bot

Navigate to the “Build” page and find the link “Open Online Code Editor”. Clicking this link will open the App Service Editor, which you can use to quickly change the code and run the build script again.

App Service Editor where you change code and run it again

There is a lot of supporting code for the bot to work, but the core of the code is in the Bots folder. This includes the EchoBot.cs File that we will change. As you can see in the code below, we’re going to add that Test Text in front of the existing one Echo Text. Changing the code will save the file as you proceed, and you will not have to manually save the changes.

The file is saved on the go, so you don't have to manually save code changes

Navigate to the console and enter the build.cmd Command. This will run a series of commands, recompile the code, and finally copy the compiled files where they are needed to make the bot available. In the end, you should see a Finished successfully Message indicating that the compiled files are now available.

If you have successfully completed a message, the change is successful

Testing the Web App Bot

Fortunately, there is a web chat testing feature built right into the Microsoft Portal Web App Bot services. With this useful tool we can test how the bot reacts to conversational dialogues and simple commands. In this case, our bot simply returns the text. To ensure that our change takes effect, when you send a text, the same text should be reproduced with the previous text from Test Echo:.

The same text was reproduced on success with the previous text of Test Echo

Next, let’s test this bot in an actual Teams client. By default, the only connected channel is web chat. Click the Teams icon to connect this bot to the team channel.

Click on

In this case, it will use all of the default settings, which is Microsoft Teams’ commercial messaging option, and all other options will remain the same. Click “Save” to make this available to the Microsoft Teams channel.

click

To load the bot into a Teams client, just click the Microsoft Teams link. The bot will automatically load into your Teams client.

Load the bot into a Teams client by clicking the Microsoft Teams link

As you can see below, the bot is available to the client. We can test this by sending a chat message and seeing that the result is as expected.

Test this by sending a chat message to see if the result is what you expected

Conclusion

Microsoft Teams offers a powerful bot experience. To simplify development, you can use the Web App Bot service in Microsoft Azure. This allows you to create a test bot that is easy to use and quick to develop, either through the online code editor or an offline editor like VS Code. Develop Microsoft Teams bots today!


Source link