我已經設法使用Google Apps腳本(GAS)創建簡單的交互式按鈕Slack應用程序。如何僅替換按鈕(附件)w/Slack交互式按鈕響應
我知道如何更換原來的消息瓦特/響應,但我想只更換按鈕,這表現(但沒有明確解釋的)多個地方的時差交互式按鈕文檔中:
https://api.slack.com/docs/message-buttons#crafting_your_message
我想要做什麼這裏展示'S: 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中顯示的複選框和確認信息來代替按鈕。
謝謝!
這應該是鬆懈的功能,用一些有意義的東西代替按鈕 – deepdive