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 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);
 }
Example #2
0
 public function testMessageWithAttachmentsAndActions()
 {
     $now = new DateTime();
     $attachmentInput = ['fallback' => 'Some fallback text', 'text' => 'Some text to appear in the attachment', 'pretext' => null, 'color' => 'bad', 'footer' => 'Footer', 'footer_icon' => 'https://platform.slack-edge.com/img/default_application_icon.png', 'timestamp' => $now, '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' => [], 'actions' => [['name' => 'Name 1', 'text' => 'Text 1', 'style' => 'default', 'type' => 'button', 'value' => 'Value 1', 'confirm' => ['title' => 'Title 1', 'text' => 'Text 1', 'ok_text' => 'OK Text 1', 'dismiss_text' => 'Dismiss Text 1']], ['name' => 'Name 2', 'text' => 'Text 2', 'style' => 'default', 'type' => 'button', 'value' => 'Value 2', 'confirm' => ['title' => 'Title 2', 'text' => 'Text 2', 'ok_text' => 'OK Text 2', 'dismiss_text' => 'Dismiss Text 2']]]];
     $attachmentOutput = ['fallback' => 'Some fallback text', 'text' => 'Some text to appear in the attachment', 'pretext' => null, 'color' => 'bad', 'footer' => 'Footer', 'footer_icon' => 'https://platform.slack-edge.com/img/default_application_icon.png', 'ts' => $now->getTimestamp(), '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' => [], 'actions' => [['name' => 'Name 1', 'text' => 'Text 1', 'style' => 'default', 'type' => 'button', 'value' => 'Value 1', 'confirm' => ['title' => 'Title 1', 'text' => 'Text 1', 'ok_text' => 'OK Text 1', 'dismiss_text' => 'Dismiss Text 1']], ['name' => 'Name 2', 'text' => 'Text 2', 'style' => 'default', 'type' => 'button', 'value' => 'Value 2', 'confirm' => ['title' => 'Title 2', 'text' => 'Text 2', 'ok_text' => 'OK Text 2', 'dismiss_text' => 'Dismiss Text 2']]]];
     $client = new Client('http://fake.endpoint', ['username' => 'Test', 'channel' => '#general']);
     $message = $client->createMessage()->setText('Message');
     $attachment = new Attachment($attachmentInput);
     $message->attach($attachment);
     $payload = $client->preparePayload($message);
     $expectedHttpData = ['username' => 'Test', 'channel' => '#general', 'text' => 'Message', 'link_names' => 0, 'unfurl_links' => false, 'unfurl_media' => true, 'mrkdwn' => true, 'attachments' => [$attachmentOutput]];
     $this->assertEquals($expectedHttpData, $payload);
 }
 /**
  * Prepares the payload to be sent to the webhook
  *
  * @param \Maknz\Slack\Message $message The message to send
  * @return array 
  * @static 
  */
 public static function preparePayload($message)
 {
     return \Maknz\Slack\Client::preparePayload($message);
 }