我正在构建并发送邮件附件:
var zz = { "text": "Would you like to play a game??","attachments": [ { "text": "Choose a game to play","fallback": "You are unable to choose a game","callback_id": "wopr_game","color": "#3AA3E3","attachment_type": "default","actions": [ { "name": "chess","text": "Chess","type": "button","value": "chess" } ] } ] } web.chat.postMessage(message.source.channel,'',zz);
带有按钮的消息在Slack上显示正常,但是当我点击一个按钮时,从Slack到我当地的ngrok或快速路线没有POST响应:
app.post(‘/ slackaction’,function(req,res)
虽然其他消息可以正常发布到此路线.
点击按钮后,我看到来自Slack的这个错误:
"Oh no,something went wrong. Please try that again"
Slack Interactive Messages request_url设置为:
https://xxx.ngrok.io/slackaction
解决方法
感谢Taylor Singletary的评论,指出我正确的方向.
自定义集成的测试令牌或机器人令牌可以发布交互式消息,但您需要一个应用程序来处理它们.
要解决此问题,您需要在此处为您的应用添加机器人:https://api.slack.com/apps
然后获取该bot的访问令牌.
您可以在此处使用Slack按钮生成器:https://api.slack.com/docs/slack-button#获取OAuth URL并将其粘贴到浏览器上.
然后,从您的应用处理OAuth流,存储访问令牌并将其与chat.postMessage一起使用.
然后,您应该在单击消息按钮时收到POST请求.