-1

I am trying to update the existing message in Google Spaces, but it seems my webhook creates a new message every time. Any guidance will be appreciated.

if you look at the webhook i shared it contains a thredkey, i successfully created a message but unable to post Thread message even though using exactly as described by Google but for some reason my Thread webhook is posting a new message and not inside the Thread.

https://chat.googleapis.com/v1/spaces/AAAAxsij123/messages?&threadKey=g3kjfKDp123&key=AIzaSyDdI0hCZtE6vy123-WEfRq3CPzqKqgtHY&token=SE2dKe34qeSC6pvIc8NNCALCiUtdfo3FF5T_fWcFGT8%3D

sub0
  • 23
  • 5

1 Answers1

0

It seems that you can only use a threadKey that you created with the same webhook, you cannot just grab the key from an existing thread to post in it. This is explained in the documentation here:

Each threadKey is unique to the app that sets it. If two different Chat apps or webhooks set the same threadKey, the messages do not thread. It is not possible to retrieve a threadKey from Chat API. The spaces.messages.thread.name field is the resource name of a thread in Chat API, not the threadKey.

This means that each webhook or Chat app has its own unique way to hash the string you used as threadKey and turn it into a "thread name", but as a result there's no (publicly available) way to do this process in reverse to get the threadKey from the "thread name". If you try to grab the name from an existing thread and add it as a key then it will just hash it again and turn it into a different one.

Essentially this means that, as the documentation explains, you have to create your own thread with an arbitrary string, then save that string to use it in the future. The arbitrary string can be anything so you can use something easy to remember. As shown in the docs:

  https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?threadKey=MY_KEY

Then just keep using MY_KEY in future messages and the webhook will post to the same thread. What you cannot do is to grab an existing thread, look for its ID and then try to post to it. The thread has to have been created by the same webhook.

Daniel
  • 3,157
  • 2
  • 7
  • 15
  • Thanks for the reply , if you look at the webhook i shared it contains a thredkey, i successfully created a message but unable to post Thread message even though using exactly as described by Google but for some reason my Thread webhook is posting a new message and not inside the Thread. – sub0 Sep 13 '22 at 23:26
  • My bad, I understood "update" in a different way. It seems that in your example you tried to use an existing thread ID, if I'm not mistaken. I updated my answer with an explanation on how it works and that you have to create your own thread first. I tested it that way and it did work for me. If you are doing the same and it still doesn't work please add your code or more details on the response/result to your question. – Daniel Sep 14 '22 at 23:14