Ejemplo n.º 1
0
 /**
  * @param SlackMessage $slackMessage
  * @return string
  * @throws \InvalidArgumentException
  */
 private function buildPostBody(SlackMessage $slackMessage) : string
 {
     if (!$slackMessage->getText()) {
         throw new \InvalidArgumentException('Message can\'t be empty');
     }
     if (!$slackMessage->getIcon()) {
         $return['icon_url'] = $this->config['default_icon'];
     } else {
         $return['icon_url'] = $slackMessage->getIcon();
     }
     if (!$slackMessage->getRecipient()) {
         $return['channel'] = $this->config['default_channel'];
     } else {
         $return['channel'] = $slackMessage->getRecipient();
     }
     if (!$slackMessage->getSender()) {
         $return['username'] = '******';
     } else {
         $return['username'] = $slackMessage->getSender();
     }
     $return['text'] = $slackMessage->getText();
     $return['mrkdwn'] = true;
     if ($slackMessage->isShowQuote()) {
         $return['attachments'] = ['fallback' => $slackMessage->getText(), 'pretext' => $slackMessage->getText(), 'fields' => ['title' => !$slackMessage->getQuoteTitle() ? '' : $slackMessage->getQuoteTitle(), 'title_link' => !$slackMessage->getQuoteTitleLink() ? '' : $slackMessage->getQuoteTitleLink(), 'text' => !$slackMessage->getQuoteText() ? '' : $slackMessage->getQuoteText(), 'color' => $this->quoteTypeColor($slackMessage->getQuoteType()), 'mrkdwn_in' => ['text', 'pretext']]];
     }
     return json_encode($return, JSON_UNESCAPED_UNICODE);
 }
 /**
  * @param SlackBot $slackBot
  * @return bool
  */
 private function sendTestMessage(SlackBot $slackBot)
 {
     $slackMessage = new SlackMessage();
     $quoteText = ['This is ' . $this->formatBold('test') . ' message sent by SlackBot', $this->formatCode(['<?php', '$someString = \'Hello world!\';', 'echo $someString;'])];
     $slackMessage->setIcon('http://cdn.wow-apps.pro/slackbot/slack-bot-icon-48.png')->setText('If you read this - SlackBot is working!')->setRecipient('general')->setSender('WoW-Apps')->setShowQuote(true)->setQuoteType(SlackBot::QUOTE_SUCCESS)->setQuoteText($this->inlineMultilines($quoteText))->setQuoteTitle('SlackBot for Symfony 3')->setQuoteTitleLink('https://github.com/wow-apps/symfony-slack-bot');
     return $slackBot->sendMessage($slackMessage);
 }