I want to post a message to Slack through a bot. When I use api/postMessage through the bot, the message gets posted multiple times (sometimes 2,3 and rarely once). When I post the same message through postman, the message is posted only once.
def start_bot(redis_object): print('In start bot') slack_client = SlackClient('xoxb-xxxx') bot_id = None PING_DELAY = 1 #1 sec response = '' if slack_client.rtm_connect(with_team_state=False): print("Starter Bot connected and running!") bot_id = slack_client.api_call("auth.test")["user_id"] while True: rtm_response = slack_client.rtm_read() #print(rtm_response) command, channel = parse_bot_commands(rtm_response,bot_id) if command: print("Channel",channel) response = handle_command(command, channel,redis_object) print(str(1),'########',response) requests.get('https://slack.com/api/chat.postMessage', headers={'Authorization': 'xoxb-xxxx'}, params = {'text': response, 'channel': channel}) time.sleep(PING_DELAY) else: print("Connection failed.")
print(str(1),'########',response) prints only once on the terminal but the message is still posted multiple times in the thread. Posting through slack_client.api_call method also posts multiple times.
#rest #python #postman