mati-core/slack-messenger

Slack messenger for nette framework

v1.0.0 2021-04-27 12:05 UTC

This package is auto-updated.

Last update: 2024-11-27 19:59:08 UTC


README

Latest Stable Version Total Downloads Integrity check Latest Unstable Version License

Install

Comoposer command:

composer require mati-core/slack-messenger

Configuration

Slack webhook documentations: https://api.slack.com/messaging/webhooks

  1. Create your own Slack APP

https://api.slack.com/apps?new_app=1

  1. Create webhook

On Slack APP dashboard find "Incoming Webhooks" in left menu and create webhook.

  1. 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:

https://app.slack.com/block-kit-builder/