Google Chat Bot: Returning a threaded reply in onMessage() creates a new message in Space

130 Views Asked by At

We've been trying to update our ChatBots to use threaded replies, but we're running into issues, specifically when responding to a brand new message in the Space. For example, if a user says:

@TheChatBot help!

We want the bot to create a threaded reply to that message. Instead, it creates a new message at the top level of the space.

Interestingly, if we mention the bot from WITHIN a thread, it works correctly.

We tried many combinations of message.thread values (e.g. { threadKey: ...} , {name: ...}) and none of the combinations worked for the message outside of a thread.

Here's a snippet of the ChatBot gs code:

function onMessage(event) {
...
  var message = event.message;
  var threadName = message.thread ? message.thread.name : null;
...
  return {
    text: ...,
    threadReply: true,
    thread: {
      name: threadName
    }
  };
}
1

There are 1 best solutions below

0
SputnikDrunk2 On

My investigation revealed that Google Chat currently restricts response placement to the top-level space name, even though individual thread names (messages where the chatbot was mentioned) are readily available within the onMessage response (e.g.,spaces/SPACE_ID/threads/THREAD_ID).


Current Behavior

Official documentation on Processing or Responding to Interaction Events confirms that Chat bots are currently limited to "Insert content to space" (see image below) for their replies, suggesting this behavior is intentional:

enter image description here

What I Have Tried

I attempted to formulate a workaround following the guide spaces.message.create. In this process, I intended for the chatbot to create a message on the thread where it has been mentioned, with use of the thread name. However, it appears there is a limitation in the Chat API. Specifically, one of the required parameters is a top-level Space name instead of a thread name.

Last Resort

Having said that, I would recommend that you consider submitting a feature idea on Google Issue Tracker. I believe this would be an ideal request for the chatbot, given its use cases such as the primary goal mentioned in your post.