File tree Expand file tree Collapse file tree 5 files changed +66
-2
lines changed Expand file tree Collapse file tree 5 files changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ HTTP_TIMEOUT="30"
7
7
REDIS_URL = " redis://redis:6380/1"
8
8
9
9
# API token, SHA-256 key.
10
- API_TOKEN = " $5$1O /inyTZhNvFt.GW$Zfckz9OL .lm2wh3IewTm8YJ914wjz5txFnXG5XW.wb4"
10
+ API_TOKEN = ' $5$1O/inyTZhNvFt.GW$Zfckz9OL.lm2wh3IewTm8YJ914wjz5txFnXG5XW.wb4'
11
11
12
12
# Retry parameters.
13
13
MAX_RETRIES = " 3"
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ def send_post_request(webhook_payload: SlingerRequestPayload) -> NoReturn:
73
73
raise WebhookPostFailedError (
74
74
f"Sending webhook failed.\n "
75
75
f"to_url: { to_url } \n "
76
- f"payload: { payload } \n "
76
+ f"payload: { payload } \n , code: { response . status_code } "
77
77
)
78
78
79
79
Original file line number Diff line number Diff line change 17
17
"API_TOKEN" , "$5$1O/inyTZhNvFt.GW$Zfckz9OL.lm2wh3IewTm8YJ914wjz5txFnXG5XW.wb4"
18
18
)
19
19
20
+ print ("=" * 40 )
21
+ print (f"{ API_TOKEN = } " )
22
+ print ("=" * 40 )
23
+
20
24
# Retry parameters.
21
25
MAX_RETRIES : int = int (os .environ .get ("MAX_RETRIES" , 3 ))
22
26
INTERVAL : int = int (os .environ .get ("INTERVAL" , 5 ))
Original file line number Diff line number Diff line change
1
+ # Requires python3.8 and up!
2
+
3
+ import asyncio
4
+ from http import HTTPStatus
5
+ from pprint import pprint
6
+
7
+ import httpx
8
+
9
+
10
+ async def send_webhook () -> None :
11
+
12
+ wh_payload = {
13
+ "to_url" : "https://webhook.site/f864d28d-9162-4ad5-9205-458e2b561c07" ,
14
+ "to_auth" : "" ,
15
+ "tag" : "Dhaka" ,
16
+ "group" : "Bangladesh" ,
17
+ "payload" : {"greetings" : "Hello, world!" },
18
+ }
19
+
20
+ async with httpx .AsyncClient (http2 = True ) as session :
21
+ headers = {
22
+ "Content-Type" : "application/json" ,
23
+ "Authorization" : (
24
+ "Token $5$1O/inyTZhNvFt.GW$Zfckz9OL.lm2wh3IewTm8YJ914wjz5txFnXG5XW.wb4"
25
+ ),
26
+ }
27
+
28
+ response = await session .post (
29
+ "http://localhost:5000/hook_slinger" ,
30
+ headers = headers ,
31
+ json = wh_payload ,
32
+ follow_redirects = True ,
33
+ )
34
+
35
+ # Hook Slinger returns http code 202, accepted, for a successful request.
36
+ assert response .status_code == HTTPStatus .ACCEPTED
37
+ result = response .json ()
38
+ pprint (result )
39
+
40
+
41
+ if __name__ == "__main__" :
42
+ asyncio .run (send_webhook ())
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ set -euo pipefail
4
+
5
+ curl -X ' POST' \
6
+ ' http://localhost:5000/hook_slinger/' \
7
+ -H ' accept: application/json' \
8
+ -H ' Authorization: Token $5$1O/inyTZhNvFt.GW$Zfckz9OL.lm2wh3IewTm8YJ914wjz5txFnXG5XW.wb4' \
9
+ -H ' Content-Type: application/json' \
10
+ -d ' {
11
+ "to_url": "https://webhook.site/37ad9530-59c3-430d-9db6-e68317321a9f",
12
+ "to_auth": "",
13
+ "tag": "Dhaka",
14
+ "group": "Bangladesh",
15
+ "payload": {
16
+ "greetings": "Hello, world!"
17
+ }
18
+ }' | python -m json.tool
You can’t perform that action at this time.
0 commit comments