├── requirements.txt ├── README.md └── slack_bot.py /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.9.1 2 | six==1.10.0 3 | slackclient==1.0.0 4 | websocket-client==0.37.0 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # slack_bot_tutorial 2 | Creating a slack bot using slack RTM. 3 | 4 | Based on the tutorial http://kazuar.github.io/building-slack-game-part1/ 5 | -------------------------------------------------------------------------------- /slack_bot.py: -------------------------------------------------------------------------------- 1 | import time 2 | from slackclient import SlackClient 3 | 4 | BOT_TOKEN = "" 5 | CHANNEL_NAME = "general" 6 | 7 | def main(): 8 | # Create the slackclient instance 9 | sc = SlackClient(BOT_TOKEN) 10 | 11 | # Connect to slack 12 | if sc.rtm_connect(): 13 | # Send first message 14 | sc.rtm_send_message(CHANNEL_NAME, "I'm ALIVE!!!") 15 | 16 | while True: 17 | # Read latest messages 18 | for slack_message in sc.rtm_read(): 19 | message = slack_message.get("text") 20 | user = slack_message.get("user") 21 | if not message or not user: 22 | continue 23 | sc.rtm_send_message(CHANNEL_NAME, "<@{}> wrote something...".format(user)) 24 | # Sleep for half a second 25 | time.sleep(0.5) 26 | else: 27 | print("Couldn't connect to slack") 28 | 29 | if __name__ == '__main__': 30 | main() 31 | 32 | --------------------------------------------------------------------------------