我正在尝试通过 GAS 的按钮单击打开一个松弛模式。目前我正在发送具有此功能的交互式按钮:
function Send(){
var url = "my slack url here"
var payload =
{
"text": "Here's your interactive buttons message.",
"blocks": [
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me",
"emoji": true
},
"value": "id_btn",
"action_id": "id_btn"
}
]
}
]
}
var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
UrlFetchApp.fetch(url,options);
}
但是,当我与按钮交互时,什么都没有发生。我目前的 Get/Post 方法如下:
function doGet(e){
return ContentService.createTextOutput("");
}
function doPost(e) {
if (typeof e !== 'undefined') {
// Extract the relevant data
var parameter = e.parameter;
var date = new Date();
var payload = JSON.parse(parameter.payload)
var trigger_id = payload.trigger_id;
var slackUrl = "https://slack.com/api/views.open";
var myToken = "Token I got after installing app to slack"
var payload_upd ={
"trigger_id": trigger_id,
"type": "modal",
"view":{
"title": {
"type": "plain_text",
"text": "Gratitude Box",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"blocks": [
{
"type": "input",
"block_id": "my_block",
"element": {
"type": "plain_text_input",
"action_id": "my_action"
},
"label": {
"type": "plain_text",
"text": "Say something nice!",
"emoji": true
}
}
]
}
}
// Send options
var options_upd = {
"headers": {"Authorization": myToken},
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload_upd),
};
UrlFetchApp.fetch(slackUrl, options_upd);
}
}
我尝试了各种方法,可以在我的有效负载和选项中组合 trigger_id 和令牌,但我找不到可行的方法。任何帮助将不胜感激,谢谢。