Skip to content

A simple Python package to send messages to Google Chat via their Incoming Webhooks API

License

Notifications You must be signed in to change notification settings

Lars147/pygochook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License


PyGoChook

A simple Python wrapper to send message to Google Chats.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

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.

Getting Started

Requirements

  • aiohttp
  • Python 3.7 (only tested version)

Installation

Install the package via pip

pip install pygochook

Usage

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.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Project Link: https://github.com/Lars147/pygochook Documentation Link: https://pygochook.readthedocs.io/en/latest/

Acknowledgements

About

A simple Python package to send messages to Google Chat via their Incoming Webhooks API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages