How to make Google App Script Chat bot answer in threads?

56 Views Asked by At

I had a google chat bot that was working as the template written by google:

function onMessage(event) {
  var name = "";

  if (event.space.type == "DM") {
    name = "You";
  } else {
    name = event.user.displayName;
  }
  var message = name + " said \"" + event.message.text + "\"";

  return { "text": message };
}

Now the problem is that with the new inline thread structure, I would like my bot to answer within the thread, and not opening a new thread (new message). But I cannot find a way to do do this.

I tried a couple of experiments such as

function onMessage(event) {
  var threadId = event.message.thread.name;
  var name = "";

  if (event.space.type == "DM") {
    name = "You";
  } else {
    name = event.user.displayName;
  }
  var message = name + " said \"" + event.message.text + "\"";

  return { 
      "text": message,
      "thread": {
        "name": threadId,
        "retentionSettings": {
          "state": "PERMANENT"
        }
      }
    }
}

but nothing seems to work. How can I make Google App Script Chat bot answer in threads?

0

There are 0 best solutions below