Add event-base listening prototype.
This commit is contained in:
parent
2bf613146a
commit
e95ac32d21
1 changed files with 30 additions and 2 deletions
|
@ -1,11 +1,39 @@
|
|||
import os
|
||||
import slack
|
||||
|
||||
'''
|
||||
client = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])
|
||||
|
||||
|
||||
response = client.chat_postMessage(
|
||||
channel='#general',
|
||||
text='Hello, world!'
|
||||
)
|
||||
assert response['ok']
|
||||
assert response['message']['text'] == 'Hello, world!'
|
||||
assert response['message']['text'] == 'Hello, world!'
|
||||
'''
|
||||
print('I am running.')
|
||||
|
||||
@slack.RTMClient.run_on(event='message')
|
||||
def say_hello(**payload):
|
||||
print('I\'m in.')
|
||||
data = payload['data']
|
||||
web_client = payload['web_client']
|
||||
rtm_client = payload['rtm_client']
|
||||
try:
|
||||
if 'Hello' in data['text']:
|
||||
channel_id = data['channel']
|
||||
thread_ts = data['ts']
|
||||
user = data['user']
|
||||
|
||||
web_client.chat_postMessage(
|
||||
channel=channel_id,
|
||||
text="Hi <@{user}>!",
|
||||
thread_ts=thread_ts
|
||||
)
|
||||
except:
|
||||
print('lmao wtf')
|
||||
|
||||
slack_token = os.environ["SLACK_API_TOKEN"]
|
||||
rtm_client = slack.RTMClient(token=slack_token)
|
||||
rtm_client.start()
|
||||
|
||||
|
|
Reference in a new issue