Slack API:如何回复一个附件动作



我已经创建了一个与Slack集成的WebHook应用程序。代码是发送消息到Slack频道,使用聊天。postMessage方法,带有一些附件动作,然后当用户单击动作按钮时,我向他发送成功消息。我想做这样的事情:

https://api.slack.com/img/api/message_guidelines/Example_6.gif

问题是当我试图发送成功消息时。Slack只接收答案的文本部分。下面是代码:

$message = 'Pre-text message';
$attachments = array(
  array(
    "title" => 'Title message',
    "author_name" => 'My name',
"author_link" => 'https://www.facebook.com/',
"author_icon" => 'https://graph.facebook.com/v2.6/picture',
"image_url" => 'https://i.scdn.co/image',
  ),
);
$answer = array(
  'text' => $message,
  'attachments' => json_encode($attachments)
)

我如何做Slack显示与附件部分的答案,如上图所示?如果我在$answer上评论文本部分,Slack会向用户显示一个错误("哦,不,出了问题。请再试一次。非常感谢您的帮助。

我找到了解决方案。在这里发帖是为了帮助有同样问题的人。在发布消息时,应该json_encode附件部分,但在发布附件动作时回答,则没有必要。解决方案如下:

$message = 'Pre-text message';
$attachments = array(
  array(
    "title" => 'Title message',
    "author_name" => 'My name',
    "author_link" => 'https://www.facebook.com/',
    "author_icon" => 'https://graph.facebook.com/v2.6/picture',
    "image_url" => 'https://i.scdn.co/image',
  ),
);
$answer = array(
    'text' => $message,
    'attachments' => $attachments
)

最新更新