> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainlit.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Teams

To make your Chainlit app available on Teams, you will need to create a Teams bot and set up the necessary environment variables.

## How it Works

The Teams bot will be available in direct messages.

<Frame caption="Preview">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/demo.gif?s=c23bad7fc29190846dc3dea891ef58ff" width="2400" height="1080" data-path="images/teams/demo.gif" />
</Frame>

## Supported Features

| Message | Streaming | Elements | Audio | Ask User | Chat History | Chat Profiles | Feedback |
| ------- | --------- | -------- | ----- | -------- | ------------ | ------------- | -------- |
| ✅       | ❌         | ✅        | ❌     | ❌        | ❌            | ❌             | ✅        |

## Install the Botbuilder Library

The Botbuilder library is not included in the Chainlit dependencies. You will have to install it manually.

```bash theme={null}
pip install botbuilder-core
```

## Create a Teams App

To start, navigate to the [App Management](https://dev.teams.microsoft.com/apps) page. Here, create a new app.

<Frame caption="Create a Teams App">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/create-app.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=f4568f92eb252b126a5f2f16d1610d84" width="1818" height="702" data-path="images/teams/create-app.png" />
</Frame>

## Fill the App Basic Information

Navigate to Configure > Basic Information and fill in the basic information about your app.
You won't be able to publish your app until you fill in all the required fields.

<Frame caption="Basic infos">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/basic-infos.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=a3402d501250d017a1d557e396ef2cbf" width="1780" height="886" data-path="images/teams/basic-infos.png" />
</Frame>

## Create the Bot

Navigate to Configure > App features and add the Bot feature.
Create a new bot and give it the following permissions and save.

<Frame caption="Bot permissions">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/bot-permissions.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=acfd4058a9e1edcbba8f0edbf43e1f5b" width="1911" height="911" data-path="images/teams/bot-permissions.png" />
</Frame>

## Go to the Bot Framework Portal

Navigate to the [Bot Framework Portal](https://dev.botframework.com/bots/), click on the Bot you just created and go to the Settings page.

## Get the App ID

In the Bot Framework Portal, you will find the app ID. Copy it and set it as an environment variable in your Chainlit app.

```
TEAMS_APP_ID=your_app_id
```

<Frame caption="Get the App ID">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/app-id.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=048f84be26a0786cef359d4b84240dad" width="1238" height="912" data-path="images/teams/app-id.png" />
</Frame>

## Working Locally

If you are working locally, you will have to expose your local Chainlit app to the internet to receive incoming messages to Teams. You can use [ngrok](https://ngrok.com/) for this.

```bash theme={null}
ngrok http 8000
```

This will give you a public URL that you can use to set up the app manifest. Do not forget to replace it once you deploy Chainlit to a public host.

## Set the Message Endpoint

Under Configuration, set the messaging endpoint to your Chainlit app HTTPS URL and add the `/teams/events` suffix.

<Frame caption="Messaging endpoint">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/endpoint.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=1db4229f4774c396f6194a7a290d6619" width="1238" height="912" data-path="images/teams/endpoint.png" />
</Frame>

## Get the App Secret

On the same page, you will find a blue "Manage Microsoft App ID and password" button. Click on it.

<Frame caption="Manage password">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/manage-password.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=b0df6a6afe868b5a2d69e2b83a2a142f" width="1238" height="912" data-path="images/teams/manage-password.png" />
</Frame>

Navigate to Manage > Certificates & secrets and create a new client secret. Copy it and set it as an environment variable in your Chainlit app.

```
TEAMS_APP_PASSWORD=your_app_secret
```

## Support Multi Tenant Account Types

Navigate to Manage > Authentication and toggle "Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant)" then save.

<Frame caption="Multi tenant">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/multitenant.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=98e9b4faa178d2409469cfe84a5b309e" width="1004" height="923" data-path="images/teams/multitenant.png" />
</Frame>

## Start the Chainlit App

Since the Chainlit app is not running, the Teams bot will not be able to communicate with it.

For the example, we will use this simple app:

```python my_app.py theme={null}
import chainlit as cl

@cl.on_message
async def on_message(msg: cl.Message):
    # Access the teams user
    print(cl.user_session.get("user"))

    # Access potential attached files
    attached_files = msg.elements

    await cl.Message(content="Hello World").send()
```

<Note>
  Reminder: Make sure the environment variables are set and that your local
  chainlit app is exposed to the internet via ngrok.
</Note>

Start the Chainlit app:

```bash theme={null}
chainlit run my_app.py -h
```

<Note>
  Using -h to not open the default Chainlit UI since we are using Teams.
</Note>

## Publish the Bot

Back to the [App Management](https://dev.teams.microsoft.com/apps) page, navigate to "Publish to org" and click on "Publish".

<Frame caption="Publish">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/publish.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=308c75b9e74f7f86ac4d8968b1b7122a" width="1904" height="861" data-path="images/teams/publish.png" />
</Frame>

## Authorize the Bot

The Bot will have to be authorized by the Teams admin before it can be used. To do so navigate to the [Teams admin center](https://admin.teams.microsoft.com/policies/manage-apps) and find the app.

<Frame caption="Publish">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/app-blocked.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=90fa426383909f570834ff0bb89c49db" width="1631" height="652" data-path="images/teams/app-blocked.png" />
</Frame>

Then authorize it.

<Frame caption="Publish">
  <img src="https://mintcdn.com/chainlit-43/bY2N4qUEa_bGPLfY/images/teams/authorize-app.png?fit=max&auto=format&n=bY2N4qUEa_bGPLfY&q=85&s=bd18346c1925ab2caf2cb9ef04dc9342" width="976" height="665" data-path="images/teams/authorize-app.png" />
</Frame>

You should now be able to interact with your Chainlit app through Teams.
