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

# Microsoft Teams

> Guide to integrate Microsoft Teams App for sending notification to user DM or channels in any workspace.

This is a step-by-step guide to integrating and sending notifications to users on Microsoft Teams.

## Pre-Requisites

To send notifications on Microsoft Teams, you'll need to create a Teams bot. This bot will be responsible for sending notifications to users / channels in their Teams workspace. You'll also need a Microsoft 365 developer account and permission to add apps to your teams. You can ask your admin to assign you relevant permission, or you can sign up for a free Microsoft 365 developer program.

* [Sign up for a Microsoft 365 developer program](https://developer.microsoft.com/en-us/microsoft-365/dev-program/)

* [Create a Teams App](docs/microsoft-teams#create-teams-app)

## Create Teams app

You'll have to create a [Teams App](/docs/microsoft-teams#step-1-create-teams-app) to send notifications via SuprSend. User will have to add this App in their Teams workspace and channel to start getting notifications through the App. You can learn more about Apps [here](https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/build-and-test/teams-developer-portal).

<Steps>
  <Step title="Creat a Microsoft 365 Account">
    First, [create a Microsoft 365 Developer Account](https://developer.microsoft.com/en-us/microsoft-365/dev-program/). Sign in If you have an existing developer account. You'll need permission to add Apps in your account. Ask your admin to assign you relevant permissions if you are using an existing account.
  </Step>

  <Step title="Navigate to Apps">
    Now, navigate to the Apps section and click on **+New App**.

    <Frame>
      <img src="https://mintcdn.com/suprsend/jhGzZpggWCp1KSgu/images/docs/d5b25a5-Screenshot_2023-10-20_at_3.38.10_PM.png?fit=max&auto=format&n=jhGzZpggWCp1KSgu&q=85&s=583b8dddffd3420f745c4067dd0aac02" width="1844" height="792" data-path="images/docs/d5b25a5-Screenshot_2023-10-20_at_3.38.10_PM.png" />
    </Frame>
  </Step>

  <Step title="Add a name and other details">
    Give your App a suitable name and Add. For your test app, you can use something like "SuprSend Test App" for app name

    <Frame>
      <img src="https://mintcdn.com/suprsend/3ix_OjxB_ZGM-pa-/images/docs/229a7e1-image.png?fit=max&auto=format&n=3ix_OjxB_ZGM-pa-&q=85&s=242ecfc9821584d8940c80d26733ca15" width="1226" height="462" data-path="images/docs/229a7e1-image.png" />
    </Frame>

    You'll be redirected to a new window where you'll have to add a few information related to your application such as company name, description, website link, URLs to register the App.

    <Frame>
      <img src="https://mintcdn.com/suprsend/ysJyO3LOXwZ5L098/images/docs/fe39ac8-image.png?fit=max&auto=format&n=ysJyO3LOXwZ5L098&q=85&s=dd21cc951479b2fb72d071158e18724e" width="1792" height="964" data-path="images/docs/fe39ac8-image.png" />
    </Frame>
  </Step>

  <Step title="Add Bot">
    Now select App feature from your left panel to click on Bot.
    If you have an existing bot, select it from the list or click on Create a new bot
    On the [bot page](https://dev.teams.microsoft.com/bots), click on **+New Bot** and add bot name. Add a relevant bot name and **Add**.

    <Frame>
      <img src="https://mintcdn.com/suprsend/iZJ8XgyTL4NrLVtX/images/docs/9a4ab84-image.png?fit=max&auto=format&n=iZJ8XgyTL4NrLVtX&q=85&s=5eb22bb8b196c13bbfd51263ea259ece" width="1246" height="446" data-path="images/docs/9a4ab84-image.png" />
    </Frame>

    Once the bot is created, you'll land on bot configuration page. Leave the endpoint blank, select "**Microsoft teams**" in the channel and create **client secret** for your bot. Save your bot secret somewhere safe. You'll need this in SuprSend vendor integration form.

    <Frame>
      <img src="https://mintcdn.com/suprsend/iZJ8XgyTL4NrLVtX/images/docs/a95a925-image.png?fit=max&auto=format&n=iZJ8XgyTL4NrLVtX&q=85&s=da7335c9c921b0116c70d79c7237b565" width="2066" height="996" data-path="images/docs/a95a925-image.png" />
    </Frame>
  </Step>

  <Step title="Get started with the Azure Portal">
    Now login to [Azure portal](https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade) and select All Apps. Here, you'll see the recently created bot. Click on it and copy the **App (client) ID**. You'll need to fill this information in SuprSend vendor integration form.

    <Frame>
      <img src="https://mintcdn.com/suprsend/3ix_OjxB_ZGM-pa-/images/docs/1aa2a33-image.png?fit=max&auto=format&n=3ix_OjxB_ZGM-pa-&q=85&s=aab1eae882efd7fb698e223ea261c443" width="2422" height="604" data-path="images/docs/1aa2a33-image.png" />
    </Frame>
  </Step>

  <Step title="Navigate to Authentication from the left panel">
    After navigating, select `Accounts in any organizational directory`and save.

    <Frame>
      <img src="https://mintcdn.com/suprsend/09Y8zJBSaqwwb23r/images/docs/775bfa0-Screenshot_2024-07-04_at_7.36.47_PM.png?fit=max&auto=format&n=09Y8zJBSaqwwb23r&q=85&s=cbf9c9d2ba6885afc45ea6619da469f7" width="2281" height="824" data-path="images/docs/775bfa0-Screenshot_2024-07-04_at_7.36.47_PM.png" />
    </Frame>
  </Step>

  <Step title="Add your Recently Created Bot">
    Now that your bot is created, go back to your developer portal -> Apps and select your last created App. Select App features -> bot. In the bot configuration, add your recently created bot.

    <Frame>
      <img src="https://mintcdn.com/suprsend/ftswjUsq0JlUh-RL/images/docs/07393df-image.png?fit=max&auto=format&n=ftswjUsq0JlUh-RL&q=85&s=12b93c3e53eb3820d966adbbc68e4210" width="1660" height="860" data-path="images/docs/07393df-image.png" />
    </Frame>
  </Step>

  <Step title="Add specific info about your bot, and add some permissions">
    Choose **Only send notifications** in "what can your bot do?" Add **personal**, **team** and **group chat** in bot scopes and click on Save.

    <Frame>
      <img src="https://mintcdn.com/suprsend/y77gmHjmaTSnbCzd/images/docs/cce58ed-image.png?fit=max&auto=format&n=y77gmHjmaTSnbCzd&q=85&s=40f27c724de678ba4d7b84cca464d2ae" width="774" height="762" data-path="images/docs/cce58ed-image.png" />
    </Frame>

    In your App permissions, add below permission.

    | Section                                 | Permissions                                                                                                                          |
    | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
    | Team Permissions -> Application         | `Channel.Create.Group`, `Channel.Delete.Group`, `ChannelMessage.Read.Group`, `ChannelMessage.Send.Group`, `TeamsActivity.Send.Group` |
    | Chat/Meeting Permissions -> Application | `ChatMessage.Read.Chat`, `ChatMessage.Send.Chat`                                                                                     |
    | User Permissions -> Application         | `TeamsActivity.Send.User`                                                                                                            |

    <Frame>
      <img src="https://mintcdn.com/suprsend/JOwfEC79k-vs3tUR/images/docs/8d923d0-image.png?fit=max&auto=format&n=JOwfEC79k-vs3tUR&q=85&s=f4dfa6fc98393563792c58ed65246465" width="1742" height="1118" data-path="images/docs/8d923d0-image.png" />
    </Frame>
  </Step>

  <Step title="Publish your App to make it available for use. ">
    Publish to org if you want your App to be accessible only inside your organization teams. Publish to store if you want to make it publically available in the teams App store.

    <Frame>
      <img src="https://mintcdn.com/suprsend/dnAGb1CmSRGCSyT3/images/docs/33aa4f7-image.png?fit=max&auto=format&n=dnAGb1CmSRGCSyT3&q=85&s=ca19ef74a5de8c6feb74ad5e14039bb1" width="2272" height="1366" data-path="images/docs/33aa4f7-image.png" />
    </Frame>

    Your admin will have to approve the App for it to go live. For admin approval, go to [admin portal](https://admin.teams.microsoft.com/policies/manage-apps) and publish it again. Your App might take some time to go live once it is published.
  </Step>

  <Step title="Add the Client ID">
    Add client ID that you copied from azure portal into your App Basic Information:

    <Frame>
      <img src="https://mintcdn.com/suprsend/09Y8zJBSaqwwb23r/images/docs/6e1bcf0-Screenshot_2024-04-04_at_3.24.04_AM.png?fit=max&auto=format&n=09Y8zJBSaqwwb23r&q=85&s=a6f19f3399f7147fea484731c9b3fba0" width="2160" height="790" data-path="images/docs/6e1bcf0-Screenshot_2024-04-04_at_3.24.04_AM.png" />
    </Frame>

    Now go to [https://teams.microsoft.com/](https://teams.microsoft.com/) and **ADD** the app . First, from left panel select Apps with a + sign and then In the section "Built for this organization", there will be an option to Add the app.

    <Frame>
      <img src="https://mintcdn.com/suprsend/jhGzZpggWCp1KSgu/images/docs/d20916c-Screenshot_2024-04-04_at_3.03.00_AM.png?fit=max&auto=format&n=jhGzZpggWCp1KSgu&q=85&s=30d9803e4dd300e4ab86700c9a0161b6" width="3010" height="1452" data-path="images/docs/d20916c-Screenshot_2024-04-04_at_3.03.00_AM.png" />
    </Frame>
  </Step>
</Steps>

## Add Teams integration on SuprSend

Go to SuprSend dashboard -> [Microsoft teams Vendor Settings](https://app.suprsend.com/en/staging/vendors/ms_teams/ms_teams-ms_teams?brand_id=default) page. Add `Application (client) ID` and `client secret` (in Password field) generated while [creating bot in the above step](/docs/microsoft-teams#creating-a-new-bot).

<Frame>
  <img src="https://mintcdn.com/suprsend/ftswjUsq0JlUh-RL/images/docs/0f6b463-image.png?fit=max&auto=format&n=ftswjUsq0JlUh-RL&q=85&s=ad8395df17e20b92f72d60b3411086d1" width="2402" height="928" data-path="images/docs/0f6b463-image.png" />
</Frame>

## Update teams channel in user or object profile

The information required in the user profile is dependent on the type of message you are sending.

<AccordionGroup>
  <Accordion title="Sending a direct message" defaultOpen={false}>
    To send a direct message to a user, add `tenant_id` , `service_url` of the tenant, and `conversation_id` or `user_id` corresponding to user personal chat.

    You can pass this information in a json format using `user.add_ms_teams` method as below:

    <CodeGroup>
      ```python python theme={"system"}
      distinct_id = "__uniq_user_id__"  # Unique identifier of user in your application
      # Instantiate User profile
      user = supr_client.user.get_instance(distinct_id=distinct_id)

      # using conversation_id
      user.add_ms_teams(
        {
      		"tenant_id": "c1981ab2-9aaf-xxxx-xxxx",
      		"service_url": "https://smba.trafficmanager.net/amer",
      		"conversation_id": "19:c1524d7c-a06f-456f-8abe-xxxx"
        })

      # using user_id
      user.add_ms_teams(
        {
      		"tenant_id": "c1981ab2-9aaf-xxxx-xxxx",
      		"service_url": "https://smba.trafficmanager.net/amer",
      		"user_id": "29:1nsLcmJ2RKtYH6Cxxxx-xxxx"
        })

      response = user.save()
      print(response)
      ```

      ```javascript node.js theme={"system"}
      const distinct_id = "__uniq_user_id__"  // Unique id of user in your application
      const user = supr_client.user.get_instance(distinct_id) // Instantiate User profile

      // using conversation_id
      user.add_ms_teams(
        {
      		"tenant_id": "c1981ab2-9aaf-xxxx-xxxx",
      		"service_url": "https://smba.trafficmanager.net/amer",
      		"conversation_id": "19:c1524d7c-a06f-456f-8abe-xxxx"
        })

      //using user_id
      user.add_ms_teams(
        {
      		"tenant_id": "c1981ab2-9aaf-xxxx-xxxx",
      		"service_url": "https://smba.trafficmanager.net/amer",
      		"user_id": "29:1nsLcmJ2RKtYH6Cxxxx-xxxx"
        })

      const response = user.save()
      response.then((res) => console.log("response", res));
      ```
    </CodeGroup>

    **Getting tenant ID, user ID, conversation ID:**

    You'll get **tenant ID** from your developer azure portal.

    <Frame>
      <img src="https://mintcdn.com/suprsend/3ix_OjxB_ZGM-pa-/images/docs/1aa2a33-image.png?fit=max&auto=format&n=3ix_OjxB_ZGM-pa-&q=85&s=aab1eae882efd7fb698e223ea261c443" width="2422" height="604" data-path="images/docs/1aa2a33-image.png" />
    </Frame>

    You'll get **conversation\_id** from the URL of the chat.

    <Frame>
      <img src="https://mintcdn.com/suprsend/dnAGb1CmSRGCSyT3/images/docs/34467e8-image.png?fit=max&auto=format&n=dnAGb1CmSRGCSyT3&q=85&s=a78e74e01b1e00a2ec02cc305174c2ca" width="2096" height="92" data-path="images/docs/34467e8-image.png" />
    </Frame>

    You can get **user\_id** by following the steps to [fetch the roster or user profile](https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/get-teams-context?tabs=json#fetch-the-roster-or-user-profile). You'll need authentication token to fetch user profile. You can get this token from SuprSend vendor page after saving the form.

    <Frame>
      <img src="https://mintcdn.com/suprsend/iZJ8XgyTL4NrLVtX/images/docs/a861ce0-image.png?fit=max&auto=format&n=iZJ8XgyTL4NrLVtX&q=85&s=a31ab2bf282b40ce7cb0311af831f0c9" width="1540" height="974" data-path="images/docs/a861ce0-image.png" />
    </Frame>
  </Accordion>

  <Accordion title="Sending to a channel" defaultOpen={false}>
    To send a message to a public or private channel, you’ll need to pass `tenant_id` , `service_url` of the tenant, and `conversation_id` of the teams chat channel.

    <Warning>
      Please note that you'll have to add App in your teams channel to send notification otherwise it will fail.
    </Warning>

    To add App to your teams channel, click on `+` icon to add a tab. In **Add a tab** modal, click on **"More Apps"**.

    <Frame>
      <img src="https://mintcdn.com/suprsend/ftswjUsq0JlUh-RL/images/docs/12077b8-image.png?fit=max&auto=format&n=ftswjUsq0JlUh-RL&q=85&s=310a4256450464fcb34c09f1a881f37d" width="1428" height="630" data-path="images/docs/12077b8-image.png" />
    </Frame>

    You'll see your App in your organization. Click on the App and **Add to the team**.

    <Frame>
      <img src="https://mintcdn.com/suprsend/dnAGb1CmSRGCSyT3/images/docs/363ff8c-image.png?fit=max&auto=format&n=dnAGb1CmSRGCSyT3&q=85&s=2b2b04bf01326965e834c9a2a457b32b" width="1868" height="684" data-path="images/docs/363ff8c-image.png" />
    </Frame>

    We recommend creating a separate user for identifying channels and not mix it in user profile. You can create a teams channel user with `distinct_id` as `channel_<channel_name>` so it's easy for you to remember and pass in your workflow calls whenever you want to send message on a teams channel.

    <CodeGroup>
      ```python python theme={"system"}
      distinct_id = "channel_general"  # Unique identifier of user in your application
      # Instantiate User profile
      user = supr_client.user.get_instance(distinct_id=distinct_id)

      user.add_ms_teams(
        {
      		"tenant_id": "c1981ab2-9aaf-xxxx-xxxx",
      		"service_url": "https://smba.trafficmanager.net/amer",
      		"conversation_id": "19:c1524d7c-a06f-456f-8abe-xxxx"
        })

      response = user.save()
      print(response)
      ```

      ```javascript node.js theme={"system"}
      const distinct_id = "channel_general"  // Unique id of user in your application
      const user = supr_client.user.get_instance(distinct_id) // Instantiate User profile

      user.add_ms_teams(
        {
      		"tenant_id": "c1981ab2-9aaf-xxxx-xxxx",
      		"service_url": "https://smba.trafficmanager.net/amer",
      		"conversation_id": "19:c1524d7c-a06f-456f-8abe-xxxx"
        })

      const response = user.save()
      response.then((res) => console.log("response", res));
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Sending message using incoming webhook" defaultOpen={false}>
    To send a direct message using incoming webhook, just pass the webhook URL in user profile. You can pass this information in a json format using `user.add_ms_teams` method as below:

    <CodeGroup>
      ```python python theme={"system"}
      distinct_id = "__uniq_user_id__"  # Unique identifier of user in your application
      # Instantiate User profile
      user = supr_client.user.get_instance(distinct_id=distinct_id)

      user.add_ms_teams(
        {
          "incoming_webhook": {
            "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX"
          }
        })

      response = user.save()
      print(response)
      ```

      ```javascript node.js theme={"system"}
      const distinct_id = "__uniq_user_id__"  // Unique id of user in your application
      const user = supr_client.user.get_instance(distinct_id) // Instantiate User profile

      user.add_ms_teams(
        {
          "incoming_webhook": {
            "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX"
          }
        })

      const response = user.save()
      response.then((res) => console.log("response", res));
      ```
    </CodeGroup>

    <Warning>
      Avoid using incoming webhook configuration in the case of a multi-tenant architecture where same set of users may belong to multiple tenants and you want to send notifications via [tenant vendor](/docs/tenant-vendor). The incoming webhook is not tied exclusively to the app configuration used for sending notifications and will invariably be dispatched to all incoming webhooks included in the user profile, regardless of the tenant's vendor configuration.
    </Warning>

    **Get Incoming webhook for a teams channel:**

    To get incoming webhook, select **connectors** from channel -> more options.

    <Frame>
      <img src="https://mintcdn.com/suprsend/ysJyO3LOXwZ5L098/images/docs/f99ea8e-image.png?fit=max&auto=format&n=ysJyO3LOXwZ5L098&q=85&s=96ccd161a7b0658f6e35ddccc34f7bbb" width="624" height="604" data-path="images/docs/f99ea8e-image.png" />
    </Frame>

    Configure **Incoming webhook** in connectors. Click on create and copy the webhook URL

    <Frame>
      <img src="https://mintcdn.com/suprsend/iZJ8XgyTL4NrLVtX/images/docs/a6006b1-image.png?fit=max&auto=format&n=iZJ8XgyTL4NrLVtX&q=85&s=c320ec8b12cc3f56d4a8b1b96785bb6d" width="1164" height="1388" data-path="images/docs/a6006b1-image.png" />
    </Frame>
  </Accordion>
</AccordionGroup>

### Order of precedence

Microsoft teams profile should only contain `incoming_webhook->url`, or the bot configurations like `tenant_id`, `conversation_id` and `serive_url` . If there are multiple keys in `user.add_ms_teams()` call, the order of precedence is as follows:

`incoming_webhook->url` > `conversation_id` > `user_id`. E.g., if your add\_ms\_teams argument is as follows:

<CodeGroup>
  ```python python theme={"system"}
  distinct_id = "__uniq_user_id__"  # Unique identifier of user in your application
  # Instantiate User profile
  user = supr_client.user.get_instance(distinct_id=distinct_id)

  user.add_ms_teams(
    {
      "incoming_webhook": {
        "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX"
      },
  		"tenant_id": "c1981ab2-9aaf-xxxx-xxxx",
  		"service_url": "https://smba.trafficmanager.net/amer",
  		"conversation_id": "19:c1524d7c-a06f-456f-8abe-xxxx",
      "user_id":"29:1nsLcmJ2RKtYH6Cxxxx-xxxx"
    })

  response = user.save()
  print(response)
  ```

  ```javascript node.js theme={"system"}
  const distinct_id = "__uniq_user_id__"  // Unique id of user in your application
  const user = supr_client.user.get_instance(distinct_id) // Instantiate User profile

  user.add_ms_teams(
    {
      "incoming_webhook": {
        "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX"
      },
  		"tenant_id": "c1981ab2-9aaf-xxxx-xxxx",
  		"service_url": "https://smba.trafficmanager.net/amer",
  		"conversation_id": "19:c1524d7c-a06f-456f-8abe-xxxx",
      "user_id":"29:1nsLcmJ2RKtYH6Cxxxx-xxxx"
    })

  const response = user.save()
  response.then((res) => console.log("response", res));
  ```
</CodeGroup>

The profile will be saved as `{"incoming_webhook": { "url": "https://wnk1z.webhook.office.com/webhookb2/XXXXXXXXX"}}`

## Create Teams template

Refer [teams template documentation](/docs/ms-teams-template) for step-by-step guide on how to create, preview and publish the template.

## Tenancy in Microsoft teams

In scenarios where you're sending notifications on behalf of your enterprise clients, each with their own team applications for communicating with end-users, you can define distinct app configurations at the tenant level. In SuprSend, we presently identify tenants as tenants.

To support this, simply include the app configuration for the tenant on the vendor details page. This will override the default tenant vendor at the time of sending notification. This configuration needs to be set up once, and SuprSend will seamlessly direct all notifications associated with that tenant through the vendor configuration specified for the tenant.

> In case you don't have vendor defined for a tenant, notifications will automatically fallback to the default vendor credentials.

Refer Steps to configure tenant level vendor [here](/docs/tenant-vendor)

***
