What you can do and what I want to do

If i send/hogehoge to Slack,

A message is sent like that
Press Edit

Will be displayed.
If i enter a character string here and submit it, you will be returned to the first screen.
You can also get the input string.

That's fine, but I want to rewrite the input string to "Enter".

What you do n’t know

I tried to execute it with the code below.
I don't see any errors, but
It was not possible to rewrite.

When I looked at the payload when it was executed, the timestamp was not included.
Perhaps when the dialog is executed and the result is returned to doPost, the returned ts is action_ts, so
I wonder if I try to get the ts required for chat.update asvar message_ts = json ['message_ts'];.

Or, since sending to Slack uses webhooks, isn't it necessary to use chat.update only for rewriting?
Slack officially wrote that either chat.update or response_url can be used, but response_url seems to be limited so I don't want to use it for this program.

function doPost (e) {
    var parameter = e.parameter;
    var data = parameter.payload;
    var json = JSON.parse (decodeURIComponent (data));
    var trigger_id = parameter.trigger_id;
    var trigger_id = json.trigger_id;
    var callback_id = parameter.callback_id;
    var callback_id = json.callback_id;
    var token = parameter.token;
    var token = json.token;
    var submission = parameter.submission;
    var submission = json.submission;
    var message_ts = parameter.message_ts;
    var message_ts = json.message_ts;
    // button
    if (callback_id == 'button') {
      var respond_dialog = Slack_Dialog (trigger_id, callback_id, message_ts);
    // dialog
    else if (callback_id == 'dialog') {
      var subject = submission.dialg_subject;
      var description = submission.dialg_description;
      var words = submission.dialg_words;
      // var response_url = "https://hooks.slack.com/xxxxxxx-xxx";var url = 'https: //hoge/slack.com/api/chat.update';
      // get object elements
      var user = json ['user']. name;
      var message_ts = json ['message_ts'];// Is this not the time stamp when the button was pressed?
      var channel_id = json ['channel']. id;
      var payload = {
        "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxb",
        'channel': channel_id,
        'ts': message_ts,
        'text': subject + "\ n" + description + "\ n" + words, // text after rewriting
      var options = {'method': 'post', 'payload': payload};
      var result = UrlFetchApp.fetch (url, options);
// Omitted

The contents and surroundings of the payload of chat.update.
Branches by callback_id when button is pressed.

if (callback_id == 'hogehogehoge') {
      var response_url = 'https://slack.com/api/chat.update';
      var user = json ['user']. name;
      var message_ts = json ['message_ts'];
      var channel_id = json ['channel']. id;
      var payload = {
        'token': 'xoxp-xxxxxxx-xxxxx ... xxxc',
        'channel': channel_id,
        'ts': message_ts,
        'text': 'Please enter \ n' + subject + '\ n' + description + '\ n' + words,
      var options = {'method': 'post', 'payload': payload};
      var result = UrlFetchApp.fetch (response_url, options);
      return ContentService.createTextOutput ();
Appendix 2
// result result
{"ok": false, "error": "message_not_found"}
// payload contents
{"type": "dialog_submission", "token": "LXXXXXXXXXXXXX", "action_ts": "1535445637.513198",
"team": {"id": "XXXXX", "domain": "hogehoge"}, "user": {"id": "XXXXXXX", "name": "XXXX"},
"channel": {"id": "XXXXXX", "name": "XXXXXX"}, "submission": {"dialg_subject": "Get what you entered"},
"callback_id": "dialog", "response_url": "https: //hooks.slack.com/app/.....", "state": ""}
  • Answer # 1

    I decided to passmessage_tsto thestateparameter of Dialog.
    It is unclear whether the main unit is used properly, but the state is not used in the response after Dialog execution (see appendix 2).

    var dialog = {
        "token": "xxxxxx-xxxxxxxxxx", // OAuth token
        "trigger_id": trigger_id,
        "dialog": JSON.stringify ({
          "callback_id": "dialog",
          "state": message_ts, // This is important
          "title": "Enter",
          "submit_label": "Submit",
          "elements": [
              "type": "text",
              "label": "Please enter",
              "name": "subject"
    // abbreviated

    Available at:

    var message_ts = json ['state'];

    This completes rewriting the message by entering it in Dialog.

  • Answer # 2

    var result = UrlFetchApp.fetch (url, options);

    Results in

        "ok": false,
        "error": "message_not_found"

    Have you returned in this way?

    tsis the time stamp when the message to be edited is posted, soaction_tsmay not work.
    You have to think about how to get the time stamp of your post.