1

我试图弄清楚当用户与按钮交互时如何在 slack 中更新同一个块。目前,在用户与按钮交互后,我可以在 Slack 中创建新的阻止消息,但我想更新原始消息。

这是我发送初始块的函数:

function Send(){
  var url = "This is my slack url"
  var payload = 
    {
    "blocks": [
        {
            "type": "actions",
            "elements": [
                {
                    "type": "button",
                    "text": {
                        "type": "plain_text",
                        "text": "Click Me",
                        "emoji": true
                    },
                    "value": "click_me_123",
                    "action_id": "actionId-0"
                }
            ]
        }
    ]
}

var options = {
    "method": "post",
    "contentType": "application/json",
    "payload": JSON.stringify(payload)
  };

UrlFetchApp.fetch(url,options);
  
} 

这是我对用户交互的回应,从上面的代码继续:

function doGet(e){
return ContentService.createTextOutput(""); 
}

function doPost(e) {

  if (typeof e !== 'undefined') { 
    
    var url = "Same url I used on my first function"
    
  var payload = 
    {
    "blocks": [
        {
            "type": "actions",
            "elements": [
                {
                    "type": "button",
                    "text": {
                        "type": "plain_text",
                        "text": "Click Me Edited",
                        "emoji": true
                    },
                    "value": "click_me_123",
                    "action_id": "actionId-0"
                }
            ]
        }
    ]
}

var options = {
    "replace_original" : "true",
    "method": "post",
    "contentType": "application/json",
    "payload": JSON.stringify(payload)
  };

UrlFetchApp.fetch(url,options); 
    
  }
  
}

基本上我正在尝试按照 slack 的指示使用“replace_original”来更新整个块,但看起来我做得不对。任何帮助,将不胜感激。

非常感谢。

4

0 回答 0