PHP code example of arouze / slack-message-builder
1. Go to this page and download the library: Download arouze/slack-message-builder 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/ */
arouze / slack-message-builder example snippets
// Here an example with the first template of Slack Documentation
// @see: https://api.slack.com/tools/block-kit-builder?template=1
// Will return an array of Slack blocks
// You can post them on the Slack webhook using json_encode
$blocks = (new SlackMessageBuilder())
->addBlock(
(new SectionBlock())
->setTextObject(
(new TextObject())
->setType(TextObject::TEXT_OBJECT_TYPE_MARKDOWN)
->setText("You have a new request:\n*<fakeLink.toEmployeeProfile.com|Fred Enriquez - New device request>*")
)
)
->addBlock(
(new SectionBlock())
->addFields(
(new TextObject())
->setType(TextObject::TEXT_OBJECT_TYPE_MARKDOWN)
->setText("Type:*\nComputer (laptop)")
)
->addFields(
(new TextObject())
->setType(TextObject::TEXT_OBJECT_TYPE_MARKDOWN)
->setText("*When:*\nSubmitted Aut 10")
)
->addFields(
(new TextObject())
->setType(TextObject::TEXT_OBJECT_TYPE_MARKDOWN)
->setText("*Last Update:*\nMar 10, 2015 (3 years, 5 months)")
)
->addFields(
(new TextObject())
->setType(TextObject::TEXT_OBJECT_TYPE_MARKDOWN)
->setText("*Reason:*\nAll vowel keys aren't working.")
)
->addFields(
(new TextObject())
->setType(TextObject::TEXT_OBJECT_TYPE_MARKDOWN)
->setText("*Specs:*\n\"Cheetah Pro 15\" - Fast, really fast\"")
)
)
->addBlock(
(new ActionBlock())
->addElement(
(new ButtonElement())
->setText(
(new TextObject())
->escapeEmoji()
->setText('Approve')
)
->setStyle(ButtonElement::BUTTON_STYLE_PRIMARY)
->setValue('click_me_123')
)
->addElement(
(new ButtonElement())
->setText(
(new TextObject())
->escapeEmoji()
->setText('Deny')
)
->setStyle(ButtonElement::BUTTON_STYLE_DANGER)
->setValue('click_me_123')
)
)
->render();
// Or you can use the Sender to easily send message in your Slack channels.
// @see https://api.slack.com/messaging/webhooks to configure a webhook on your Slack instance.
(new Sender())->sendToChannel(
'channel-name',
'SERVICE_ID',
'CHANNEL_ID',
'CHANNEL_TOKEN',
$blocks
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.