slack-client icon indicating copy to clipboard operation
slack-client copied to clipboard

Implement ping/pong

Open steefmin opened this issue 9 years ago • 4 comments

Are you planning to implement ping/pong messages to the slack api such that the client can monitor its connection and reconnect when it is dropped? I'm having some issues with my connection and it looks like the client stays active after a connection drop, but it is dropped from slack's point of view. A similar sollution worked in another slack-bot project

steefmin avatar Jun 17 '16 07:06 steefmin

+1

Lisennk avatar Jul 12 '16 19:07 Lisennk

+1

paulprinke avatar Jul 14 '16 20:07 paulprinke

I don't think I'll be implementing this feature, as I don't have enough resources to actively develop this project, but I am definitely open to someone else implementing it. I can offer advice and guidance on ReactPHP if that is a barrier for anyone looking into it themselves.

sagebind avatar Jul 14 '16 22:07 sagebind

For anyone interested, I hacked a solution into my rather hacky bot script:

$nReconnects = 0;
do {
	$oClient->connect()->then(
		function () use ( $oClient, $sDevelopmentChannelId, &$oChannel ) {
			echo "Connected!", PHP_EOL;

			$oClient->getChannelById( $sDevelopmentChannelId )->then(
				function ( \Slack\Channel $oObtainedChannel ) use ( $oClient, &$oChannel ) {
					$oChannel = $oObtainedChannel;
				}
			);
			$oClient->send( 'Reconnected...', $oChannel );
		}
	);

	$oReactLoop->run();

	$nReconnects++;
	sleep(10); // so as not to hammer it, if there are genuine connection issues.
}
while ( $nReconnects <= 10 && !$bDisconnect );

The $bDisconnect is a boolean that is set when the bot receives a disconnect message, so that I can break out of that reconnection loop. Also, the $nReconnects is just a safety for not forever running while you play with it, otherwise just remove it for a forever thing.

This might help some of you without actually implementing anything into the client library. You could also implement a ping/pong in a similar fashion.

dlgoodchild avatar May 05 '17 07:05 dlgoodchild