Spaces:
Sleeping
Sleeping
Update webhooks_server.py
Browse files- webhooks_server.py +31 -7
webhooks_server.py
CHANGED
|
@@ -1,18 +1,42 @@
|
|
| 1 |
import os
|
| 2 |
import requests
|
|
|
|
| 3 |
from mcp.types import TextContent
|
| 4 |
|
| 5 |
-
|
| 6 |
def send_slack_notification(message: str) -> str:
|
| 7 |
-
"""Send a formatted notification to the team Slack channel.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
webhook_url = os.getenv("SLACK_WEBHOOK_URL")
|
| 9 |
if not webhook_url:
|
| 10 |
return "Error: SLACK_WEBHOOK_URL environment variable not set"
|
| 11 |
|
| 12 |
try:
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
except Exception as e:
|
| 18 |
-
return f"
|
|
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
+
from typing import Union
|
| 4 |
from mcp.types import TextContent
|
| 5 |
|
| 6 |
+
|
| 7 |
def send_slack_notification(message: str) -> str:
|
| 8 |
+
"""Send a formatted notification to the team Slack channel.
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
message: The message text to send (supports markdown formatting)
|
| 12 |
+
|
| 13 |
+
Returns:
|
| 14 |
+
str: Success message or error description
|
| 15 |
+
"""
|
| 16 |
webhook_url = os.getenv("SLACK_WEBHOOK_URL")
|
| 17 |
if not webhook_url:
|
| 18 |
return "Error: SLACK_WEBHOOK_URL environment variable not set"
|
| 19 |
|
| 20 |
try:
|
| 21 |
+
payload = {
|
| 22 |
+
"text": message,
|
| 23 |
+
"mrkdwn": True # Enable markdown formatting
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
response = requests.post(
|
| 27 |
+
webhook_url,
|
| 28 |
+
json=payload,
|
| 29 |
+
headers={'Content-Type': 'application/json'},
|
| 30 |
+
timeout=10 # 10 second timeout
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Check if the request was successful
|
| 34 |
+
if response.status_code == 200:
|
| 35 |
+
return "Message sent successfully"
|
| 36 |
+
else:
|
| 37 |
+
return f"Slack API error: {response.status_code} - {response.text}"
|
| 38 |
+
|
| 39 |
+
except requests.exceptions.RequestException as e:
|
| 40 |
+
return f"Error sending message: {str(e)}"
|
| 41 |
except Exception as e:
|
| 42 |
+
return f"Unexpected error: {str(e)}"
|