Spaces:
Running
Running
slack bot integration file
Browse files- slack_bot.py +20 -0
slack_bot.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
SLACK_BOT_TOKEN = os.getenv("SLACK_BOT_TOKEN")
|
4 |
+
SLACK_BOT_CHANNEL_ID = os.getenv("SLACK_BOT_CHANNEL_ID")
|
5 |
+
|
6 |
+
payload = {"channel": SLACK_BOT_CHANNEL_ID, "text": "This message was sent from Hugging Face demo workspace."}
|
7 |
+
|
8 |
+
headers = {
|
9 |
+
"Authorization": f"Bearer {SLACK_BOT_TOKEN}",
|
10 |
+
"Content-Type": "application/json",
|
11 |
+
}
|
12 |
+
|
13 |
+
response = requests.post(
|
14 |
+
"https://slack.com/api/chat.postMessage", json=payload, headers=headers
|
15 |
+
)
|
16 |
+
|
17 |
+
if response.status_code == 200 and response.json().get("ok"):
|
18 |
+
print("Message sent successfully!")
|
19 |
+
else:
|
20 |
+
print("Failed to send message:", response.json())
|