Build a bot that can send proactive messages to Microsoft Teams

Completed

The Teams Toolkit for Visual Studio Code extension supplies several scenario-based app templates for building bots. The Chat Notification bot scenario-based app template creates a bot that can be triggered to send a proactive notification to Microsoft Teams. A proactive message is a message sent in response to an external event or trigger. You'll use this template to create a bot in the next unit.

Note

The exercise in this module uses Teams Toolkit v5.0.0.

Components for building a bot

To develop a bot for Teams, you need:

  • A web server to host and run the bot code.
  • An Azure Bot Service bot to make the bot available to Teams.
  • An Microsoft Entra app to register the bot with the Microsoft Cloud.
  • An HTTP tunnel service to supply a publicly accessible URL for the local endpoint that's used to receive messages from the bot service.
  • A Microsoft Teams app package to deploy the bot into Teams. This package has the app manifest file, which describes the bot capabilities and where the bot can be installed (chat, channel, meeting, personal app).

Simplified setup

Teams Toolkit for Visual Studio Code handles the complexity of creating and configuring the resources needed to develop a bot. When you run the bot for the first time, it performs the following steps for you:

  1. Verifies and installs prerequisites.
  2. Starts an HTTP tunnel using VisualStudio Dev Tunnels service.
  3. Creates a Microsoft Entra app registration.
  4. Creates an Azure Bot Service registration.
  5. Compiles the bot code and starts a local web server.
  6. Generates a Teams app package.
  7. Deploys the app package to Teams.
  8. Starts a debugging session.
  9. Opens a browser window, goes to a Teams web client, and displays an app installation dialog.

Proactive messages

To trigger a proactive message to be sent to Teams, you send an HTTP POST request to the notification endpoint that's hosted on the local web server. You can use any HTTP client to send the request. For example, you can use a command-line tool like cURL or PowerShell, a desktop application like Postman, or a cloud service like Azure Functions.

Adaptive cards

A bot can send interactive cards called adaptive cards to Teams as proactive messages. Adaptive cards supply a powerful and flexible way to create rich, consistent, interactive experiences that can be used across a wide range of platforms and devices.

In the next exercise, you'll learn how to create a bot for Teams by using the Notification bot scenario-based app template. You'll also learn how to trigger the bot to send an adaptive card to Teams from the command line.