1. Go to this page and download the library: Download montopolis/montopolis-slack library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
montopolis / montopolis-slack example snippets
// For convenience, it's recommended that you wrap the `Fluent` helper in a global function:
function slack(): \Montopolis\Slack\Fluent
{
$config = new \Montopolis\Slack\Infrastructure\ArraySlackConfigurationRepository([
'slack' => [
'token' => '___oauth-token-from-above___',
'default_channel' => 'general',
'fallback_to_default' => true
],
]);
$transformer = new \Montopolis\Slack\Application\MessageTransformer();
$client = new \Montopolis\Slack\Infrastructure\HttpSlackClient($config, $transformer);
return new \Montopolis\Slack\Fluent($client);
}
// It can then be used as such:
slack()
->channel('support')
->text('This is the Slack Message')
->send();
// In AppServiceProvider.php:...
public function register()
{
$this->app->bind(\Montopolis\Slack\Fluent::class, function ($app) {
// This assumes config/services.php has a `slack` key containing `token` and `default_channel`:
$config = new \Montopolis\Slack\Infrastructure\ArraySlackConfigurationRepository(config('services'));
$transformer = new \Montopolis\Slack\Application\MessageTransformer();
$client = new \Montopolis\Slack\Infrastructure\HttpSlackClient($config, $transformer);
return new \Montopolis\Slack\Fluent($client);
});
}
// etc...
// In helpers.php:...
function slack(): \Montopolis\Slack\Fluent
{
return app()->make(\Montopolis\Slack\Fluent::class);
}
// etc...
// In application:
slack()
->channel('support')
->text('This is sent from a Laravel app')
->send();
slack()
->channel('support')
->blocks([
[
"type" => "section",
"text" => [
"type" => "mrkdwn",
"text" => "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
],
],
[
"type" => "divider",
],
[
"type" => "section",
"text" => [
"type" => "mrkdwn",
"text" => "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
],
"accessory" => [
"type" => "image",
"image_url" => "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
"alt_text" => "alt text for image"
],
],
[
"type" => "actions",
"elements" => [
[
"type" => "button",
"text" => [
"type" => "plain_text",
"text" => "Farmhouse",
"emoji" => true,
],
"value" => "click_me_123",
],
]
],
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.