Download the PHP package masterro/laravel-slack without Composer
On this page you can find all versions of the php package masterro/laravel-slack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-slack
Send slack messages and handle interactions with it
Description
This package is used for sending Slack messages and handling interactions with slack messages: clicking on messages buttons and interacting with users through dialogs.
Installition
Install the package via composer:
Install service provider:
Publish config and database migration file:
Run migrations:
This is the contents of the published laravel-slack-plugin.php
config file:
Usage
Sending messages
Plugin supports this methods from slack api:
You can inject service Pdffiller\LaravelSlack\Services\LaravelSlackPlugin
into your method.
Service has 2 methods:
buildMessage((AbstractMethodInfo $method), [Model $model], [string $options])
sendMessage([$message])
Instances of these classes can be used as a $method
parameter:
Pdffiller\LaravelSlack\AvailableMethods\ChatPostMessage
Pdffiller\LaravelSlack\AvailableMethods\ChatUpdate
Pdffiller\LaravelSlack\AvailableMethods\DialogOpen
Pdffiller\LaravelSlack\AvailableMethods\FilesUpload
Eloquent models can be used as a not obligatory $body
parameter.
All sent slack messages via chat.postMessage
method are saved in the database in the laravel_slack_message
table.
Slack message ts
and channel
are saved for every message.
If eloquent model is sent as the $body
parameter to the buildMessage
method, model's primary key and model's path are also saved.
If json options are sent as a $options parameter to the buildMessage
method, it will be also saved in the db.
You can then use ts
and channel
parameters in chat.update
method in order to update existing slack message.
Sending plain text message
Update slack message
Building messages with attachments
For building messages with attachments plugin has this classes:
Pdffiller\LaravelSlack\RequestBody\Json\Attachment
Pdffiller\LaravelSlack\RequestBody\Json\AttachmentField
Pdffiller\LaravelSlack\RequestBody\Json\AttachmentAction
Sending message with text attachment
Sending message with attachment including fields
Sending message with attachment including actions
Sending message with file
Open dialogs after messages interaction
Dialog can be opened after interaction with message, for example clicking on a button. After interaction with message, trigger_id
is sent in the request payload. This parameter is used in the dialog.open
method.
For building dialog plugin has this classes:
Pdffiller\LaravelSlack\RequestBody\Json\Dialog
Pdffiller\LaravelSlack\RequestBody\Json\DialogElement
Handling Interactive Components
Plugin supports handling interacrtions with buttons and dialogs. All requests from slack are sent to the plugin's endpoint. It's url can be changed in the generated laravel-slack-plugin.php
config in the endpoint-url
section. This URL should be added to the Interactive Components
section in your Slack app. OAuth Access Token and Verification token from Slack App should be added to your config file.
Plugin has convenient system of handlers for processing all interactions.
Both Attachment and Dialog have callback_id
parameter. After every interaction with button or dialog slack sends request to the /slack/handle
endpoint. callback_id
parameter is included in the request payload, so all requests can be distinguished by this parameter.
So, one handler should be implemented for the requests of one callback_id
type.
Plugin has Pdffiller\LaravelSlack\Handlers\BaseHandler
class which has this methods:
shouldBeHandled()
handle()
In your project you should implement your own handlers on top of plugin's BaseHandler
class.
Handler example
Handler should be added to the handlers
section in the generated laravel-slack-plugin.php
config file in your project.
All versions of laravel-slack with dependencies
guzzlehttp/guzzle Version >=6.3
illuminate/contracts Version ^5.7|^6.0|^7.0|^8.0
illuminate/support Version ^5.7|^6.0|^7.0|^8.0