Guest User

Untitled

a guest
Jan 21st, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. def start_bot(redis_object):
  2. print('In start bot')
  3. slack_client = SlackClient('xoxb-xxxx')
  4. bot_id = None
  5. PING_DELAY = 1 #1 sec
  6. response = ''
  7. if slack_client.rtm_connect(with_team_state=False):
  8. print("Starter Bot connected and running!")
  9. bot_id = slack_client.api_call("auth.test")["user_id"]
  10. while True:
  11. rtm_response = slack_client.rtm_read()
  12. #print(rtm_response)
  13. command, channel = parse_bot_commands(rtm_response,bot_id)
  14. if command:
  15. print("Channel",channel)
  16. response = handle_command(command, channel,redis_object)
  17. print(str(1),'########',response)
  18. requests.get('https://slack.com/api/chat.postMessage',
  19. headers={'Authorization': 'Basic xxxx'},
  20. params = {'text': response, 'channel': channel})
  21. time.sleep(PING_DELAY)
  22. else:
  23. print("Connection failed.")
Add Comment
Please, Sign In to add comment