Building a Microsoft Teams Bot

Reading Time: 3 minutes

Microsoft has released Teams from one year, the utility of this product is indisputable, a strength is definitely the possibility to extend it with bots, connectors and tabs.
In this article, I’ll talk about how to build a bot and how to leverage the Microsoft Teams API capabilities, which are the following:

  • Fetch Channel List
  • Mention User
  • Start New 1 on 1 Chat
  • Route Message To General
  • Fetch Member List
  • Send O365 Card
  • Fetch Team Info
  • Start New Reply Chain
  • Mention Channel
  • Mention Team
  • Notification Feed
  • Bot Delete Message

Let’s start to create a bot, the easiest way is create a “Web App Bot” on Azure, this naturally presupposes the possession of a subscription:

Create a Bot via Azure | Giuliano De Luca
Create a Bot via Azure

The next step is to download the package, you can do it by clicking on “Build” under “Bot Management” and then “Download zip file”:

Download Bot package
Download Bot package

Unzip the content in a folder and open it with Visual Studio Code or other code editors, in my case I’ll use VSCode.
In order to debug the bot locally is required ngrok a “secure introspectable tunnels to localhost webhook development tool and debugging tool”, then on VSCode create a folder “.vscode” and a file “launch.json” as follow:

vscode-launch | Giuliano De Luca

The content of the file “launch.json” is:

This allows running the VSCode debugger.
When you are ready to debug your bot run the console command “ngrok http 3978” and copy the https URL:

ngrok | Giuliano De Luca

Open the “Settings” of your bot on Azure and paste the ngrok https URL in the field “Messaging endpoint”, at the end will be something like that https://ngrokurl/api/messages in this way your bot will respond directly from your local machine.
The last step is set up the breakpoints and click on play:

vscode-play | Giuliano De Luca

Open Teams and start a new chat, in the field to: write the Microsoft App Id that you can read on Azure in “Application Settings” this allow you to start a one to one conversation with your bot.
I developed a sample that you can find on my Github which makes use of Microsoft Teams API check the images below:

The solution is available on Github: