forked from slackapi/python-slack-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
25 lines (23 loc) · 826 Bytes
/
Copy pathexample.py
File metadata and controls
25 lines (23 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
from slackclient import SlackClient
import time
#get your personal token from https://api.slack.com/web, bottom of the page.
api_key = ''
client = SlackClient(api_key)
if client.rtm_connect():
while True:
last_read = client.rtm_read()
if last_read:
try:
parsed = last_read[0]['text']
#reply to channel message was found in.
message_channel = last_read[0]['channel']
if parsed and 'food:' in parsed:
choice = random.choice(['hamburger', 'pizza'])
client.rtm_send_message(message_channel,
'Today you\'ll eat %s.' % choice)
except:
pass
time.sleep(1)