我已经设法使用Google Apps脚本(GAS)创建了一个简单的交互式按钮Slack应用程序.
我知道如何用响应来替换原始消息,但我想只更换按钮,如Slack Interactive Button文档中所示(但没有清楚解释)多个位置:https:
//api.slack.com/文档/消息按钮#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);
}
Run Code Online (Sandbox Code Playgroud)
我现在的操作网址代码如下所示:
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);
}
Run Code Online (Sandbox Code Playgroud)
我不想替换整个原始消息,而是仅使用复选框和确认消息替换按钮,如上面的gif所示.
谢谢!
您只能替换完整的消息,而不仅仅是替换部分.
有两个选项可以更新原始邮件:
用响应Slack请求 {"replace_original": true}
使用 chat.update
如果您的原始消息不是类型,ephemeral
您将从original_message
属性中的Slack获取原始消息的副本作为有效负载的一部分,这有助于更新交换原始消息.
请参阅Slack文档中的此页面作为参考.