polem / slack-notifier
A simple slack wrapper
Installs: 38 051
Dependents: 1
Suggesters: 0
Security: 0
Stars: 59
Watchers: 6
Forks: 16
Open Issues: 4
Requires
- guzzle/guzzle: ~3
- symfony/console: ~2.4
- symfony/serializer: ~2.4
Requires (Dev)
- phpunit/phpunit: ~3
This package is not auto-updated.
Last update: 2024-12-21 15:24:10 UTC
README
Installation
composer require polem/slack-notifier
Usage
Simple
require __DIR__ . '/vendor/autoload.php'; $client = new Slack\Client('your_team', 'your_token'); $slack = new Slack\Notifier($client); $message = new Slack\Message\Message('Hello world'); $message->setChannel('#test') ->setMrkdwn(true) ->setIconEmoji(':ghost:') ->setUsername('slack-php'); $slack->notify($message);
With attachments
require __DIR__ . '/vendor/autoload.php'; $client = new Slack\Client('your_team', 'your_token'); $slack = new Slack\Notifier($client); $message = new Slack\Message\Message('Hello world'); $attachment = new Slack\Message\MessageAttachment(); $attachment ->setMrkdwnIn(array('pretext', 'text', 'fields')) ->setFallback('fallback text') ->setPretext('Pretext text') ->setAuthorName('Author Name') ->setAuthorLink('Author Link') ->setAuthorIcon('Author Icon') ->setTitle('Title') ->setTitleLink('http://github.com') ->setImageUrl('http://github.com/image.jpg'); $field = new Slack\Message\MessageField(); $field ->setTitle('foo') ->setValue('bar'); $attachment->addField($field); $message->addAttachment($attachment); $message->setChannel('#test') ->setIconEmoji(':ghost:') ->setUsername('slack-php'); $slack->notify($message);
Message
If your message contain @username and you want him to be notified, add $message->enableLinkNames(true)