1. Go to this page and download the library: Download yuki777/slack 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/ */
yuki777 / slack example snippets
// Instantiate without defaults
$client = new Nexy\Slack\Client('https://hooks.slack.com/...');
// Instantiate with defaults, so all messages created
// will be sent from 'Cyril' and to the #accounting channel
// by default. Any names like @regan or #channel will also be linked.
$settings = [
'username' => 'Cyril',
'channel' => '#accounting',
'link_names' => true
];
$client = new Nexy\Slack\Client('https://hooks.slack.com/...', $settings);
$client->send('Hello world!');
$client->to('#accounting')->send('Are we rich yet?');
$client->to('@regan')->send('Yo!');
$client->from('Jake the Dog')->to('@FinnTheHuman')->send('Adventure time!');
// Either with a Slack emoji
$client->to('@regan')->withIcon(':ghost:')->send('Boo!');
// or a URL
$client->to('#accounting')->withIcon('http://example.com/accounting.png')->send('Some accounting notification');
$client->to('#operations')->attach((new \Nexy\Slack\Attachment())
->setFallback('Server health: good')
->setText('Server health: good')
->setColor('danger')
)->send('New alert from the monitoring system'); // no message, but can be provided if you'd like
$client->to('#operations')->attach((new \Nexy\Slack\Attachment())
->setFallback('Current server stats')
->setText('Current server stats')
->setColor('danger')
->setFields([
new \Nexy\Slack\AttachmentField(
'Cpu usage',
'90%',
true // whether the field is short enough to sit side-by-side other fields, defaults to false
),
new \Nexy\Slack\AttachmentField('RAM usage', '2.5GB of 4GB', true),
])
)->send('New alert from the monitoring system'); // no message, but can be provided if you'd like
$client->to('@regan')->attach((new \Nexy\Slack\Attachment())
->setFallback('Keep up the great work! I really love how the app works.')
->setText('Keep up the great work! I really love how the app works.')
->setAuthorName('Jan Appleseed')
->setAuthorLink('https://yourapp.com/feedback/5874601')
->setAuthorIcon('https://static.pexels.com/photos/61120/pexels-photo-61120-large.jpeg')
)->send('New user feedback');
$client->to('#weird')->disableMarkdown()->send('Disable *markdown* just for this message');
$client->to('#general')->enableMarkdown()->send('Enable _markdown_ just for this message');
$client->to('#operations')->attach((new \Nexy\Slack\Attachment())
->setFallback('It is all broken, man')
->setText('It is _all_ broken, man')
->setPretext('From user: *JimBob*')
->setColor('danger')
->setMarkdownFields(['pretext', 'text'])
)->send('New alert from the monitoring system');
// Implicitly
$client->to('@regan')->send('I am sending this implicitly');
// Explicitly
$message = $client->createMessage();
$message->to('@regan')->setText('I am sending this explicitly');
$message->send();
$attachment = (new Attachment())
->setFallback('Some fallback text')
->setText('The attachment text')
;
// Explicitly create a message from the client
// rather than using the magic passthrough methods
$message = $client->createMessage();
$message->attach($attachment);
// Explicitly set the message text rather than
// implicitly through the send method
$message->setText('Hello world')->send();
// implicitly create a message and set the attachments
$client->setAttachments($bigArrayOfAttachments);
// or explicitly
$client->createMessage()->setAttachments($bigArrayOfAttachments);
$attachment = new Attachment();
$attachment->setFields($bigArrayOfFields);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.