'Send a Google Chat message in Python

I'm trying to send a Google Chat message from Python in much the same way you can send a Gmail message:

https://developers.google.com/gmail/api/quickstart/python

I see documentation on how to create a Chat Bot (https://developers.google.com/chat/how-tos/bots-develop), but these typically require that you create your own https server that google can access.

I've tried using the scope 'https://www.googleapis.com/auth/chat', and it successfully goes through the authorization flow, and in particular the 'chat' scope claims to grant permissions to send messages, etc:

(see https://vizycam.com/wp-content/uploads/2022/01/Image-634-1.jpg)

I can build a request using build() and the granted credentials:

from googleapiclient.discovery import build
...
service = build('chat', 'v1', credentials=gcloud.creds())

and I can see that it has methods dms(), rooms(), spaces(), etc. that I could use to create a message, but I'm unable to get any requests to work.

Is it possible to send a chat message from a user account programmatically, in much the same way the Gmail example above does?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source