If you were to say in your organization that you were going to build a bot to automate any tasks, I’m sure you would gain the attention of everyone in the room. Bots are powerful automated agents that can help you to do your daily tasks in an efficient way using natural language.
Even though it sounds futuristic and complex, building a bot is quite easy and does not require a single line of code. It is also quite easily accessible to everyone. By the end of this chapter, you will hopefully be the Microsoft Teams superhero of your organization.
The topics you will learn about in this chapter are as follows:
- Creating and packaging a bot using QnA Maker
- Creating and packaging a bot using Power Virtual Agents
- Using a bot in Microsoft Teams
Microsoft QnA Maker is a service that allows you to build and publish bots without writing code. Using an intelligent extraction system, it is able to get the information to be used by the bot from an Excel spreadsheet, a Word document, or even a website.
Before we begin creating our bot, you will need to have access to your organization’s Microsoft Azure and you must be able to deploy custom apps on Microsoft Teams.
Peter – HR manager
Peter manages HR in his organization and spends most of his day replying to questions from other employees. To save him time, Peter has compiled questions and replies in an Excel file, from which he copies them into Microsoft Teams.
To get more time to do his daily tasks, Peter wants to build a Microsoft Teams bot to reply to questions automatically, and to achieve this, he will use Microsoft QnA Maker.
- Start by opening QnA Maker – https://www.qnamaker.ai/.
- Click on Sign in and authenticate using your corporate account:
- Once authenticated, in the black bar at the top, click on Create a knowledge base. This action will redirect you to a five-step process in which you will create the intelligence for your bot.
- In STEP 1 Create a QnA service in Microsoft Azure, click on the Create a QnA service button. This action will open Microsoft Azure and, if you're not yet authenticated, you must sign in with your corporate account:
- In Azure, you will be presented with a form similar to the one in the following screenshot, which you must fill in to create your QnA service:
(b) Subscription: If you have access to more than one Azure subscription, select the one you want to use here.
(c) Pricing tier: Select the pricing tier. There are several options available. Choose one according to the load you estimate for your bot. The F tier is free and gives you 3 transactions per second and a maximum of 50,000 transactions per month. You can start with the free instance and adjust it later if needed.
(d) Resource group: The resource group where you want to create your service. Resource groups on Azure are typically used to group resources related to the same application or to separate resources from production and development environments.
(e) Azure Search pricing tier: Azure Search is a cognitive service that will be used by the bot. This is the service that handles the natural language and retrieves the results even if the question is not an exact match to what was provided to the QnA service. The F tier is free. It gives you 50 MB of storage. If needed, you can adjust it later to a paid tier with more storage space.
(f) Azure Search location: The data center where your service will be running. It’s recommended to select the one closer to the physical location of your organization.
(g) App Name: The name of your app service. By default, it will have the same name as the QnA service, but you can change it if needed.
(h) Website location: The data center where your website will be located. It’s recommended to select the one closest to the physical location of your organization.
(i) App insights: App insights is a tool that helps you to understand how your app is being used. It will monitor the usage of the application so you will know what your users are doing with your bot.
- Click on Create. The service will take a few minutes to get created. Once it’s available, you will receive a notification on Azure.
Go back to the QnA Maker portal, scroll down to STEP 2 Connect your QnA service to your KB, and click the Refresh button. This will establish a connection with Azure and will get the information about the service you have just created. Select the service as shown in the following screenshot:
- In STEP 3 Name your KB, provide a name for your knowledge base. This can be changed at any time if needed:
- In STEP 4 Populate your KB, provide the data that your bot will use to answer the questions. This supports existing websites that will be parsed by the system to get questions, documents, and Excel spreadsheets.
- Click on Add file and upload your Excel file. The following screenshot has an example of how simple your spreadsheet can be, with just two columns. In column A, we have the questions and in column B, we have the answers:
- Choose the Chit-chat option. By default, this option is off, but you can enable it to allow the bot to reply to questions that you have not planned to answer. There are five different types that you can choose from. Make sure you pick one that matches the culture of your organization:
- In STEP 5 Create your KB, click on Create your KB:
- After a few seconds, you will be redirected to the knowledge base EDIT panel and you will be able to review and add alternative phrases to your questions and answers.
- Click on Save and train, to save any modifications you may have made to the system:
- In the black bar at the top, click on PUBLISH and then click on the Publish button:
- After a few seconds, you will be redirected to a success page. On this page, click on the Create Bot button. This will redirect you to Azure again, where you will need to create the bot itself:
- The form on Azure is automatically filled; you just need to validate the data and make the necessary adjustments. Since this is a no-code solution, you can ignore the option selected for SDK language:
- Click on Create. This process will take a few minutes. Once the deployment finishes, you will get a notification on Azure.
- On the Azure notification, click on the Go to resource button. This will open the setup page of the bot framework:
- On the vertical menu, click on Test in Web Chat and check whether your bot works as you expect:
- On the vertical menu, click on Channels and then click on the Microsoft Teams logo:
- Click on Save to create a new channel for Microsoft Teams. This action will allow you to test your bot on Microsoft Teams.
Creating a QnA bot is accessible to all users if they have access to their organization’s Microsoft Azure subscription. Also, it can be used to automate processes that are currently being done manually, wasting the productive time of all collaborators.
If you are not yet familiar with Microsoft Teams App Studio, it is recommended to have a look at Chapter 8, Build Your Own App for Microsoft Teams Using App Studio.
Let’s get right to it:
- Open App Studio on Microsoft Teams.
- Click on the Manifest editor tab.
- Click on the Create a new app button:
- Fill in the App details form. A detailed description of this form can be found in Chapter 8, Build Your Own App for Microsoft Teams Using App Studio.
- On the Capabilities group click on Bots.
- To start the connection between your bot and your Microsoft Teams app, click on Set up:
- On the Set up a bot popup, click on the Existing bot tab:
- Select Connect to a different bot id and open Azure to get the ID of your bot.
- On Azure, click on All services.
- In the Overview menu, click on AI + machine learning.
- Click on the name of your newly created bot:
- On the App Service Settings group, click on Configuration.
- On the Application settings tab, look for the value MicrosoftAppId.
- Click on it and copy its value:
- Paste the ID from Azure in the Bot ID field in Microsoft Teams App Studio.
- On the scope option, select where you want to make it available. You can choose Personal, Team, or Group chat. Choose according to the features and the intent of your bot. The more options you select, the more possibilities you will give to your users to interact with it.
- Click on Save.
- On the Finish step, click on Test and distribute.
- Click on Download to get the application package:
- Open Microsoft Teams Apps Store.
- Click on Upload a custom app, and select the upload for the organization to make it available to all users.
- Once installed, click on the app and then click Add. To learn more about how to install custom apps on Microsoft Teams, read Chapter 6, Extending Microsoft Teams Using Apps.
After completing these steps, your bot has been built with QnA Maker on Azure, and that was done without writing a single line of code. Similar to how we created a bot using QnA Maker, in the next section, we will see how to do so using another tool.
Note: Power Virtual Agents licensing
Power Virtual Agents is not included in Microsoft 365 plans – it requires a separate license for it to work. More information about prices can be found on the Power Virtual Agents website at https://powervirtualagents.microsoft.com/.
To get started with Power Virtual Agents, do the following:
- Open the sign-in page: https://powervirtualagents.microsoft.com.
- Sign in if you already have a license or start a trial by clicking on Sign up free or Start free:
- On the Create a new bot popup, give your bot a name:
- Click on Create and wait a few seconds for the process to finish. Once it’s created, you will enter Power Virtual Agents:
- On the vertical menu, click on Topics. You will notice that the topics are already pre-populated with lessons that will help you to understand how Power Virtual Agents work with conditions and variables:
- To add your own topic, click on New topic.
- Provide a name and a description for your topic.
- Enter a trigger phrase and click on Add. Try to start with 5-10 diverse phrases.
- Click on Go to authoring canvas to start building your topic:
- Click on the + icon to add a node. Nodes can be messages, questions, or conditions:
- Build your topic as illustrated in the following screenshot and save it.
- Test it in the test bot. The reply path will be highlighted in the build area:
The process to get your new bot packaged and installed on Teams is similar to the one we have seen already in the previous section, Packaging the Bot using QnA Maker. The main difference is in the steps required to get the bot’s ID.
To get the bot’s ID to package it into a Microsoft Teams app, do the following:
- In the vertical menu, click on Publish.
- In the Publish window, click on the Publish button. The publication will take 15 minutes:
- Scroll down and click on the Go to channels link.
- Click on Microsoft Teams:
- Click on Add to generate a new App ID.
- Click on Copy to copy the app ID to the clipboard:
- Follow the steps described in the Packaging the bot created using QnA Maker section (steps 1 to 7 and steps 19 to 22) to get the bot installed on Microsoft Teams.
With Power Virtual Agents, you will be able to create complex scenarios for your bot without writing code. The graphical user interface allows you to easily see how things are working and how you can improve the replies of the bot.
Now that our bot is created and packaged, we are now ready to use it.
Let’s now see how to use the bot as a personal app:
- You will need to click on … to expand the More apps section and get access to it:
Once you open the bot, you will be able to ask it private questions in a 1:1 chat without even mentioning the bot. Just type your question and wait for it to reply.
As you can see in the following screenshot, we have enabled the Chit-chat option so the bot is able to reply to questions other than the ones that were uploaded from the spreadsheet. This will make the user more comfortable when interacting with the bot:
The bot can also be used in the context of chats in channels and group chats. To use it, all you need to do is to mention it. Mentions on Microsoft Teams start with the @ sign followed by the name of the bot or the person.
In the following screenshot, you can see the bot being mentioned in a channel. The use of the bot in a channel allows you to keep a conversation about the same topic in one thread, as also illustrated in the screenshot:
In this chapter, you have learned how to build your own bot with artificial intelligence and without writing a single line of code. You have also learned how to package the bot into a Microsoft Teams app, how to make it available in the tenant, and about the ways you can use it to interact with bots.
The last chapter of this book is for users that have an administrator role in their organization. It will cover Microsoft Teams PowerShell and will explain how you can automate tasks such as team creation in your organization using scripts.