Skip to content
This repository has been archived by the owner on Jun 4, 2018. It is now read-only.

Pawl WebSocket Client #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@ public function docsPublish($message = 'Regenerate docs')
->checkout('master')
->run();
}

/**
* Run the example bot.
*
* @param string $token Slack RealTime Messaging Token
*/
public function exampleBot($token)
{
$this->taskExec('bin/examplebot')
->arg($token)
->run();
}
}
38 changes: 38 additions & 0 deletions bin/examplebot
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env php
<?php
/**
* Bot Example
*/

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

// Ensure API Key has been provided
if (! isset ($argv[1])) {
die('Usage: ' . $argv[0] . ' <token>' . PHP_EOL);
}

use Slack\RealTimeClient as Client;

// Event Loop
$loop = \React\EventLoop\Factory::create();

// Console Output
$out = new \React\Stream\Stream(STDOUT, $loop);

$client = new Client($loop);
$client->setToken($argv[1]);

// disconnect after first message
$client->on('message', function ($message) use ($client, $out) {
$out->write('Someone typed a message:'.$message['text'].PHP_EOL);
$client->disconnect();
$out->end('Goodbye.'.PHP_EOL);
});

$client->connect()->then(function () use ($out) {
$out->write('Connected! Waiting for a message...'.PHP_EOL);
}, function (\Exception $ex) use ($out) {
$out->end('Error: '.$ex->getMessage().PHP_EOL);
});

$loop->run();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}],
"require": {
"php": ">=5.5",
"devristo/phpws": "dev-master",
"ratchet/pawl": "^0.2",
"evenement/evenement": "2.0.*",
"guzzlehttp/guzzle": "~6.0",
"react/event-loop": "^0.4.1",
Expand Down
Loading