PHP code example of coderstephen / slack-client
1. Go to this page and download the library: Download coderstephen/slack-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
coderstephen / slack-client example snippets
$loop = \React\EventLoop\Factory::create();
$client = new \Slack\ApiClient($loop);
$client->setToken('YOUR-TOKEN-HERE');
// ...
$loop->run();
$client->getChannelById('C025YTX9D')->then(function (\Slack\Channel $channel) use ($client) {
$client->send('Hello from PHP!', $channel);
});
use Slack\Message\{Attachment, AttachmentBuilder, AttachmentField};
$message = $client->getMessageBuilder()
->setText('Hello, all!')
->setChannel($someChannelObject)
->addAttachment(new Attachment('My Attachment', 'attachment text'))
->addAttachment(new Attachment('Build Status', 'Build failed! :/', 'build failed', 'danger'))
->addAttachment(new AttachmentBuilder()
->setTitle('Some Fields')
->setText('fields')
->setColor('#BADA55')
->addField(new AttachmentField('Title1', 'Text', false))
->addField(new AttachmentField('Title2', 'Some other text', true))
->create()
]))
->create();
$client->postMessage($message);
$client = new \Slack\RealTimeClient();
$client->setToken('YOUR-TOKEN-HERE');
$client->connect();
$client->on('file_created', function($data) {
echo 'A file was created called ' . $data['file']['name'] . '!\n';
});
$loop = React\EventLoop\Factory::create();
$client = new Slack\RealTimeClient($loop);
$client->setToken('YOUR-TOKEN-HERE');
// disconnect after first message
$client->on('message', function ($data) use ($client) {
echo "Someone typed a message: ".$data['text']."\n";
$client->disconnect();
});
$client->connect()->then(function () {
echo "Connected!\n";
});
$loop->run();