php - Slack API - Attachments not showing -


i've created (fairly simple) implementation slack post messages in channel php. works well, except attachments. reason, show "some" of messages, not everything.

the code snippet i'm using identical 1 here

<?php /**  * slack incoming webhook - single php file  *  * @author      chris - http://codepad.co/cheers | https://github.com/webremote  * @copyright   copyright (c) 2016  * @version     0.0.28  * @build       20160204  */ // settings $token      = 'xxx-xxx-xxx-xxx-xxx'; // request token via https://api.slack.com/tokens $channel    = '#mandrill-log';  if ($_server['request_method'] == 'post') {     if (!empty($_post['mandrill_events'])) {         foreach (json_decode($_post['mandrill_events'], true) $entry) {             // default values             $attachments = [];             $type = 'unknown';             $emoji = 'question';             $text = print_r($entry, true);             switch ($entry['event']) {                 case 'send':                     $text = 'sent mail ' . $entry['msg']['email'] . ' subject "' . $entry['msg']['subject'] . '" (from: ' . $entry['msg']['sender'] . ')';                     $emoji = 'email';                     $type = 'sent';                     break;                  case 'click':                     $text = 'somebody ' . $entry['location']['country'] . ' clicked url "' . $entry['url'] . '"';                     $emoji = 'point_right';                     $type = 'click';                     $attachments = [                         'fallback'  => $text,                         'text'      => 'url clicked: ' . $entry['url'],                         'fields'    => [                             [                                 'title' => 'location',                                 'value' => $entry['location']['country'] . (!empty($entry['location']['region']) ? php_eol . $entry['location']['region'] : '') . (!empty($entry['location']['city']) ? php_eol . $entry['location']['city'] : ''),                                 'short' => true,                             ],                             [                                 'title' => 'browser',                                 'value' => $entry['user_agent_parsed']['type'],                                 'short' => true                             ],                             [                                 'title' => 'subject',                                 'value' => $entry['msg']['subject'],                                 'short' => true,                             ],                             [                                 'title' => 'sender',                                 'value' => $entry['msg']['sender'],                                 'short' => true                             ]                         ],                         'thumb_url' => $entry['user_agent_parsed']['ua_icon']                     ];                     break;                  case 'open':                     $text = 'somebody ' . $entry['location']['country'] . ' opened email "' . $entry['msg']['subject'] . '"';                     $emoji = 'open_book';                     $type = 'read';                     $attachments = [[                         'fallback'  => $text,                         'fields'    => [                             [                                 'title' => 'location',                                 'value' => $entry['location']['country'] . (!empty($entry['location']['region']) ? php_eol . $entry['location']['region'] : '') . (!empty($entry['location']['city']) ? php_eol . $entry['location']['city'] : ''),                                 'short' => true,                             ],                             [                                 'title' => 'browser',                                 'value' => $entry['user_agent_parsed']['type'] . ($entry['user_agent_parsed']['mobile'] ? ' - mobile' : ' - desktop'),                                 'short' => true                             ],                             [                                 'title' => 'subject',                                 'value' => $entry['msg']['subject'],                                 'short' => true,                             ],                             [                                 'title' => 'sender',                                 'value' => $entry['msg']['sender'],                                 'short' => true                             ]                         ],                         'thumb_url' => $entry['user_agent_parsed']['ua_icon']                     ]];                     break;                  case 'soft_bounce':                     $text = 'email ' . $entry['msg']['email'] . ' subject "' . $entry['msg']['subject'] . '" got (soft) bounced';                     $emoji = 'space_invader';                     $type = 'bounce';                     break;                  case 'hard_bounce':                     $text = 'email ' . $entry['msg']['email'] . ' subject "' . $entry['msg']['subject'] . '" got (hard) bounced (' . $entry['msg']['diag'] .')';                     $emoji = 'skull_and_crossbones';                     $type = 'bounce';                     break;             }              if ($entry['type'] == 'blacklist') {                 if ($entry['action'] == 'add') {                     $type = 'blacklist';                     $emoji = 'new_moon_with_face';                     $text = 'the e-mail ' . $entry['reject']['email'] . ' has been added blacklist (reason: ' . $entry['reject']['reason'] . ', expires @ ' . $entry['reject']['expires_at'] . ')';                 }             }              if (empty($attachments)) {                 $ch = curl_init();                 curl_setopt($ch, curlopt_useragent,         'webremote.mandrill.webhook');                 curl_setopt($ch, curlopt_post,              true);                 curl_setopt($ch, curlopt_url,               'https://slack.com/api/chat.postmessage?');                 curl_setopt($ch, curlopt_postfields, [                     'token'         => $token,                     'channel'       => $channel,                     'username'      => 'mandrill-' . $type,                     'text'          => $text,                     'icon_emoji'    => ':' . $emoji . ':'                 ]);                 curl_exec($ch);                 curl_close($ch);             }              elseif (!empty($attachments)) {                 $ch = curl_init();                 curl_setopt($ch, curlopt_useragent,         'webremote.mandrill.webhook');                 curl_setopt($ch, curlopt_post,              false);                 curl_setopt($ch, curlopt_url,               'https://slack.com/api/chat.postmessage?' . http_build_query([                     'token'         => $token,                     'channel'       => $channel,                     'username'      => 'mandrill-' . $type,                     'text'          => $text,                     'attachments'   => json_encode($attachments),                     'icon_emoji'    => ':' . $emoji . ':'                 ]));                 curl_setopt($ch, curlopt_returntransfer,    1);                 curl_setopt($ch, curlopt_httpheader,        [                     'content-length: ' . strlen($datasend)                 ]);                 $response = curl_exec($ch);                 curl_close($ch);                            }         }     } } 

for "case: send" (line 23) want display attachments, reason, doesn't work. result in slack "text"-field, whereas attachments ignored for... no reason?

i've tried searching api documentation, faq , so, no topics showed up. there specific reasons why attachment doesn't show?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -