{"action":"created","issue":{"url":"https://api.github.com/repos/howdyai/botkit/issues/393","repository_url":"https://api.github.com/repos/howdyai/botkit","labels_url":"https://api.github.com/repos/howdyai/botkit/issues/393/labels{/name}","comments_url":"https://api.github.com/repos/howdyai/botkit/issues/393/comments","events_url":"https://api.github.com/repos/howdyai/botkit/issues/393/events","html_url":"https://github.com/howdyai/botkit/issues/393","id":173754520,"number":393,"title":"Getting multiple messages in response","user":{"login":"Kishanrajdev047","id":3402534,"avatar_url":"https://avatars.githubusercontent.com/u/3402534?v=3","gravatar_id":"","url":"https://api.github.com/users/Kishanrajdev047","html_url":"https://github.com/Kishanrajdev047","followers_url":"https://api.github.com/users/Kishanrajdev047/followers","following_url":"https://api.github.com/users/Kishanrajdev047/following{/other_user}","gists_url":"https://api.github.com/users/Kishanrajdev047/gists{/gist_id}","starred_url":"https://api.github.com/users/Kishanrajdev047/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kishanrajdev047/subscriptions","organizations_url":"https://api.github.com/users/Kishanrajdev047/orgs","repos_url":"https://api.github.com/users/Kishanrajdev047/repos","events_url":"https://api.github.com/users/Kishanrajdev047/events{/privacy}","received_events_url":"https://api.github.com/users/Kishanrajdev047/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/howdyai/botkit/labels/help%20wanted","name":"help wanted","color":"159818"},{"url":"https://api.github.com/repos/howdyai/botkit/labels/Middleware","name":"Middleware","color":"e99695"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-08-29T11:35:46Z","updated_at":"2016-10-03T07:26:25Z","closed_at":null,"body":"I have created a bot using Botkit and wit.ai. It runs perfectly fine. However, after a certain period of time, I start getting multiple messages from the bot. After I restart the node.js service, it starts working normally.\r\n\r\nHere's the code I have written,\r\n\r\n````\r\nconst _bots = {};\r\nfunction trackBot(bot) {\r\n  _bots[bot.config.token] = bot;\r\n}\r\n\r\n const controller = Botkit.slackbot({\r\n     json_file_store: './db_slackbutton_bot/',\r\n     logger: new winston.Logger({\r\n       transports: [\r\n        new (winston.transports.Console)(),\r\n        new (winston.transports.File)({ filename: './bot.log' })\r\n       ]\r\n      }),\r\n     debug: true\r\n })\r\n .configureSlackApp({\r\n   clientId: config.slack.clientId,\r\n   clientSecret: config.slack.clientSecret,\r\n   scopes: ['bot'],\r\n });\r\n\r\n // Handle events related to the websocket connection to Slack\r\n\r\ncontroller.on('rtm_open',function(bot) {\r\n  console.log('** The RTM api just connected!');\r\n});\r\n\r\ncontroller.on('rtm_close',function(bot) {\r\n  // you may want to attempt to re-open\r\n  console.log('** The RTM api just closed');\r\n  bot.startRTM(function(err) {\r\n    if (!err) {\r\n      trackBot(bot);\r\n    }\r\n  });\r\n});\r\n\r\n\r\n\r\n/*\r\n  code for starting RTM\r\n*/\r\ncontroller.storage.teams.all(function(err,teams) {\r\n  if (err) {\r\n    throw new Error(err);\r\n  }\r\n\r\n  // connect all teams   with bots up to slack!\r\n  for (var t  in teams) {\r\n    if (teams[t].bot) {\r\n      controller.spawn(teams[t]).startRTM(function(err, bot) {\r\n        if (err) {\r\n          console.log('Error connecting bot to Slack:',err);\r\n        } else {\r\n          trackBot(bot);\r\n        }\r\n      });\r\n    }\r\n  }\r\n});\r\n\r\ncontroller.on('create_bot',function(bot,config) {\r\n  if (_bots[bot.config.token]) {\r\n    // already online! do nothing.\r\n  } else {\r\n    bot.startRTM(function(err) {\r\n      if (!err) {\r\n        trackBot(bot);\r\n      }\r\n      bot.startPrivateConversation({user: config.createdBy},function(err,convo) {\r\n        if (err)  {\r\n          console.log(err);\r\n        } else {\r\n          convo.say('Hey, thanks for adding me to your team! You can say hi to me to get started :)');\r\n        }\r\n      });\r\n\r\n    });\r\n  }\r\n});\r\n````\r\n\r\nI am not able to figure out what is the issue in the code. These are few errors in the error log,\r\n\r\n````\r\n{\"level\":\"error\",\"message\":\"** BOT ID: after5 ...reconnect failed after #4 attempts and 8050ms\",\"timestamp\":\"2016-08-26T10:53:19.175Z\"}\r\n{\"level\":\"error\",\"message\":\"Abnormal websocket close event, attempting to reconnect\",\"timestamp\":\"2016-08-27T03:08:30.972Z\"}\r\n\r\n````\r\nand the screenshot of the messages,\r\n\r\n![error_message_twice](https://cloud.githubusercontent.com/assets/3402534/18050174/9bf6f224-6e0a-11e6-8480-3eee6fb5c761.png)\r\n"},"comment":{"url":"https://api.github.com/repos/howdyai/botkit/issues/comments/251042689","html_url":"https://github.com/howdyai/botkit/issues/393#issuecomment-251042689","issue_url":"https://api.github.com/repos/howdyai/botkit/issues/393","id":251042689,"user":{"login":"dtesler","id":3260343,"avatar_url":"https://avatars.githubusercontent.com/u/3260343?v=3","gravatar_id":"","url":"https://api.github.com/users/dtesler","html_url":"https://github.com/dtesler","followers_url":"https://api.github.com/users/dtesler/followers","following_url":"https://api.github.com/users/dtesler/following{/other_user}","gists_url":"https://api.github.com/users/dtesler/gists{/gist_id}","starred_url":"https://api.github.com/users/dtesler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtesler/subscriptions","organizations_url":"https://api.github.com/users/dtesler/orgs","repos_url":"https://api.github.com/users/dtesler/repos","events_url":"https://api.github.com/users/dtesler/events{/privacy}","received_events_url":"https://api.github.com/users/dtesler/received_events","type":"User","site_admin":false},"created_at":"2016-10-03T07:26:25Z","updated_at":"2016-10-03T07:26:25Z","body":"@vinodjoseph62 This is likely because the `direct_message` event is being fired multiple times, not because of your responses.  The [Events API](https://api.slack.com/events-api) doesn't seem to have this issue."}}
{"actor":{"display_login":"dtesler"}}