Navigation

Send chats to the same thread in a Google chat room using cURL

Chats might be flooded in a chat room if they are not properly organized. Specially, when it comes to automated chat notifications, we can consider having a common thread for each related notifications when possible. Check how we can send chats to the same thread in a Google chat room using 'curl'.

Prerequisites

  • Webhook URL for a Google chat room.
  • Terminal with 'curl' installed.
NOTE: You can refer this to learn how to create Google chat room webhook URL if you do not know.

Google API supports a query parameter named threadKey which we can use to send chats to the same thread where necessary.

Let's assume that https://chat.googleapis.com/v1/spaces/myspace/messages?key=mykey&token=mytoken would be the webhook URL.

Then we can define the threadKey query param to this URL as follows since we are using this to invoke the Google chat API.
https://chat.googleapis.com/v1/spaces/myspace/messages?key=mykey&token=mytoken&threadKey=1

The value for the threadKey should be any distinct value. You just need to use the same value each time when you need to send the chat to the same thread. 

Following is the sample 'curl' command.

curl \
-X POST \
-H 'Content-Type: application/json' \
"https://chat.googleapis.com/v1/spaces/myspace/messages?key=mykey&token=mytoken&threadKey=1" \
-d '{"text": "Hello from Witcentre!"}'

We will get an chat to a new thread when we execute this as follows.

When we re-run the same command, the same chat will come to the same thread again. See the following diagram.


Share

WitCentre

Post A Comment:

0 comments: