【发布时间】:2017-03-14 17:54:29
【问题描述】:
我已经设法使用 Google Apps 脚本 (GAS) 创建了一个简单的交互式按钮 Slack 应用程序。
我知道如何用响应替换原始消息,但我只想替换按钮,如 Slack 交互式按钮文档中的多个位置所示(但未明确解释):
https://api.slack.com/docs/message-buttons#crafting_your_message
我想做这里演示的事情: https://a.slack-edge.com/dcb1/img/api/message_guidelines/Example_6.gif
这是对原始邮件的更新,是用相同的文本但不同的附件替换原始邮件,...?
我当前的交互式按钮消息代码如下所示:
function sendMsgWithButton() {
// slack channel url (where to send the message)
var slackUrl = "https://hooks.slack.com/services/...";
// message text
var messageData = {
"text": "Here's your interactive buttons message.",
"attachments": [
{
"text": "Can you click the button?",
"fallback": "Sorry, no support for buttons.",
"callback_id": "ptNotificationButtonResponse",
"color": "#3AA3E3",
"attachment_type": "default",
"actions": [
{
"name": "userResponse",
"text": "OK",
"style": "primary",
"type": "button",
"value": "ok"
}
]
}
]
}
// format for Slack
var options = {
'method' : 'post',
'contentType': 'application/json',
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(messageData)
};
// post to Slack
UrlFetchApp.fetch(slackUrl, options);
}
我当前的操作 URL 代码现在看起来像这样:
function doPost() {
var replyMessage = {"replace_original": true,
"response_type": "in_channel",
"text": "I see you clicked the button."
};
return ContentService.createTextOutput(JSON.stringify(replyMessage)).setMimeType(ContentService.MimeType.JSON);
}
我不想替换整个原始消息,而是将按钮替换为复选框和确认消息之类的东西,如上面的 gif 所示。
谢谢!
【问题讨论】:
-
这应该是用有意义的东西替换按钮的松弛功能
标签: slack-api