A simple Python wrapper to send message to Google Chats.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Python Google Chat Webhook is a simple Python wrapper to send messages to Google Chat via their Incoming Webhooks (https://developers.google.com/hangouts/chat/how-tos/webhooks). As for now Google Chat is only available for G Suite Customers.
- aiohttp
- Python 3.7 (only tested version)
Install the package via pip
pip install pygochook
Send a message to a Google Chat...
>>> import pygochook
>>> message = "This is awesome!"
>>> gchat_webhook_url = "https://chat.googleapis.com/..."
>>> gchat_msg_sender = pygochook.MsgSender(message, gchat_webhook_url)
>>> gchat_msg_sender.send()
[{...}] # response message from google chat
Or send a message to multiple Google Chats...
>>> import pygochook
>>> message = "This is awesome! I can send even to multiple chats!"
>>> gchat_webhook_urls = ["https://chat.googleapis.com/...", "https://chat.googleapis.com/..."]
>>> gchat_msg_sender = pygochook.MsgSender(message, gchat_webhook_urls)
>>> gchat_msg_sender.send()
[{...}, {...}] # response message from google chat
With the use of aiohttp
the requests will be performed asynchronously. Hence, it does not matter if you send the message to one or multiple Google Chats with respect to response time. An example:
>>> import pygochook
>>> @timer
... def to_one_chat(msg, url):
... gchat_sender = pygochook.MsgSender(msg, url)
... return gchat_sender.send()
...
>>> @timer
... def to_multi_chats(msg, urls):
... gchat_sender = pygochook.MsgSender(msg, urls)
... return gchat_sender.send()
...
>>> message = "Time does not even matter!"
>>> url = "https://chat.googleapis.com/..."
>>> multiple_urls = ["https://chat.googleapis.com/...", ..., "https://chat.googleapis.com/..."] # 10 Chat API-URLs
>>>
>>> to_one_chat(message, url) # send to one chat
Total execution time: 454 ms
>>>
>>> to_multi_chat(message, multiple_urls) # send to 10 chats
Total execution time: 2007 ms
Because of the asynchronous structure, the total function execution time is as long as the longest response time.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Project Link: https://github.com/Lars147/pygochook Documentation Link: https://pygochook.readthedocs.io/en/latest/