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.