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

# Microsoft Teams notifications

This example shows how to set up Airflow notifications in a [Microsoft Teams](https://www.microsoft.com/en-us/microsoft-teams/group-chat-software) channel by using [Airflow callbacks](/docs/learn/2.x/error-notifications-in-airflow#airflow-callbacks). Teams notifications about DAG runs and tasks let you quickly inform many team members about the status of your data pipelines.

## Before you start

Before trying this example, make sure you have:

* [Teams](https://www.microsoft.com/en-us/microsoft-teams/log-in) with a Business account supporting team channels.
* The [Astro CLI](/docs/cli/v1.43/install-cli).
* An Astro project running locally on your computer. See [Getting started with the Astro CLI](/docs/cli/v1.43/get-started-cli).

## Send task failure notifications to MS Teams

Follow these steps to receive notifications in MS Teams for failed tasks in an example DAG. Refer to the [Airflow callbacks section](/docs/learn/2.x/error-notifications-in-airflow#airflow-callbacks) of our notifications guide to learn how to set up notifications for other types of events.

1. Open the folder containing your Astro Project. Copy the contents of the `include` folder in the [project GitHub repository](https://github.com/astronomer/cs-tutorial-msteams-callbacks/tree/main/include) to your Astro project `include` folder.

   ```text wrap theme={null}
   ├── .astro
   ├── dags
   └── include
       ├── hooks
       │   └── ms_teams_webhook_hook.py
       ├── operators
       │   └── ms_teams_webhook_operator.py
       ├── ms_teams_callback_functions.py
       └── ms_teams_callback_functions_with_partial.py
   ```

2. Create a [Microsoft Teams Incoming Webhook](https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet#create-incoming-webhooks-1) for the channel where you want to receive notifications. Copy and save the webhook URL.

3. In the Airflow UI, go to **Admin** > **Connections** and create a new connection with the following parameters. Note that you won't be able to test this connection from the Airflow UI.

   * **Connection Id**: `ms_teams_callbacks`
   * **Connection Type**: `HTTP`
   * **Host**: `<your-organization>.office.com/webhook/<your-webhook-id>`
   * **Schema**: `https`

   <Frame>
     <img src="https://mintcdn.com/astronomer/dALHYMAz3j7hCvzV/images/img/examples/example-ms-teams-callback-connection.png?fit=max&auto=format&n=dALHYMAz3j7hCvzV&q=85&s=59927a5483cbbadb5cbfd2c3fadbb250" alt="Connection" width="983" height="489" data-path="images/img/examples/example-ms-teams-callback-connection.png" />
   </Frame>

   <Info>
     Some corporate environments use outbound proxies. If you're behind an outbound proxy for internet access, put the proxy details in the **Extra** field when creating the HTTP connection in the Airflow UI (for example, `{"proxy":"http://my-proxy:3128"}`).
   </Info>

   <Info>
     If the `HTTP` connection type isn't available, double check that the [HTTP provider](https://airflow.apache.org/registry/providers/http/) is installed in your Airflow environment.
   </Info>

4. Import the failure callback function at the top of your DAG file.

   ```python wrap theme={null}
   from include.ms_teams_callback_functions import failure_callback
   ```

5. Set the `on_failure_callback` keyword of your DAG's `default_args` parameter to the imported `failure_callback` function.

   ```python wrap theme={null}
   @dag(
       start_date=datetime(2023, 7, 1),
       schedule="@daily",
       default_args={
           "on_failure_callback": failure_callback,
       }
   )
   ```

6. Run your DAG. Any failed task will trigger the `failure_callback` function which sends a notification message to your Teams channel.

The `include` folder of the [project repository](https://github.com/astronomer/cs-tutorial-msteams-callbacks) also contains callback functions for other triggers in addition to the failure callback shown here. You can modify any of the functions to customize the notification message. To learn more about all available callback parameters, see [Airflow callbacks](/docs/learn/2.x/error-notifications-in-airflow#airflow-callbacks).

<Frame>
  <img src="https://mintcdn.com/astronomer/dALHYMAz3j7hCvzV/images/img/examples/example-ms-teams-callback-task-fail-teams-msg.png?fit=max&auto=format&n=dALHYMAz3j7hCvzV&q=85&s=d31835ba80b7329f9949d65da2bd1ba5" alt="Notification" width="1017" height="445" data-path="images/img/examples/example-ms-teams-callback-task-fail-teams-msg.png" />
</Frame>

## See also

* [MS Teams developer documentation](https://learn.microsoft.com/en-us/microsoftteams/platform/mstdd-landing)
* [Manage Airflow DAG notifications](/docs/learn/2.x/error-notifications-in-airflow)
