mati-core / slack-messenger
Slack messenger for nette framework
v1.0.0
2021-04-27 12:05 UTC
Requires
- php: ^8.0
- baraja-core/package-manager: ~2.0
- guzzlehttp/guzzle: ^7.3
- nette/application: ^3.0
- nette/bootstrap: ^3.0
- nette/di: ^3.0
- nette/neon: ^3.0
- nette/security: ^3.0
- nette/utils: ^3.0
Requires (Dev)
- nette/tester: ~2.0
- phpstan/phpstan: ^0.12
- phpstan/phpstan-nette: ^0.12.6
- tracy/tracy: ^2.3
This package is auto-updated.
Last update: 2024-11-27 19:59:08 UTC
README
Install
Comoposer command:
composer require mati-core/slack-messenger
Configuration
Slack webhook documentations: https://api.slack.com/messaging/webhooks
- Create your own Slack APP
https://api.slack.com/apps?new_app=1
- Create webhook
On Slack APP dashboard find "Incoming Webhooks" in left menu and create webhook.
- Copy webhook url in to your project common.neon
parameters: slack: hook: YOUR_WEB_HOOK_HERE
Web hook link example:
https://hooks.slack.com/services/abcd1235456/abcd1235456/abcd1235456abcd1235456
Sending messages
Include SlackMessenger service into your presenter
use \MatiCore\SlackMessenger\SlackMessengerTrait final class *Presenter extends BasePresenter { use SlackMessengerTrait; }
All object are from namespace
\MatiCore\SlackMessenger
Simple formated message example
try{ //Main message object with simple text (primary show on notification banner) $message = new Message('Hello World!'); //You can set message title $message->setTitle(':star: Hello World!'); // Add markdown section with formated text $message->addSection(new MarkdownSection( 'This is my *FIRST* message from website!' )); // Add divider $message->addSection(new Divider()); // Add link $message->addSection(new MarkdownSection('Odesláno z kontaktního formuláře na app-universe.cz | '. date('d.m.Y H:i:s'))); // send message $this->slackMessenger->sendMessage($message); }catch (\MatiCore\SlackMessenger\SlackMessengerException $e){ // Send message error }
Section list
You can add custom section just implement MessageSection interface.
Slack message builder: