File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
integration_tests/samples/issues Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ # ------------------
2+ # Only for running this script here
3+ import logging
4+ import sys
5+ from os .path import dirname
6+
7+ sys .path .insert (1 , f"{ dirname (__file__ )} /../../.." )
8+ logging .basicConfig (level = logging .DEBUG )
9+ # ------------------
10+
11+ # export SLACK_API_TOKEN=xoxb-***
12+ # python3 integration_tests/samples/issues/issue_506.py
13+
14+ import os
15+ from slack import RTMClient
16+
17+ logger = logging .getLogger (__name__ )
18+ global_state = {}
19+
20+
21+ @RTMClient .run_on (event = "open" )
22+ def open (** payload ):
23+ web_client = payload ["web_client" ]
24+ auth_result = web_client .auth_test ()
25+ global_state .update ({"bot_id" : auth_result ["bot_id" ]})
26+ logger .info (f"cached: { global_state } " )
27+
28+
29+ @RTMClient .run_on (event = "message" )
30+ def message (** payload ):
31+ data = payload ["data" ]
32+ if data .get ("bot_id" , None ) == global_state ["bot_id" ]:
33+ logger .debug ("Skipped as it's me" )
34+ return
35+ # do something here
36+ web_client = payload ["web_client" ]
37+ message = web_client .chat_postMessage (channel = data ["channel" ], text = "What's up?" )
38+ logger .info (f"message: { message ['ts' ]} " )
39+
40+
41+ rtm_client = RTMClient (token = os .environ ["SLACK_API_TOKEN" ])
42+ rtm_client .start ()
You can’t perform that action at this time.
0 commit comments