1

There's a thread that my webhook has previously created that it wants to reply to. Is this possible using a webhook? It seems to be possible with a bot, see this answer:

https://stackoverflow.com/a/58657945/3832377

But I can't find any documentation on doing it from a webhook. As I've created the original message in the thread, I can guarentee a consistent threadId.

I tried to send a body that looked like:

{
  "cards": [/* a card */]
  "thread": { "name": "some_thread_name" }
}

But received a 500 error.

Alexander Craggs
  • 7,874
  • 4
  • 24
  • 46

2 Answers2

1

Documentation: https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/create

States you have to add the threadKey as a query parameter, not in the request body.

Alexander Craggs
  • 7,874
  • 4
  • 24
  • 46
0

I just spent a long time trying to figure this out, and finally found the answer.

The documentation from Google doesn't cover this question in a way that makes sense, and I just had to find it via trial and error.

To add your chat as a reply using the webhook, you copy the webhook URL, and then append this: &threadKey=TheNameOfTheThreadIllCallThisOneBob An example of what a full webhook for this might look like is this:

https://chat.googleapis.com/v1/spaces/AAAAPeRudTM/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=Qqd9NHOkp-EU3XV7ZM9TguW65Nz1p_qUwoijbWYxGS4%3D&threadKey=TheNameOfTheThreadIllCallThisOneBob

If the thread doesn't already exist, it will create a new thread, and then send chats to that thread as a reply in the future.

Josh Heaps
  • 296
  • 2
  • 13
  • I'm doing this to send a message via GoogleAppScript and it isn't working. It sends all the messages as new message. Has anything changed recently ? – Zircoz Apr 02 '23 at 16:25
  • This is still working for me. You appended the threadkey at the end of the webhook URI? – Josh Heaps Apr 03 '23 at 17:43
  • Yep, I did append it. It posted same message in but outside thread. On that note, are you doing it for a DM/group or GSpace ? – Zircoz Apr 04 '23 at 06:01
  • Dm/group I've never touched a gspace before – Josh Heaps Apr 04 '23 at 15:38