Example #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);
 }