litaio / lita-slack

A Slack adapter for Lita.
MIT License
141 stars 130 forks source link

Lita receives last message again when restarted #101

Open ekilah opened 8 years ago

ekilah commented 8 years ago

Context: this is ported over from a conversation at https://github.com/litaio/lita/issues/197

It seems that the Slack RTM connection always re-receives the last message that was sent by Lita when restarting the Lita process after a deploy.

I'm noticing this while trying to implement a :unhandled_message event handler in my custom Lita handler.

To clarify, here's the sequence I see:

> me: lita valid_command
> lita: response to valid_command
> me: other message(s), not necessarily directed at lita (this is optional)
# CTRL+C lita server, restart it with `lita start`
> lita: Sorry, I don't understand the command "response to valid_command".

The last line is produced by my on(:unhandled_message) block. Can anyone else replicate this behavior? It seems like a bug to me... or, at least, something that the adapter should filter out since it might be slack's "fault" (or feature)? I have yet to narrow down the cause. I'm a new Lita user.

I could probably work around it by seeing if the message was sent by the bot (sorta related to https://github.com/litaio/lita-slack/pull/95), but it seems like this shouldn't be necessary? I can also make this not happen as often by filtering by command? in the unhandled_message block, but that doesn't prevent DMs from suffering from this if that's where lita's last message went.

Lita logs showing this behavior: (my comments are prefixed by #s)

[2016-07-29 08:37:55 UTC] DEBUG: Dispatching message to Lita from <my UID>. # this is my unhandled message, lita replies to it immediately as expected
^C[2016-07-29 08:38:03 UTC] INFO: Disconnected from Slack.
[2016-07-29 08:38:03 UTC] DEBUG: Closing connection to the Slack Real Time Messaging API.
[2016-07-29 08:38:03 UTC] DEBUG: Closing connection to the Slack Real Time Messaging API.
bash-3.2$ lita start
[2016-07-29 08:38:04 UTC] DEBUG: Connecting to the Slack Real Time Messaging API.
[2016-07-29 08:38:05 UTC] DEBUG: Connected to the Slack Real Time Messaging API.
[2016-07-29 08:38:05 UTC] INFO: Connected to Slack.
[2016-07-29 08:38:05 UTC] DEBUG: reconnect_url event received from Slack and will be ignored.
[2016-07-29 08:38:05 UTC] DEBUG: Dispatching message to Lita from <Lita's UID> # this logs that Lita re-receives the message that it sent to me in response to the unhandled message
ekilah commented 8 years ago

I will have to test again - for now, I've stopped trying to use the unhandled message handler.

However, this does sound a bit related to https://github.com/litaio/lita-slack/pull/90 so maybe it is resolved / a similar thing. I will try and test this theory and play with this more when I have some free time...