Skip to content

Commit 675f5d9

Browse files
committed
Send a message back to Slack, check the error that we got
1 parent ee1c245 commit 675f5d9

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

solution/main.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
from pprint import pprint
22

3+
import requests
4+
35
from benedict import benedict
46

7+
from dotenv import dotenv_values
8+
59
from fastapi import Body, FastAPI, Request, Response
610

11+
config = dotenv_values(".env")
12+
713
app = FastAPI()
814

915

16+
# This token can be obtained from the `OAuth Tokens for Your Workspace` section
17+
# In `OAuth & Permissions` in the bot settings
18+
BOT_TOKEN = config["BOT_TOKEN"]
19+
20+
1021
@app.post("/echo")
1122
async def echo(request: Request, response: Response, data=Body(...)):
1223
raw_body = await request.body()
@@ -24,8 +35,22 @@ async def echo(request: Request, response: Response, data=Body(...)):
2435
channel_id = payload.get("event.channel")
2536

2637
if event_type == "app_mention":
27-
# Send the message here
28-
print(channel_id)
38+
send_message_payload = {
39+
"channel": channel_id,
40+
"text": "Pinging back in the channel"
41+
}
42+
43+
headers = {
44+
"Authorization": f"Bearer {BOT_TOKEN}"
45+
}
46+
47+
response = requests.post(
48+
"https://slack.com/api/chat.postMessage",
49+
headers=headers,
50+
json=send_message_payload
51+
)
52+
# We do that to debug any incoming errors from Slack
53+
pprint(response.text)
2954

3055
return {
3156
"data": data,

solution/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ fastapi==0.67.0
22
uvicorn==0.14.0
33
requests==2.26.0
44
python-benedict==0.24.0
5+
python-dotenv==0.18.0

0 commit comments

Comments
 (0)