Recover messages when on disconnection
Add an option to automatically recover messages sent during the time has been auto disconnected from slack.
You mean build-in retry? What's your scenario? Are we talking RTM or Web API?
RTM. Not a retry but to recover the messages we missed during the time was disconnected. Sometimes the connection is disconnected for a second or a little longer and if we are not lucky and a message was sent during that time, the bot will never respond, even though the connection will be recovered in a second.
I see. I could be wrong, but I don't think Slack provides that kind of facility.
We could try an exponential backoff, synchronously. Something like this
number_of_retries = 3 backoff_factor = 2 attempt = 1
First attempt after 2 seconds. [attempt] Second attempt after 22 (4) seconds. [attempt x backoff_factor] Third attempt after 42(8) seconds. [attempt x backoff_factor] Finally return result (Success/failure) The api would return only after all the retries have been completed.
But I don't know if this would be overkill. Considering that the gem returns an error response, the apps using this gem could implement this functionality.
I think the issue describes recovering incoming RTM messages that were missed, not retrying API calls (that is more standard in client libraries and I'd be open to having that implemented via https://www.rubydoc.info/github/lostisland/faraday/Faraday/Request/Retry).
Just to clarify this is the case using the client.on :close, client.on :closed, client.on :hello [2020-09-28T16:24:08.723056 #17096] INFO -- : Connection closing, exiting. 2020-09-28 16:24:08 +0000 [2020-09-28T16:24:08.723391 #17096] INFO -- : Connection has been disconnected. 2020-09-28 16:24:08 +0000 [2020-09-28T16:24:10.113424 #17096] INFO -- : Successfully connected, welcome 'smart-bot' to the 'xxxxxx' team at https://xxxxxx.slack.com.
So a couple of seconds where the Bot was disconnected, so not listening and if during that time a user sent a message the bot won't be aware of that message and won't respond.
I am facing this kind of disconnections like 10 times every day.
So if we would be aware of the last message received and then on :hello we recover all messages sine last connection we can filter the ones that were sent during the disconnection.
I don't know of a way to recover those messages :(
This is one of the reasons to switch from an RTM solution to an event-based one (using https://github.com/slack-ruby/slack-ruby-bot-server-events), where Slack will queue messages if your application is not able to respond.