feat(microsoft-teams): new Microsoft Teams notification integration

Incoming-webhook / Power Automate Workflows, 3 commands: send message,
send Adaptive Card (title/text/facts/action button). Webhook-URL auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guillaume BOURGEOIS
2026-07-11 23:28:25 +02:00
parent e3c15ae972
commit df4cd98a9e
4 changed files with 258 additions and 0 deletions
@@ -0,0 +1,89 @@
import json, os, sys, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def post(cfg, payload):
url = str(cfg.get("webhook_url", ""))
if not url:
raise Exception("webhook_url is not configured")
data = json.dumps(payload).encode("utf-8")
headers = {"Content-Type": "application/json"}
req = urllib.request.Request(url, data=data, headers=headers, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
r.read()
return r.status
def adaptive_card(body_blocks, actions=None):
card = {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.4",
"body": body_blocks,
}
if actions:
card["actions"] = actions
return {
"type": "message",
"attachments": [
{"contentType": "application/vnd.microsoft.card.adaptive", "content": card}
],
}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
title = str(inputs.get("title", "")).strip()
if not title:
raise Exception("title is required")
text = str(inputs.get("text", "")).strip()
facts_raw = str(inputs.get("facts", "")).strip()
action_title = str(inputs.get("action_title", "")).strip()
action_url = str(inputs.get("action_url", "")).strip()
if action_title and not action_url:
raise Exception("action_url is required when action_title is set")
blocks = [{"type": "TextBlock", "text": title, "weight": "Bolder", "size": "Large", "wrap": True}]
if text:
blocks.append({"type": "TextBlock", "text": text, "wrap": True})
if facts_raw:
facts = []
for pair in facts_raw.split(","):
if "=" not in pair:
continue
k, v = pair.split("=", 1)
facts.append({"title": k.strip(), "value": v.strip()})
if facts:
blocks.append({"type": "FactSet", "facts": facts})
actions = None
if action_title and action_url:
actions = [{"type": "Action.OpenUrl", "title": action_title, "url": action_url}]
payload = adaptive_card(blocks, actions)
status = post(cfg, payload)
return {"ok": True, "status": status}
_run(main)