Files
Brancheneinstufung2/lead-engine/trading_twins/teams_notification.py

71 lines
2.6 KiB
Python

import requests
import json
import os
from datetime import datetime
# Default-Webhook (Platzhalter) - sollte in .env stehen
DEFAULT_WEBHOOK_URL = os.getenv("TEAMS_WEBHOOK_URL", "")
def send_approval_card(job_uuid, customer_name, time_string, webhook_url=DEFAULT_WEBHOOK_URL):
"""
Sendet eine Adaptive Card an Teams mit Approve/Deny Buttons.
"""
# Die URL unserer API (muss von außen erreichbar sein, z.B. via ngrok oder Server-IP)
api_base_url = os.getenv("API_BASE_URL", "http://localhost:8004")
card_payload = {
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": None,
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"body": [
{
"type": "TextBlock",
"text": f"🤖 Automatisierte E-Mail an {customer_name}",
"weight": "Bolder",
"size": "Medium"
},
{
"type": "TextBlock",
"text": f"(via Trading Twins) wird um {time_string} Uhr ausgesendet.",
"isSubtle": True,
"wrap": True
},
{
"type": "TextBlock",
"text": "Wenn Du bis dahin NICHT reagierst, wird die E-Mail automatisch gesendet.",
"color": "Attention",
"wrap": True
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "✅ JETZT Aussenden",
"url": f"{api_base_url}/action/approve/{job_uuid}"
},
{
"type": "Action.OpenUrl",
"title": "❌ STOP Aussendung",
"url": f"{api_base_url}/action/cancel/{job_uuid}"
}
]
}
}
]
}
try:
response = requests.post(webhook_url, json=card_payload)
response.raise_for_status()
return True
except Exception as e:
print(f"Fehler beim Senden an Teams: {e}")
return False