Skip to content

Commit de730a5

Browse files
authored
Update Teams integration (#51)
1 parent ee71982 commit de730a5

9 files changed

Lines changed: 37 additions & 12 deletions
-44.4 KB
Binary file not shown.
-249 KB
Binary file not shown.
53.6 KB
Loading
88.9 KB
Loading
8.02 KB
Loading
33.6 KB
Loading
58.1 KB
Loading
34.8 KB
Loading

docs/how-tos/airflow/send-ms-teams-notifications.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,45 @@ sidebar_position: 35
88

99
As stated in [how to send email notifications](/docs/how-tos/airflow/send-emails), Airflow allows multiple ways to inform users about DAGs and tasks status.
1010

11-
Furthermore, it's important to understand Airflow handles these 4 status (`failure`, `retry`, `success` and `missed SLA`) via callbacks. You can learn more about them [here](https://airflow.apache.org/docs/apache-airflow/2.2.1/logging-monitoring/callbacks.html)
11+
Furthermore, it's important to understand Airflow handles these 4 status (`failure`, `retry`, `success` and `missed SLA`) via callbacks. You can learn more about them [here](https://airflow.apache.org/docs/apache-airflow/2.2.1/logging-monitoring/callbacks.html).
1212

13-
Below we explain how to use those callbacks to send Microsoft Teams notifications.
13+
## Prepare the Microsoft side
1414

15-
## Prepare Microsoft Teams
15+
Sending messages through Teams is done using Power Automate webhooks. These connections can be assigned to Teams channels, chats, or individuals. It is a simple two step automation: a webhook receives the DAG notification, and an action posts it to your Teams.
1616

17-
Sending messages through Teams is done using Webhooks. These connections can be assigned to MS Teams channels.
17+
Everything on the Microsoft side is managed through their [Power Automate](https://make.powerautomate.com/) application. Choose `My flows` from the sidebar:
1818

19-
In the channel you want to send Airflow notifications to, click the `...` -> `Connectors` and search for `Incoming Webhook`.
19+
![Choose My flows](./assets/teams/my-flows.png)
2020

21-
![Create channel Connector](./assets/create-channel-connector.png)
21+
Choose `Instant cloud flow` from the `New flow` dropdown:
2222

23-
Click `Configure`, give it a name, and optionally select an image to use as the sender's avatar, then click `Create` and you will be given a webhook URL.
23+
![Instant cloud flow](./assets/teams/new-flow.png)
2424

25-
![Create Incoming Webhook](./assets/create-incoming-webhook.png)
25+
Now pick the type of trigger to use. `When a Teams webhook request is received`:
26+
27+
![Webhook request](./assets/teams/choose-trigger.png)
28+
29+
This will create a flowchart with just the webhook on it. Click on it to bring up a sidebar with its settings. Make sure it is set to allow anyone to trigger the flow. Also note the empty URL field here; we will have to come back for it after the flow is saved. You can name this flow at any time by clicking on the title text (shown here as `Untitled flow`).
30+
31+
![Webhook setup](./assets/teams/webhook-setup.png)
32+
33+
Then, click the (+) on the flowchart to add an action. Type `card` into the search box to narrow the results, then choose `Post card in a chat or channel`:
34+
35+
![Post card](./assets/teams/choose-post-action.png)
36+
37+
The settings for this action determine where your notification will go. First, paste the following into the `Adaptive Card` field; this tells the workflow how to read the notifications:
38+
- `@triggerBody()?['attachments'][0]?['content']`
39+
40+
Then set `Post In` to `Chat with Flow bot` to message only yourself, or for group messages, `Group chat` or `Channel`. For the latter two, there are more fields to set the exact destination.
41+
42+
![Action setup](./assets/teams/post-action-setup.png)
43+
44+
Now click Save in the upper right corner of the screen, and when it finishes, you can return to the webhook's sidebar and copy the URL it's generated. Make sure to copy all of it.
2645

2746
:::info
28-
Store this URL in a safe place as you will need it in a subsequent step and anyone with this link can send notification to that MS Teams channel.
47+
Store this URL in a safe place as you will need it in a subsequent step and anyone with this link can send notifications to that Teams channel.
2948
:::
49+
3050
## Prepare Airflow
3151
### Create a new Integration
3252

@@ -86,7 +106,13 @@ To send MS Teams notifications, in the Airflow DAG we need to import the appropr
86106
- `connection_id`: the name of the Datacoves Integration created above
87107
- if no connection_id is specified, MSTeams Notifier will use `ms_teams`
88108
- `message`: the body of the message
89-
- `theme_color`: theme color of the MS Teams card
109+
- `theme_color`: theme color of the MS Teams card. This may be one of:
110+
- `default`
111+
- `emphasis`
112+
- `good`
113+
- `attention`
114+
- `warning`
115+
- `accent`
90116

91117
:::info
92118
`on_failure_callback` will throw an error if using lists causing your task to fail.
@@ -154,13 +180,12 @@ notifications:
154180
args:
155181
connection_id: MS_TEAMS
156182
message: "DAG {{ dag.dag_id }} Succeeded"
157-
color: 0000FF
158183
on_failure_callback:
159184
notifier: notifiers.datacoves.ms_teams.MSTeamsNotifier
160185
args:
161186
connection_id: MS_TEAMS
162187
message: "DAG {{ dag.dag_id }} Failed"
163-
color: 9900FF
188+
color: "warning"
164189

165190
# DAG Tasks
166191
nodes:

0 commit comments

Comments
 (0)