1

I am trying to figure out how to update the same block in slack when a user interacts with a button. Currently I am able to create a new block message in Slack after user interacts with the button, but I want to update the original message.

This is my function to send the initial block:

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);
  
} 

This is my response to user interaction, continuing from the above code:

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); 
    
  }
  
}

Basically I am trying to use "replace_original" as instructed by slack to update the whole block, but it looks like I am not doing it right. Any help would be appreciated.

Thank you very much.

CTR Tracker
  • 37
  • 1
  • 6
  • 1
    I was able to get this working using attachments and text like this: var payload = { "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": [... but I can't get the same result using blocks, if anyone knows how to do it, would be great since I used blocks in the projects so far. – CTR Tracker Oct 23 '20 at 13:56

0 Answers0