/** * {@inheritdoc} */ protected function createPayload() { $payload = new ChatPostMessagePayload(); $payload->setChannel('#acme_channel'); $payload->setUsername('acme_user'); $payload->setText('Hello World!'); $payload->setIconEmoji(':truck:'); $payload->setLinkNames(true); $payload->setParse('full'); $payload->setUnfurlLinks(true); $payload->setUnfurlMedia(false); $payload->setIconUrl('http://foo.bar/emoji-1.png'); $fakeAttachmentField = new AttachmentField(); $fakeAttachmentField->setShort(false); $fakeAttachmentField->setTitle('the title'); $fakeAttachmentField->setValue('the value'); $fakeAttachment = new Attachment(); $fakeAttachment->setTitle('the title'); $fakeAttachment->setTitleLink('http://thetitlelink.com'); $fakeAttachment->setColor('the color'); $fakeAttachment->setFallback('the fallback'); $fakeAttachment->setImageUrl('the image url'); $fakeAttachment->setPreText('this is...'); $fakeAttachment->setText('my attachment'); $fakeAttachment->setAuthorIcon(':skull:'); $fakeAttachment->setAuthorName('the author'); $fakeAttachment->setAuthorLink('http://theauthor.com'); $fakeAttachment->addField($fakeAttachmentField); $payload->addAttachment($fakeAttachment); return $payload; }
public function post() { $content = $this->readInput(); $client = new ApiClient($this->token); $payload = new ChatPostMessagePayload(); $payload->setChannel($this->options->get('channel', '#general')); $payload->setUsername($this->options->get('user', 'SlackPipe Bot')); if (!Asserts::isEmbedUrl($content) && !Asserts::isImage($content)) { $payload->setText("```" . PHP_EOL . $content . '```'); } else { $payload->setUnfurlLinks(true); $payload->setText($content); } return $this->getResponse($client->send($payload)); }
/** * @return ChatPostMessagePayload */ protected function createPayload() { $payload = new ChatPostMessagePayload(); $channel = $this->input->getArgument('channel'); // help support un-escaped channel names such as 'general' (the hash-sign requires the channel name to be quoted) // also making sure to ignore it if a channel ID was given // @todo Reconsider this approach; different channel formats could be allowed that might conflict with this if (substr($channel, 0, 1) !== '#' && !(substr($channel, 0, 1) === 'G' && is_numeric(substr($channel, 1)))) { $channel = '#' . $channel; } $payload->setChannel($channel); $payload->setText($this->input->getArgument('text')); if ($this->input->getOption('username')) { $payload->setUsername($this->input->getOption('username')); } if ($this->input->getOption('icon-url')) { $payload->setIconUrl($this->input->getOption('icon-url')); } if ($this->input->getOption('icon-emoji')) { $payload->setIconEmoji($this->input->getOption('icon-emoji')); } if ($this->input->getOption('parse')) { $payload->setParse($this->input->getOption('parse')); } if ($this->input->getOption('link-names')) { $payload->setLinkNames($this->input->getOption('link-names')); } if ($this->input->getOption('unfurl-links')) { $payload->setUnfurlLinks($this->input->getOption('unfurl-links')); } if ($this->input->getOption('unfurl-media')) { $payload->setUnfurlMedia($this->input->getOption('unfurl-media')); } return $payload; }