sagebind / slack-client Goto Github PK
View Code? Open in Web Editor NEWA better Slack client, with RTM API support.
License: MIT License
A better Slack client, with RTM API support.
License: MIT License
Switch from React PHP to Icicle, which is so much easier to work with and so much cooler. Icicle should have a usable websocket package soon, which will be much more actively maintained and less buggy than PHPWS., which was a less-than-ideal dependency anyway.
This will be a major change, and will be bundled with other changes toward a v1.0 release. All React-related code will be removed and replaced with Icicle. Guzzle may also be removed in favor of icicleio/http
. A name change may also be involved.
Shameless plug: I'm a member of the Icicle team. ๐
Hi all,
I'm sorry to bother but seems no one have my problem with PHP7.
With PHP 5.6 all good, but after my update to PHP 7,
I started to receive a React Timeout Error.
I can copy and paste the issue, but I don't know how much could be useful.
React\Promise\Timer\TimeoutException: Timed out after 5 seconds in...
#0 [internal function]: React\Promise\Timer{closure}(Object(React\EventLoop\Timer\Timer))
Next React\Dns\Query\TimeoutException: DNS query for mpmulti-dgb1.slack-msgs.com timed out in...
All my composer library has been updated to the latest version, and honestly I don't know what to do.
Anyone can help me please?
Thank you so much.
Regards
No mater what i have tried i just cant get this lib to send messages with attachments, some sort of explanation or sample code could be extremely helpfull
I actually noticed this while using https://github.com/chrisgillis/slackwolf which has slack-client as a dependency. It'd be nice if there was a way to 'refresh' the data for an object; in this particular case I'd like to re-get the list of users in a channel, but I imagine being able to refresh most things would be nice. As it is now I can only force a disconnect and then re-connect, which repopulates all the objects with new data.
I see the actual API calls to fetch the data required are in ApiClient, but they're hidden away behind implementations of Channel and whatnot.
I see that there is a loop, is it based off of when a user sends a message in the channel? I'd like to have a function ran when someone inputs a message. Right now, I'm using JS to refresh the div and send a request every minute or so.
I've tried multiple different things, like:
$user = new User($client, $data['user']);
but I can't get them to work.
EDIT: the error I receive:
Slack\ClientObject::__construct() must be of the type array, string given
Title basically says it all. ApiClient->getDMById() tries to call Slack "im.info", but "im.info" isn't a valid method. See list of valid methods: https://api.slack.com/methods
This is an issue to remind myself to set up documentation on how to use stuff :P.
class Slack\Payload#287 (1) {
protected $data =>
array(6) {
'type' =>
string(7) "message"
'channel' =>
string(9) "G0GNUPNRX"
'user' =>
string(9) "U1"
'text' =>
string(6) "!start"
'ts' =>
string(17) "1450242920.000008"
'team' =>
string(9) "T1"
}
}
PHP Notice: Undefined index: G0GNUPNRX in /Users/chris/slackwolf/vendor/coderstephen/slack-client/src/RealTimeClient.php on line 170
I am running the latest version of slack-client (installed via composer) and I set up the simple test:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$loop = React\EventLoop\Factory::create();
$client = new Slack\RealTimeClient($loop);
$client->setToken('xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
// disconnect after first message
$client->on('message', function ($data) {
echo "Someone typed a message: ".$data['text']."\n";
$client->disconnect();
});
$client->connect()->then(function () {
echo "Connected!\n";
});
$client->on('hello', function() {
echo "EHLO\n";
}
$loop->addPeriodicTimer(1, function() {
echo "Tick\n";
});
$loop->run();
I am only getting the tick output when I run the script. Any ideas?
it work for me if i just simple message posting, but once I try to integrate with attachment message, the whole process keep looping, sending message to channel.
I use this dependice for my bot's enterprise and when I format with sprintf
about 8 times it's okay but after it didn't work :-(
I don't know if it's you're side or mine, but don't leave youre project ๐
See ya.
Hi,
Lib been working really well in PHP5. Gave my app a go on PHP 7 today but couldn't get it to work. As far as I can tell everything is the same, except the PHP version, has anyone else had success running the RealTimeClient in PHP7?
The WebSocket appears to be connecting, but nothing happens after that. Waiting for ->on('hello') or ->on('error') nothing happens. Eventually the react loop seems to stop and the script exits.
Will try to debug further, but not had much luck pinpointing it so far. Throwing this out there in case anyone has any suggestions?
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
Hi there, I believe this is a bug with the websocket package and not your package directly, but every event comes in twice (with the same payload) which causes everything to be triggered twice:
object(Devristo\Phpws\Messaging\WebSocketMessage)#53 (2) {
["frames":protected]=>
array(1) {
[0]=>
object(Devristo\Phpws\Framing\WebSocketFrame)#2094 (10) {
["FIN":protected]=>
int(1)
["RSV1":protected]=>
int(0)
["RSV2":protected]=>
int(0)
["RSV3":protected]=>
int(0)
["opcode":protected]=>
int(1)
["mask":protected]=>
int(0)
["payloadLength":protected]=>
int(63)
["maskingKey":protected]=>
int(0)
["payloadData":protected]=>
string(63) "{"type":"user_typing","channel":"D214XLEJG","user":"U096BVDUM"}"
["actualLength":protected]=>
int(0)
}
}
["data":protected]=>
string(0) ""
}
object(Devristo\Phpws\Messaging\WebSocketMessage)#53 (2) {
["frames":protected]=>
array(1) {
[0]=>
object(Devristo\Phpws\Framing\WebSocketFrame)#2094 (10) {
["FIN":protected]=>
int(1)
["RSV1":protected]=>
int(0)
["RSV2":protected]=>
int(0)
["RSV3":protected]=>
int(0)
["opcode":protected]=>
int(1)
["mask":protected]=>
int(0)
["payloadLength":protected]=>
int(63)
["maskingKey":protected]=>
int(0)
["payloadData":protected]=>
string(63) "{"type":"user_typing","channel":"D214XLEJG","user":"U096BVDUM"}"
["actualLength":protected]=>
int(0)
}
}
["data":protected]=>
string(0) ""
}
object(Devristo\Phpws\Messaging\WebSocketMessage)#53 (2) {
["frames":protected]=>
array(1) {
[0]=>
object(Devristo\Phpws\Framing\WebSocketFrame)#2094 (10) {
["FIN":protected]=>
int(1)
["RSV1":protected]=>
int(0)
["RSV2":protected]=>
int(0)
["RSV3":protected]=>
int(0)
["opcode":protected]=>
int(1)
["mask":protected]=>
int(0)
["payloadLength":protected]=>
int(116)
["maskingKey":protected]=>
int(0)
["payloadData":protected]=>
string(116) "{"type":"message","channel":"D214XLEJG","user":"U096BVDUM","text":"Hey","ts":"1488026184.000017","team":"T02TZ7DQW"}"
["actualLength":protected]=>
int(0)
}
}
["data":protected]=>
string(0) ""
}
object(Devristo\Phpws\Messaging\WebSocketMessage)#53 (2) {
["frames":protected]=>
array(1) {
[0]=>
object(Devristo\Phpws\Framing\WebSocketFrame)#2094 (10) {
["FIN":protected]=>
int(1)
["RSV1":protected]=>
int(0)
["RSV2":protected]=>
int(0)
["RSV3":protected]=>
int(0)
["opcode":protected]=>
int(1)
["mask":protected]=>
int(0)
["payloadLength":protected]=>
int(116)
["maskingKey":protected]=>
int(0)
["payloadData":protected]=>
string(116) "{"type":"message","channel":"D214XLEJG","user":"U096BVDUM","text":"Hey","ts":"1488026184.000017","team":"T02TZ7DQW"}"
["actualLength":protected]=>
int(0)
}
}
["data":protected]=>
string(0) ""
}
The only way I've been able to mitigate this is to do something like:
$messages = [];
$client->on('message', function ($data) use (&$messages) {
$dataArray = $data->jsonSerialize();
if ($key = array_search($dataArray, $messages, true))
{
unset($key);
return;
}
$messages[] = $data;
This might just be something I misunderstood, but I made a message with an attachment like the following, but I just can't seem to get markdown enabled. I tried adding the mrkdown_in
to the attachment fields (https://api.slack.com/docs/message-formatting), but I haven't gotten it to work yet.
$message = $client->getMessageBuilder()
->setText('Ordinary text')
->setChannel($channel)
->addAttachment(new Attachment('This is my attachment:', 'This *is* _my_ text', "#BADA55", "Pretext with *bold* word", ['mrkdown_in' => ['text', 'pretext', 'fields']]))
->create();
The markdown is never parsed, when it get's into the channel.
Hi there, great Slack client, thanks!
There seems to be an issue
$client->getAuthedUser()->done(function ($user) {
//something
});
where $client is the RealTimeClient. It outputs the notice: PHP Notice: Undefined index: XXXXXXX in /vagrant/dev/slack/vendor/coderstephen/slack-client/src/RealTimeClient.php on line 218
and $user is null.
Or am I using this incorrectly?
Because of https://github.com/coderstephen/slack-client/blob/master/src/RealTimeClient.php#L116, errors in websocket connections don't actually print errors. I spent two hours trying to work out why my program was exiting without complaining about anything. There must be a better way of doing this, perhaps a spoofing object of some sort?
I am running a Python script in a Windows server machine to use the Slack RTM API to listen on new incoming messages addressed to a bot. Based on the message, I write back to the Slack channel where the question was asked.
Unfortunately, the websocket used by RTM API is randomly getting closed, forcing me to come up with a workaround where I have to call slack_client.rtm_connect() in my except block to re-connect.
This is causing two issues:
Attached is the excerpt from my Python script.
Please let me know if this is a known bug or have a better to handle this type of websocket error.
Thank you in advance for your reply.
Bastien
I'm trying to create channel using Bot User OAuth Access Token.
I've selected all Permission Scopes for the bot, but always get this exception:
exception 'Slack\ApiException' with message 'Missing scope' in /storage/www/redminetoslack/vendor/coderstephen/slack-client/src/ApiClient.php:415
Stack trace:
#0 /storage/www/redminetoslack/vendor/guzzlehttp/promises/src/Promise.php(203): Slack\ApiClient->Slack\{closure}(Object(GuzzleHttp\Psr7\Response))
#1 /storage/www/redminetoslack/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#2 /storage/www/redminetoslack/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#3 /storage/www/redminetoslack/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(96): GuzzleHttp\Promise\TaskQueue->run()
#4 /storage/www/redminetoslack/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(123): GuzzleHttp\Handler\CurlMultiHandler->tick()
#5 /storage/www/redminetoslack/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
#6 /storage/www/redminetoslack/vendor/guzzlehttp/promises/src/Promise.php(223): GuzzleHttp\Promise\Promise->invokeWaitFn()
#7 /storage/www/redminetoslack/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\Promise\Promise->waitIfPending()
#8 /storage/www/redminetoslack/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\Promise\Promise->invokeWaitList()
#9 /storage/www/redminetoslack/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#10 /storage/www/redminetoslack/vendor/coderstephen/slack-client/src/ApiClient.php(397): GuzzleHttp\Promise\Promise->wait()
#11 [internal function]: Slack\ApiClient->Slack\{closure}(Object(React\EventLoop\StreamSelectLoop))
#12 /storage/www/redminetoslack/vendor/react/event-loop/src/Tick/FutureTickQueue.php(46): call_user_func(Object(Closure), Object(React\EventLoop\StreamSelectLoop))
#13 /storage/www/redminetoslack/vendor/react/event-loop/src/StreamSelectLoop.php(175): React\EventLoop\Tick\FutureTickQueue->tick()
#14 /storage/www/redminetoslack/helper.php(335): React\EventLoop\StreamSelectLoop->run()
#15 /storage/www/redminetoslack/helper.php(426): SlackClient->createChannel('issue-14787', 'creating interi...', 'The content for...', Array)
#16 /storage/www/redminetoslack/helper.php(511): RedmineToSlack->checkChannel()
#17 /storage/www/redminetoslack/helper.php(408): RedmineToSlack->processRedmineIssue(Object(stdClass))
#18 /storage/www/redminetoslack/index.php(10): RedmineToSlack->processRedmineIssues()
#19 {main}
Here is my code:
$this->loop = \React\EventLoop\Factory::create();
$this->client = new \Slack\ApiClient($this->loop);
$this->client->setToken($token);
$this->client->apiCall('channels.create', ['name' => $name])->then(function(\Slack\Payload $response) {
$channel = new \Slack\Channel($this->client, $response['channel']);
$this->channels[$channel->getName()] = $channel;
})->otherwise(function($reason) {
echo $reason->__toString().PHP_EOL;
});
$this->loop->run();
I got same if trying to add bot to existing channel.
What I'm doing wrong?
Hello,
API Documentation url is down
Under PHP version 5.6 or greater, the real-time client refuses to connect to Slack using SSL, throwing various exceptions that look similar to this:
2015-06-04T22:56:25-05:00 ERR (3): exception 'UnexpectedValueException' with message '
Unable to complete SSL/TLS handshake: stream_socket_enable_crypto():
Peer certificate CN=`*.slack-msgs.com' did not match expected CN=`<IP_ADDRESS>''
in /data/projects/slack-client/vendor/react/socket-client/src/StreamEncryption.php:96
When using postMessage() and getMessageBuilder to build my messages, formatted text and newlines work fine but when I try linking my strings, it shows as the raw text instead of the linked text.
An example would be
<http://www.google.com|google>
returns as such in the message when it should show as
Every good library needs a complete suite of tests. The goal is at least 70% coverage. Test coverage and results can be viewed on Scrutinizer.
$ composer require coderstephen/slack-client
Using version ^0.2.0 for coderstephen/slack-client
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.Problem 1
- Installation request for coderstephen/slack-client ^0.2.0 -> satisfiable by coderstephen/slack->client[v0.2.0].
- coderstephen/slack-client v0.2.0 requires devristo/phpws dev-master -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion for more details.Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.
Installation failed, deleting ./composer.json.
Problem 1
- Installation request for coderstephen/slack-client ^0.2.5 -> satisfiable by coderstephen/slack-client[v0.2.5].
- coderstephen/slack-client v0.2.5 requires devristo/phpws dev-master -> satisfiable by devristo/phpws[dev-master] but these conflict with your requirements or minimum-stability.
Is there a way I can still use this package?
I'm using example code, and this callback newer works with PM's, only with pubic channels:
$client->on('message', function ($data) use ($client) {
$client->getChannelById($data['channel'])->then(function (\Slack\Channel $channel) use ($client) {
print $channel->getId();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.