Maknz\Slack\Client::preparePayload PHP Method

preparePayload() public method

Prepares the payload to be sent to the webhook.
public preparePayload ( Message $message ) : array
$message Message The message to send
return array
    public function preparePayload(Message $message)
    {
        $payload = ['text' => $message->getText(), 'channel' => $message->getChannel(), 'username' => $message->getUsername(), 'link_names' => $this->getLinkNames() ? 1 : 0, 'unfurl_links' => $this->getUnfurlLinks(), 'unfurl_media' => $this->getUnfurlMedia(), 'mrkdwn' => $message->getAllowMarkdown()];
        if ($icon = $message->getIcon()) {
            $payload[$message->getIconType()] = $icon;
        }
        $payload['attachments'] = $this->getAttachmentsAsArrays($message);
        return $payload;
    }

Usage Example

 public function testMessageWithAttachmentsAndFields()
 {
     $attachmentArray = ['fallback' => 'Some fallback text', 'text' => 'Some text to appear in the attachment', 'pretext' => null, 'color' => 'bad', 'mrkdwn_in' => [], 'image_url' => 'http://fake.host/image.png', 'thumb_url' => 'http://fake.host/image.png', 'title' => 'A title', 'title_link' => 'http://fake.host/', 'author_name' => 'Joe Bloggs', 'author_link' => 'http://fake.host/', 'author_icon' => 'http://fake.host/image.png', 'fields' => [['title' => 'Field 1', 'value' => 'Value 1', 'short' => false], ['title' => 'Field 2', 'value' => 'Value 2', 'short' => false]]];
     $expectedHttpData = ['username' => 'Test', 'channel' => '#general', 'text' => 'Message', 'link_names' => false, 'unfurl_links' => false, 'unfurl_media' => true, 'mrkdwn' => true, 'attachments' => [$attachmentArray]];
     $client = new Client('http://fake.endpoint', ['username' => 'Test', 'channel' => '#general']);
     $message = $client->createMessage()->setText('Message');
     $attachment = new Attachment($attachmentArray);
     $message->attach($attachment);
     $payload = $client->preparePayload($message);
     $this->assertEquals($expectedHttpData, $payload);
 }
All Usage Examples Of Maknz\Slack\Client::preparePayload