Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot loses connection to Slack #30

Open
gugglegum opened this issue Mar 9, 2018 · 2 comments
Open

Bot loses connection to Slack #30

gugglegum opened this issue Mar 9, 2018 · 2 comments

Comments

@gugglegum
Copy link

gugglegum commented Mar 9, 2018

The bot loses connection sometimes and does nothing with it. In slack chat (web-)application slackbot user just become with gray circle (offline). But the script continues to run, need to be killed and restarted. Isn't there a way to force the bot to check is connection alive and throw an exception if not?

The code (excepting code of commands and config):

<?php

require __DIR__ . '/vendor/autoload.php';

use PhpSlackBot\Bot;
use SlackBot\Commands\AlphaLockCommand;
use SlackBot\Commands\AlphaShipmentCommand;
use SlackBot\Commands\GetItemQtyCommand;
use SlackBot\Commands\StatusCommand;

$config = require __DIR__ . '/config.php';

$bot = new Bot();
$bot->setToken($config['slackbot']['token']);
try {
    $bot->loadCommand(new StatusCommand());
    $bot->loadCommand(new GetItemQtyCommand());
    $bot->loadCommand(new AlphaLockCommand());
    $bot->loadCommand(new AlphaShipmentCommand());
    $bot->run();
} catch (\Exception $e) {
    echo $e->getMessage(), "\n";
}
@jclg
Copy link
Owner

jclg commented Mar 11, 2018

Instead of throwing an exception, I think it would be better to check periodically (using a react loop timer) if the bot is still online and re-connect automatically.
To detect disconnections, we can use ping/pong messages specified in the Slack RTM protocol. https://api.slack.com/rtm Section "Ping and Pong"

I am busy at the moment so any help will be very welcome 😃

@djdevin
Copy link
Contributor

djdevin commented Aug 20, 2018

This is likely due to this change, maybe it was acting as a keepalive.

RTM API Presence is now only available via subscription.
As of January 2018, presence_change events are not dispatched without presence subscriptions established with presence_sub. Relatedly, current user presence status is no longer communicated in rtm.start.

https://api.slack.com/docs/presence-and-status#presence

I've used this bot for a while and only recently would it disconnect frequently :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants