Skip to content

Commit 8150fa9

Browse files
committed
Merge pull request #39 from henriklindgren/master
Added doc/examples/example.py
2 parents ff47acf + 6197c3d commit 8150fa9

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

doc/examples/example.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
import random
4+
from slackclient import SlackClient
5+
import time
6+
7+
#get your personal token from https://api.slack.com/web, bottom of the page.
8+
api_key = ''
9+
client = SlackClient(api_key)
10+
11+
if client.rtm_connect():
12+
while True:
13+
last_read = client.rtm_read()
14+
if last_read:
15+
try:
16+
parsed = last_read[0]['text']
17+
#reply to channel message was found in.
18+
message_channel = last_read[0]['channel']
19+
if parsed and 'food:' in parsed:
20+
choice = random.choice(['hamburger', 'pizza'])
21+
client.rtm_send_message(message_channel,
22+
'Today you\'ll eat %s.' % choice)
23+
except:
24+
pass
25+
time.sleep(1)

0 commit comments

Comments
 (0)