Skip to content

Commit c73c917

Browse files
authored
feat(reports): add native Microsoft Teams alert notifications (#45508)
1 parent 850fe54 commit c73c917

55 files changed

Lines changed: 7576 additions & 113 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/superset-python-unittest.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ jobs:
6969
uses: $/.github/actions/setup-backend/
7070
with:
7171
python-version: ${{ matrix.python-version }}
72+
- name: Verify Teams SDK is available for authentication and delivery tests
73+
run: python -c "import microsoft_teams.apps"
7274
- name: Install HiveServer2 transport test dependencies
7375
run: uv pip install --system -e ".[hive,impala]"
7476
- name: SDK unit tests

‎docs/admin_docs/configuration/alerts-reports.mdx‎

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,217 @@ This information can then be retrieved from the endpoint `/api/v1/saved_query/`
982982
schedule the queries that have `schedule_info` in their JSON metadata. For schedulers other than
983983
Airflow, additional fields can be easily added to the configuration file above.
984984

985+
## Microsoft Teams configuration
986+
987+
Teams is an optional, disabled-by-default notification destination for
988+
attachment-free alerts in standard channels. Each deployment supports one
989+
Microsoft tenant and bot identity. Scheduled reports, private/shared channels,
990+
direct messages, and file attachments are not supported.
991+
992+
### Install and configure
993+
994+
Install the extra in both the web-server and Celery worker images using the same
995+
Superset release as the deployment:
996+
997+
```bash
998+
pip install 'apache-superset[teams]==<your-superset-version>'
999+
superset db upgrade
1000+
```
1001+
1002+
Configure both processes with the same server-side settings. Load the secret
1003+
value from a deployment secret store, rather than checking it into source control:
1004+
1005+
```python
1006+
import os
1007+
1008+
FEATURE_FLAGS = {
1009+
"ALERT_REPORTS": True,
1010+
}
1011+
ALERT_REPORTS_TEAMS = {
1012+
"tenant_id": os.environ["TEAMS_TENANT_ID"],
1013+
"application_id": os.environ["TEAMS_APPLICATION_ID"],
1014+
"credential": os.environ["TEAMS_CLIENT_SECRET"],
1015+
"destinations": [
1016+
{
1017+
"key": "ops",
1018+
"label": "Operations alerts",
1019+
"team_id": os.environ["TEAMS_OPS_TEAM_ID"],
1020+
"channel_id": os.environ["TEAMS_OPS_CHANNEL_ID"],
1021+
},
1022+
],
1023+
}
1024+
```
1025+
1026+
Destination keys must be unique, stable identifiers of 1–128 letters, digits,
1027+
underscores or hyphens, starting with a letter or digit. Keep keys stable when
1028+
changing routing. Each destination requires a label, team ID, and channel ID.
1029+
Approve only standard channels in the configured tenant. Duplicate keys or
1030+
channels and unknown configuration fields are rejected. An empty mapping leaves
1031+
Teams unconfigured.
1032+
1033+
For `team_id`, use the Teams thread ID, for example `19:example@thread.tacv2`,
1034+
not the Microsoft 365 group GUID shown as the Team ID in Graph or the Teams
1035+
admin center. In Teams, open the team's **More options (…) > Get link to team**.
1036+
Copy the value between `/l/team/` and `/conversations` and URL-decode it
1037+
(`%3A` becomes `:` and `%40` becomes `@`). Do not use the link's `groupId` parameter.
1038+
For `channel_id`, use **Get link to channel** and URL-decode the value immediately
1039+
after `/l/channel/`. See Microsoft's [Teams link formats](https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/build-and-test/deep-link-teams).
1040+
The installation callback matches `team_id` exactly. A group GUID will cause
1041+
installation events to return 403 and leave the destination without an active
1042+
installation.
1043+
1044+
Merge `ALERT_REPORTS` into your existing feature flags. Teams is enabled by valid
1045+
`ALERT_REPORTS_TEAMS` configuration and the installed `teams` extra. Restart the web
1046+
server and workers after changing configuration or rotating a secret. Apply the migration
1047+
before accepting installation events. The scheduler, broker, and worker setup
1048+
from the earlier Alerts and Reports instructions still applies; the Teams SDK
1049+
does not run another web server. Attachment-free Teams alerts do not need a
1050+
browser or screenshot worker.
1051+
1052+
### Register the Microsoft app
1053+
1054+
Use a Microsoft Entra application restricted to your organization and an Azure
1055+
Bot registration with the same application ID and tenant. Create a client secret
1056+
and put its **value** in `TEAMS_CLIENT_SECRET`. Enable the Microsoft Teams channel
1057+
on the bot registration. Set its messaging endpoint to
1058+
`https://superset.example/api/v1/teams/events/`, using your public HTTPS host and
1059+
any deployment URL prefix. See Microsoft's
1060+
[bot registration guidance](https://learn.microsoft.com/en-us/azure/bot-service/bot-service-quickstart-registration?view=azure-bot-service-4.0).
1061+
1062+
Package the notification-only app for your organization's Teams app catalog.
1063+
The bot must support team scope only and have `isNotificationOnly` enabled;
1064+
see the [manifest reference](https://learn.microsoft.com/en-us/microsoftteams/platform/resources/schema/manifest-schema#bots).
1065+
This example uses manifest version 1.22, which supports the required fields:
1066+
1067+
```json
1068+
{
1069+
"$schema": "https://developer.microsoft.com/json-schemas/teams/v1.22/MicrosoftTeams.schema.json",
1070+
"manifestVersion": "1.22",
1071+
"version": "1.0.0",
1072+
"id": "cccccccc-cccc-4ccc-8ccc-cccccccccccc",
1073+
"developer": {
1074+
"name": "Your organization",
1075+
"websiteUrl": "https://superset.example/",
1076+
"privacyUrl": "https://superset.example/privacy",
1077+
"termsOfUseUrl": "https://superset.example/terms"
1078+
},
1079+
"name": { "short": "Superset Alerts" },
1080+
"description": {
1081+
"short": "Superset alert notifications",
1082+
"full": "Receive configured Superset alerts in approved standard Teams channels."
1083+
},
1084+
"icons": { "outline": "outline.png", "color": "color.png" },
1085+
"accentColor": "#20A7C9",
1086+
"bots": [
1087+
{
1088+
"botId": "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb",
1089+
"scopes": ["team"],
1090+
"isNotificationOnly": true,
1091+
"supportsFiles": false
1092+
}
1093+
]
1094+
}
1095+
```
1096+
1097+
Replace the package `id` with a new UUID and `botId` with your configured application
1098+
ID. Replace the example URLs with your organization's published pages. Include
1099+
`manifest.json`, a 32×32 transparent outline icon, and a 192×192 color icon at the
1100+
root of the app ZIP. Have your Teams administrator approve the package and allow
1101+
installation in the selected teams. Install it in each approved team after the
1102+
callback is reachable. Configure each standard channel's actual team and channel
1103+
identifiers on the server; display labels and Microsoft 365 group names are not
1104+
routing IDs. Do not add personal or group-chat scopes, file support, or
1105+
private/shared channel capabilities.
1106+
1107+
Installing the app updates the installation record for its team, but does not
1108+
approve any destinations. Configure the allowlist separately. Uninstalling marks
1109+
the installation inactive; reinstalling refreshes its verified service URL and
1110+
reactivates the same record. If an initial installation happened before callback
1111+
routing was ready, remove and reinstall the app to deliver a fresh event.
1112+
Lifecycle events require a timezone-qualified source timestamp. Older events are
1113+
acknowledged without changing installation state, and removal wins timestamp ties.
1114+
Removal records are retained even when the installation event has not arrived.
1115+
1116+
### Route the callback
1117+
1118+
Your ingress must forward `POST /api/v1/teams/events/` (including the trailing
1119+
slash) to Flask, preserving the Authorization header and JSON body. The callback
1120+
accepts bodies up to 256 KiB, or a smaller deployment body limit, and returns 413
1121+
for oversized requests before JSON parsing, SDK authentication, or database access.
1122+
Do not send this path through a browser login redirect or an ingress SSO challenge. Keep TLS
1123+
termination and the configured public URL consistent. Other Superset routes keep
1124+
their normal authentication and CSRF requirements; do not exempt the whole API.
1125+
The callback validates Microsoft's connector token, application, tenant, approved
1126+
team, and signed service URL before changing installations.
1127+
1128+
Allow outbound connectivity from the web server for connector signing keys and
1129+
from workers for Entra token acquisition and the verified Bot Framework service
1130+
URL. Use the public Microsoft cloud endpoints supported by this adapter. Changing
1131+
the bot identity requires matching configuration on both web and worker processes
1132+
and a new verified installation for that identity.
1133+
1134+
### Create a Teams alert
1135+
1136+
1. Install the app in each approved team once the callback is reachable.
1137+
2. In **Alerts & reports**, create an alert and disable attachments.
1138+
3. Choose **Teams** as the notification method and select an approved destination
1139+
by its display label. Add another Teams notification method to notify another
1140+
channel.
1141+
4. Save the alert and check its execution logs after delivery.
1142+
1143+
Each alert creates a separate channel post containing its name, optional
1144+
description, and an **Open in Superset** link when link inclusion is enabled.
1145+
Execution errors show a generic failure message rather than SQL diagnostics.
1146+
1147+
You can save an alert before installing the bot, but delivery requires an active
1148+
installation. Saved destinations that are no longer configured remain visible
1149+
as unavailable. Restore the destination's stable key or select a replacement.
1150+
Credentials are managed in deployment configuration, not in the alert editor.
1151+
1152+
### Configure a recipient through the API
1153+
1154+
Use recipient type `Teams`, `recipient_config_json` containing only
1155+
`{"target": "ops"}`, and `report_format="NONE"`. Replace `ops` with a configured
1156+
destination key. Create, update, and delivery validation enforce the same
1157+
restrictions, including partial updates to saved alerts.
1158+
1159+
The protected destination API returns keys, labels, and installation availability,
1160+
without credentials or routing details.
1161+
1162+
### Troubleshooting
1163+
1164+
| Symptom | Check |
1165+
| --- | --- |
1166+
| Teams is absent from the editor | Install the extra, enable `ALERT_REPORTS`, provide valid Teams configuration, choose an alert, and disable attachments. |
1167+
| Destination says “Bot installation required” | Check the bot is installed in the configured team and the callback received its installation event. Saving is allowed before installation; delivery requires an active record. |
1168+
| Saved destination says “Unavailable” | Restore the original stable key or choose an approved replacement. Configuration changes do not rewrite saved recipients. |
1169+
| Callback returns 404 | Check `ALERT_REPORTS_TEAMS` is configured, the ingress path/prefix, and that the request reached this deployment. |
1170+
| Callback returns 503 | Check the optional SDK is installed and the deployment configuration passes validation. A busy callback worker returns 503 after waiting at most one second for its authentication lock. |
1171+
| Callback returns 401 or 403 | Check connector token authentication, bot application/tenant IDs, approved team, signed service URL, and that ingress preserved Authorization. Browser cookies cannot authenticate this route. |
1172+
| Delivery fails authorization | Check installation status, secret value/expiry, bot registration, and channel access. A second 401 after one refresh or a 403 ends delivery. |
1173+
| Save fails after a configuration change | Restore the integration/key or explicitly remove/replace Teams recipients. Partial updates validate the merged schedule, including format and schedule type. |
1174+
| Delivery times out or exhausts retries | Check Entra and Bot Framework connectivity and worker execution context. The 60-second retry budget includes token acquisition and cleanup and is capped by the execution deadline. Use a supported prefork worker with finite `working_timeout` and `ALERT_REPORTS_WORKING_TIME_OUT_KILL=True` for the outer task limit. |
1175+
| A duplicate channel post appears | A response can be lost after Teams accepted a post. Bounded retries may create another root post; delivery is not exactly-once. |
1176+
1177+
Use the existing alert execution logs to inspect success and failure. Do not copy
1178+
access tokens, credentials, raw SDK responses, or SQL diagnostics into channel
1179+
messages or issue reports. Rotate credentials through deployment configuration;
1180+
there is no browser credential-management page.
1181+
1182+
### Delivery timeouts and retries
1183+
1184+
Delivery allows up to four attempts within a cooperative 60-second retry budget,
1185+
limited by the remaining report execution deadline. Requests have socket timeouts
1186+
of at most 10 seconds. Throttling honors Microsoft's retry delay, and expired
1187+
authentication can refresh once. A lost response can cause duplicate posts.
1188+
1189+
Socket timeouts do not bound DNS resolution or an entire streaming response. For
1190+
an outer time limit, use a Celery prefork worker with
1191+
[time-limit support](https://docs.celeryq.dev/en/stable/userguide/workers.html#time-limits),
1192+
keep `ALERT_REPORTS_WORKING_TIME_OUT_KILL=True`, and set a finite schedule
1193+
`working_timeout`. These limits cover the entire alert task, including query
1194+
execution and delivery. Hard task termination cannot guarantee resource cleanup.
1195+
9851196
:::resources
9861197

9871198
- [Tutorial: Automated Alerts and Reporting via Slack/Email in Superset](https://dev.to/ngtduc693/apache-superset-topic-5-automated-alerts-and-reporting-via-slackemail-in-superset-2gbe)

‎docs/developer_docs/contributing/howtos.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,29 @@ npm run playwright:debug tests/auth/login.spec.ts
211211
npm run playwright:report
212212
```
213213

214+
### Testing Microsoft Teams notifications
215+
216+
For deployment setup, see the [Microsoft Teams configuration guide](/admin-docs/configuration/alerts-reports#microsoft-teams-configuration).
217+
218+
Backend tests under `tests/unit_tests/integrations/teams/` exercise the real SDK
219+
with fake HTTP transports. Install the `teams` extra to run authentication and
220+
transport tests rather than skipping them. Notification contract tests at
221+
`tests/unit_tests/reports/notifications/teams_tests.py` run without the SDK.
222+
223+
The browser regression at `playwright/tests/reports/teams-alerts.spec.ts` requires a
224+
running Superset instance, an admin test user, Reports and Teams enabled, at least
225+
one configured destination, and a selectable test database. An unconfigured
226+
integration skips this optional browser test. Use an isolated test deployment
227+
with placeholder UUIDs and a dummy secret; no Microsoft app or installation is
228+
needed for this test. It mocks destination availability, creates only inactive
229+
alerts, blocks execution requests, verifies saved recipient keys, and deletes its
230+
schedule afterward. It never clicks **Trigger now**. Run it from
231+
`superset-frontend`:
232+
233+
```bash
234+
npx playwright test playwright/tests/reports/teams-alerts.spec.ts --project=chromium
235+
```
236+
214237
### Debugging Server App
215238

216239
For debugging the Flask backend:

‎docs/static/resources/openapi.json‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9591,7 +9591,8 @@
95919591
"Email",
95929592
"Slack",
95939593
"SlackV2",
9594-
"Webhook"
9594+
"Webhook",
9595+
"Teams"
95959596
],
95969597
"type": "string"
95979598
}
@@ -29644,6 +29645,59 @@
2964429645
]
2964529646
}
2964629647
},
29648+
"/api/v1/report/teams_destinations/": {
29649+
"get": {
29650+
"responses": {
29651+
"200": {
29652+
"content": {
29653+
"application/json": {
29654+
"schema": {
29655+
"properties": {
29656+
"result": {
29657+
"items": {
29658+
"properties": {
29659+
"available": {
29660+
"type": "boolean"
29661+
},
29662+
"key": {
29663+
"type": "string"
29664+
},
29665+
"label": {
29666+
"type": "string"
29667+
}
29668+
},
29669+
"type": "object"
29670+
},
29671+
"type": "array"
29672+
}
29673+
},
29674+
"type": "object"
29675+
}
29676+
}
29677+
},
29678+
"description": "Approved destinations and installation availability"
29679+
},
29680+
"401": {
29681+
"$ref": "#/components/responses/401"
29682+
},
29683+
"403": {
29684+
"$ref": "#/components/responses/403"
29685+
}
29686+
},
29687+
"security": [
29688+
{
29689+
"jwt": []
29690+
},
29691+
{
29692+
"api_key": []
29693+
}
29694+
],
29695+
"summary": "List approved Teams alert destinations",
29696+
"tags": [
29697+
"Report Schedules"
29698+
]
29699+
}
29700+
},
2964729701
"/api/v1/report/{pk}": {
2964829702
"delete": {
2964929703
"parameters": [

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pinot = ["pinotdb[sqlalchemy]>=9.2.2, <10.0.0"]
274274
playwright = ["playwright>=1.64.1, <2"]
275275
postgres = ["psycopg2-binary==2.9.13"]
276276
presto = ["pyhive[presto]>=0.7.0"]
277+
teams = ["microsoft-teams-apps==2.1.1"]
277278
trino = ["trino>=0.340.0"]
278279
prophet = [
279280
"prophet>=1.5.0, <2",

‎requirements/development.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
#
19-
-e .[development,bigquery,clickhouse,cockroachdb,crate,databend,druid,duckdb,elasticsearch,fastmcp,firebird,gevent,gsheets,monetdb,mongodb,mssql,mysql,oracle,postgres,presto,prophet,risingwave,snowflake,starrocks,trino,thumbnails,ydb]
19+
-e .[development,bigquery,clickhouse,cockroachdb,crate,databend,druid,duckdb,elasticsearch,fastmcp,firebird,gevent,gsheets,monetdb,mongodb,mssql,mysql,oracle,postgres,presto,prophet,risingwave,snowflake,starrocks,trino,teams,thumbnails,ydb]
2020
-e ./superset-extensions-cli[test]
2121
# testcontainers-backed db_engine_specs tests (tests/testcontainers/) --
2222
# see .github/workflows/testcontainers.yml

0 commit comments

Comments
 (0)