Here's how to post a message to Google Hangouts Chat by specifying a thread.
I will omit it. (I may add it later
I will omit it. (I may add it later
Post a message using the URL of the webhook.
import requests
webhook_url = 'https://chat.googleapis.com/*******'
response = requests.post(
webhook_url,
json={"text": "Transmission test\n"}
)
The result looks like this.
If you post multiple times this way, each message will be posted in a separate thread.
Print the response when you post a message. The content of the decoded response is described in the text attribute.
print(response.text)
Copy the thread identifier described in "thread" in this.
{
"name": "spaces/***********/messages/***********************",
"sender": {
"name": "users/*********************",
"displayName": "test_webhook",
"avatarUrl": "",
"email": "",
"domainId": "",
"type": "BOT"
},
"text": "Transmission test\n",
"cards": [],
"previewText": "",
"annotations": [],
"thread": {
"name": "spaces/***********/threads/***********"← here
},
"space": {
"name": "spaces/***********",
"type": "ROOM",
"displayName": "test"
},
"fallbackText": "",
"argumentText": "Transmission test\n",
"createTime": "2020-02-18T14:33:38.083263Z"
}
Use the thread identifier obtained in step 4 to specify the thread and post the message.
import requests
webhook_url = 'https://chat.googleapis.com/*******'
thread = "spaces/***********/threads/***********"
response = requests.post(
webhook_url,
json = {
"text": "Transmission test\n",
"thread": {
"name": thread
}
}
)
Then, the message will be posted to the thread that posted the message in 3.
I was able to post a message to Google Hangouts Chat by specifying a thread.
If you like, please comment.
Recommended Posts