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.