Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions samples/bot-conversation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
launchSettings.json
appsettings.*.json
package-lock.json
.env
uv.lock
.venv/
147 changes: 147 additions & 0 deletions samples/bot-conversation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Teams Conversation Bot

This sample demonstrates how to handle various bot conversation events in Microsoft Teams, including adaptive cards, read receipts, message update/delete events, and mentions. It showcases capabilities such as immersive reader support, AI labels, citations, feedback buttons, and sensitivity labels.

## Interaction with Bot

![Conversation Bot](bot-conversation.gif)

The bot responds to the following commands:

* **Who am I?** - Gets information about the current user
* **Find me in Adaptive Card** - Mentions the user in an Adaptive Card
* **Update Card** - Updates the card message with a counter
* **Delete card** - Deletes the card message
* **Send Immersive Reader Card** - Shows an Immersive Reader card with flight status

## Sample Implementations

| Language | Framework | Directory |
|----------|-----------|-----------|
| C# | .NET 10 / ASP.NET Core | [dotnet/bot-conversation](dotnet/bot-conversation/README.md) |
| TypeScript | Node.js | [nodejs/bot-conversation](nodejs/bot-conversation/README.md) |
| Python | Python 3.12+ | [python/bot-conversation](python/bot-conversation/README.md) |

# How to run these samples

You can run these samples locally using the `agentsplayground` tool, without provisioning the Teams App, or you can run in the Teams Client after you have provisioned the Teams Application and configured the application with your local DevTunnels URL.

## Run in the `agentsplayground`

Install the tool agentsplayground for your platform

Windows

```
winget install agentsplayground
```

Linux

```
curl -s https://raw.githubusercontent.com/OfficeDev/microsoft-365-agents-toolkit/dev/.github/scripts/install-agentsplayground-linux.sh | bash
```

Other platforms (like MacOS, via npm)

```
npm install -g @microsoft/m365agentsplayground
```

Once the tool is installed, you can run it from your terminal with the command `agentsplayground`, and it will try to connect to `localhost:3978` where your bot is running.

## Run in the Teams Client

To run these samples in the Teams Client, you need to provision your app in a M365 Tenant, and configure the app to your DevTunnels URL.

1. Install the tool DevTunnels https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started
2. Get Access to a M365 Developer Tenant https://learn.microsoft.com/en-us/office/developer-program/microsoft-365-developer-program-get-started
3. Create a Teams App with the Bot Feature in the Teams Developer Portal (in your tenant) https://dev.teams.microsoft.com

### Configure DevTunnels

Create a persistent tunnel for the port 3978 with anonymous access

```
devtunnel create -a my-tunnel
devtunnel port create -p 3978 my-tunnel
devtunnel host my-tunnel
```

Take note of the URL shown after *Connect via browser:*

### Provisioning the Teams Application

Navigate to the Teams Developer Portal http://dev.teams.microsoft.com

#### Create a new Bot resource

1. Navigate to `Tools->Bot management`, and add a `New bot`
1. In Configure, paste the Endpoint address from devtunnels and append `/api/messages`
1. In Client secrets, create a new secret and save it for later

> Note. If you have access to an Azure Subscription in the same Tenant, you can also create the Azure Bot resource ([learn more](https://learn.microsoft.com/en-us/azure/bot-service/abs-quickstart?view=azure-bot-service-4.0&tabs=singletenant)).

#### Create a new Teams App

1. Navigate to `Apps` and create a `New App`
1. Fill the required values in Basic information (short and long name, short and long description and App URLs)
1. In `App features->Bot` select the bot you created previously
1. Select `Preview in Teams`

> Note. When using an Azure Bot resource, provide the ClientID instead of selecting an existing bot.

## Configure the new project to use the new Teams Bot Application

For NodeJS and Python you will need a `.env` file with the next fields

```
TENANT_ID=
CLIENT_ID=
CLIENT_SECRET=
```

For dotnet you need to add these values to `appsettings.json` or `launchSettings.json` using the next syntax.

appSettings.json


```json
"urls" : "http://localhost:3978",
"Teams": {
"ClientID": "",
"ClientSecret": "",
"TenantId": ""
},
```

Or to use Env Vars from the profile defined in `launchSettings.json` (using the Environment Configuration Provider)

```json
"teamsbot": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:3978",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"Teams__TenantId": "YOUR_TenantId",
"Teams__ClientID": "YOUR_ClientId",
"Teams__ClientSecret": "YOUR_ClientSecret"
}
}
```

## Pro Tip: Read the configuration settings using the Azure CLI

To obtain the TenantId, ClientId and SecretId you can use the Azure CLI with:

> Note. If you don't have access to an Azure Subscription you can still use the Azure CLI, make sure you login with `az login --allow-no-subscription`

```
az ad app credential reset --id $appId
```

## Further Reading

- [Microsoft Teams SDK Documentation](https://learn.microsoft.com/microsoftteams/platform/)
Binary file added samples/bot-conversation/appManifest/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions samples/bot-conversation/appManifest/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/teams/v1.19/MicrosoftTeams.schema.json",
"manifestVersion": "1.19",
"version": "1.0.0",
"id": "${{TEAMS_APP_ID}}",
"developer": {
"name": "teamsConversationBot",
"websiteUrl": "https://www.microsoft.com",
"privacyUrl": "https://www.teams.com/privacy",
"termsOfUseUrl": "https://www.teams.com/termsofuser"
},
"icons": {
"outline": "outline.png",
"color": "color.png"
},
"name": {
"short": "TeamsConversationBot",
"full": "TeamsConversationBot"
},
"description": {
"short": "Demo bot for Teams showing conversation events with adaptive card support.",
"full": "This sample app showcases Teams bot conversation events and adaptive cards."
},
"accentColor": "#FFFFFF",
"bots": [
{
"botId": "${{CLIENT_ID}}",
"scopes": [
"personal",
"groupChat",
"team"
],
"isNotificationOnly": false,
"supportsCalling": false,
"supportsVideo": false,
"supportsFiles": false,
"commandLists": [
{
"scopes": [
"personal",
"groupChat",
"team"
],
"commands": [
{
"title": "Mentionme",
"description": "Sends message with @mention of the sender"
},
{
"title": "Whoami",
"description": "Sends message with name of the sender"
}
]
}
]
}
],
"permissions": [
"identity",
"messageTeamMembers"
],
"validDomains": ["${{BOT_DOMAIN}}"]
}
Binary file added samples/bot-conversation/appManifest/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/bot-conversation/bot-conversation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.