Skip to main content

Helper Python classes for handling and responding to Hangouts Chat events

Project description

Hangouts Chat Helper

PyPI version Build status Coverage Python versions Github license


Helper Python classes for handling and responding to Hangouts Chat events.


Install with pip:

pip install hangouts-helper

Message Components

This library contains several component classes to assist with constructing a Hangouts Chat message.

  • Message
  • Section
  • Card
  • CardAction
  • CardHeader
  • TextParagraph
  • KeyValue
  • Image
  • ButtonList
  • ImageButton
  • TextButton


Using the Pizza Bot example from the official Hangouts Chat API documentation, this is how you'd construct the same message using the components above.

from hangouts_helper.message import (Message, Card, CardHeader, Section,
    Image, KeyValue, ButtonList, TextButton)

message = Message()
            title='Pizza Bot Customer Support',
        KeyValue(top_label='Order No.', content='12345'),
        KeyValue(top_label='Status', content='In Delivery')),
            TextButton(text='OPEN ORDER').add_link(url='')))))

The raw message output is available from message.output(). After converting to JSON, the message looks like this:

    "cards": [
            "header": {
                "imageUrl": "",
                "subtitle": "",
                "title": "Pizza Bot Customer Support"
            "sections": [
                    "widgets": [
                            "keyValue": {
                                "content": "12345",
                                "topLabel": "Order No."
                            "keyValue": {
                                "content": "In Delivery",
                                "topLabel": "Status"
                    "header": "Location",
                    "widgets": [
                            "image": {
                                "imageUrl": ""
                    "widgets": [
                            "buttons": [
                                    "textButton": {
                                        "onClick": {
                                            "openLink": {
                                                "url": ""
                                        "text": "OPEN ORDER"

Chat Handler

The library also includes a class to help with handling incoming chat events. The methods contained in HangoutsChatHandler correspond to the different event types you can expect to receive. Each method should return a message response.


from enum import Enum

from hangouts_helper.handler import HangoutsChatHandler, SpaceType
from hangouts_helper.message import Message

class ActionMethod(Enum):

class MyHangoutsChatHandler(HangoutsChatHandler):
    ActionMethod = ActionMethod

    def handle_added_to_space(self, space_type, event):
        if space_type == SpaceType.DM:
            return Message(text="Thanks DM'ing me!")
        elif space_type == SpaceType.ROOM:
            return Message(text="Thanks adding me to your room!")

    def handle_message(self, message, event):
        return Message(text="Thanks for your message!")

    def handle_card_clicked(self, action_method, action_parameters, event):
        if action_method == ActionMethod.BUTTON_CLICKED:
            return Message(text="I've processed your button click!")

    def handle_removed_from_space(self, event):

A Flask app that repsonds to Hangouts Chat events might look like:

from flask import Flask, jsonify
app = Flask(__name__)

def hello_world():
    event = request.json
    handler = MyHangoutsChatHandler()
    response_message = handler.handle_event(event)
    return jsonify(response_message.output())


  • Add examples for each component type in README
  • Document and add examples for adding OnClick events to widgets
  • Document Enums (SpaceType, EventType, ActionMethod, Icon, ImageStyle, ResponseType)
  • Document usage scenarios for HangoutsChatHandler
  • Add methods for interacting with Hangouts Chat API to HangoutsChatHandler

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for hangouts-helper, version 18.8.3
Filename, size File type Python version Upload date Hashes
Filename, size hangouts_helper-18.8.3-py2.py3-none-any.whl (6.8 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size hangouts-helper-18.8.3.tar.gz (10.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page