-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Old events firing when botkit restarts (after upgrade) #663
Comments
A little more info: On startup, I am also seeing other messages without the |
Final note: When I revert back to |
@sporkd This may actually be related to an issue Slack is having with their API. |
Thanks @benbrown. However, if I move back and forth between |
Perhaps not! Are you using the RTM? Events API? |
@benbrown I'm using RTM in a custom integration. I've put in some additional logging and can confirm that the bot is in fact responding to one of it's own previous replies from before the restart. The whole interaction is happening inside a Slack direct message session I'm having with the bot itself. Botkit seems to be regarding it's own most recent reply as a direct message to itself, and is re-triggering it on the every restart. I am using CTL-C in development mode to stop nodemon. |
So you are receiving those messages again after the bot has restarted? Can you confirm that they are coming down the wire from Slack again? |
Good question. Actually the message does not appear to be coming from slack. I have the following and the controller.on('message_received', function(bot, message) {
console.log("MESSAGE RECEIVED ", message);
}
controller.hears('\\b(help)\\b', ['direct_message','direct_mention','mention'], (bot, message) => {
console.log("HELP EVENT RECEIVED ", message);
}); In this case, it seems to be replaying a message that the bot itself already generated. The message.text getting logged is text that the bot already responded with in a previous server run. e.g. |
This is strange for a number of reasons, not the least of which is that Botkit by default should NOT hear its own messages. |
Yes, I do see |
@benbrown Ok, found the problem! The line of code in SlackBot.js to check if a message is from the Bot itself looks like this: Unfortunately
Now I think the second scenario in particular is where there's a strong argument that I located the commit where the And I can confirm that reverting that commit solves all my issues. 😂 I also have suspicion that it might also be a factor in the following reported issues involving duplicate messages: (in some instances I was seeing duplicate messages from instances replying to eachother and on RTM reconnect) |
Ive touched that line of code before, when events api was released. I cant
recall why I made the choice that I did there (or maybe I made a different
one).
Theres some concerns with slack I believe where bot_id is all you have when
using an incoming webhook to post as your app. Its a lil messy on the slack
end with determining if the message was by YOUR bot or just a bot. In order
to avoid infinite loops of bots talking to bots, I think, we are ignoring
messages from all bots here.
Botkit doesnt have a standard for talking to other bots, yet. Would be a
cool api to implement if anyones up for it!
We need to make tests that can catch this stuff when things get changed,
especially as more people are relying on botkit and getting bigger.
Im trying to create a serverless botkit flavor for a client project to
prepare them to scale easily, so very interested in your efforts to load
balance on ec2! We are using elastic beanstalk until I can get us onto
lambda 👍
…On Fri, Feb 17, 2017 at 5:24 PM Peter Gumeson ***@***.***> wrote:
@benbrown <https://github.com/benbrown> Ok, found the problem! The line
of code in SlackBot.js to check if a message is from the Bot itself looks
like this: if (message.user == bot.identity.id && message.bot_id).
Unfortunately message.bot_id is not always present! I discovered in our
case it's because I have 2 different Botkit instances connecting to the
same Bot configured in Slack. Guessing that may not be standard, but
perhaps valid when trying to divide event handling between multiple
instances. Anyway, the root of the problem seems to be twofold given two
instances, botkit1 and botkit2:
1.
message.bot_id will always come back undefined when botkit2 instance
hears a message from botkit1. In that case I would think the proper
thing to do would be to ignore the message because message.user ==
bot.identity.id. That means the message was sent by the bot user
configured in Slack. However, in the scenario above, the first test will
pass, but message.bot_id will be undefined. So botkit2 will go ahead
and continue processing that message, even though it's from... "itself"?
2.
Then, the issue I was seeing on restart was a bit of a continuation of
the first; It seems that when RTM reconnects, Slack will remember the most
recent message from (all?) users in that channel, and resend them. Guessing
so you can attempt to reprocess. So again, what was happening was a message
sent by botkit1 was getting picked up when botkit2 instance came
online.
Now I think the second scenario in particular is where there's a strong
argument that message.bot_id shouldn't be checked. Imagine a scenario
where an EC2 instance gets rebuilt and comes back online to replace an old
instance. As things currently stand, the Bot will try to process it's own
most recent messages thinking they are from a non-bot user.
I located the commit where the bot_id check was introduced here. 6db1cff
<6db1cff>
And I can confirm that reverting that commit solves all my issues. 😂
I also have suspicion that it might also be a factor in the following
reported issues involving duplicate messages:
#393 <#393>
#473 <#473>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#663 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AMUR24fHQMko94YEeEV2Wkl_oK0lbpoEks5rdh4cgaJpZM4MDeHK>
.
|
Thanks for your reply @jonchurch. Sorry I'm just now getting back to you. to address your first point:
This is actually not true. That would be: As it stands, it only ignores if And it seems I'm not alone in noticing missing The original issue #271 that introduced the However, notice in the above announcement that an |
Another suggestion is to actually just go ahead and make the change to So either if (message.as_user) {
// this is our bot posting as another user
if (message.user == bot.identity.id && message.bot_id) {
return false;
}
} else {
// this is our bot
if (message.user == bot.identity.id) {
return false;
}
} or // this is our bot or any another bot
if (message.user == bot.identity.id || message.bot_id) {
return false;
} EDIT: removed 3rd option b/c it probably wouldn't work. Thoughts? @benbrown @jonchurch |
@sporkd I see now what you are talking about! Thanks for all the detail. I think that I'm partial to the second choice. This sounds like a sane and pragmatic fix for some smelly code. Would remove the ability for people to respond to bot messages, but this isn't officially supported yet anyways. Closing it off for the master branch would give us time to think through officially supporting that before people start relying on it as a feature. I'll submit a PR This might solve some of the phantom double message edge case issues that have been kicking around forever to boot. |
Sounds good @jonchurch. In that case I also agree second option is better. In Issue #271 they even propose an additional fix would be checking for ANY presence of bot_id, which option 2 does. I'll watch for the new release and test it out. Thanks for bearing with the long description. Lots of details. |
Is there any update on this ? I am experiencing the same issue with a single slack bot on reconnect. Slack is sending back the last message 1 or 2 times so it get processed again. @jonchurch did you get to submit a PR in the end ? Thanks in advance for the update. |
@tlvenn I too was experiencing this problem. I ended up editing my Slackbot_worker.js to include lastPong != 0 on line 210.
|
How do I access the slackbot_worker.js file if I'm using glitch? |
Hi. I just upgraded to latest version of botkit from a pretty old version (v0.1.1). The problem is now when I start (or restart) botkit, it seems to be remembering the last message that was received, and is triggering that event again. The reason I know it's an old event, is the incoming message contains the same value, e.g
{ reply_to: 106 }
even between restarts. The only way to make it forget 106 is to send a new message into slack. But then that new message becomes the one that gets stuck asreply_to
when I restart botkit.This was definitely not an issue in the previous version I was using.
My event handlers look mostly like this: (however the one that gets triggered will depend on the current message stuck in
reply_to
)The text was updated successfully, but these errors were encountered: