bc / slack-hooker
simple slack webhook
Installs: 1 010
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
- guzzlehttp/guzzle: >=5 <7.0
- psr/http-message: ~1.0
Requires (Dev)
- codeception/codeception: ~2
- phpmd/phpmd: @stable
This package is not auto-updated.
Last update: 2025-02-01 20:47:38 UTC
README
Install
composer require bc/slack-hooker:*
Usage
require_once 'vendor/autoload.php'; //instantiate bc\Slack\SlackHooker with webhook url $hooker = new bc\Slack\SlackHooker('WEBHOOK_URL'); //build message $messageBuilder = new bc\Slack\MessageBuilder(); $messageBuilder ->setText("Simpe text") ->setUserName("Bot") ->setChannel('#random') ->setIconEmoji(':cow:'); //build attachment $attachBuilder = new bc\Slack\AttachmentBuilder(); $attachBuilder ->setFallback("fallback text") ->setText("attachment text") ->setPreText("pre text") ->setColor("#369") ->setAuthorName("Author") ->setAuthorLink("") ->setAuthorIcon("") ->setTitle("title") ->setTitleLink("") ->addField('field1', 'value') ->addField('field2', 'value') ->addField('field3', 'value', false) ->setImageUrl("") ->setThumbUrl(""); //add attachment $messageBuilder->attach($attachBuilder->build()); //build and add another attachment $attachment = (new bc\Slack\AttachmentBuilder()) ->setFallback("fallback") ->setText("second attachment") ->build(); $messageBuilder->attach($attachment); $message = $messageBuilder->build(); //send message. returns \Psr\Http\Message\ResponseInterface $response = $hooker->sendMessage($message);