Zoro-147 commited on
Commit
b311b0f
·
verified ·
1 Parent(s): 9875a08

Update webhooks_server.py

Browse files
Files changed (1) hide show
  1. 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
- @mcp.tool()
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
- # TODO: Send POST request to webhook_url
14
- # TODO: Include message in JSON payload with "mrkdwn": true
15
- # TODO: Handle response and return status
16
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  except Exception as e:
18
- return f"Error sending message: {str(e)}"
 
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)}"