This code sample creates a simple Google Chat app that responds to events and messages from a room. The sample is built using Python 3 on Google App Engine, Standard Environment.
-
Follow the steps in Setting Up Your Development Environment to install Python and the Google Cloud SDK
-
Follow the steps in Setting Up Your GCP Resources to create a project and enable App Engine.
-
Run the following command to deploy the app:
gcloud app deploy
- To configure the app to respond to @mentions in Google Chat, follow the steps to enable the API in Publishing apps.
- When configuring the app on the Configuration tab on the Google Chat API page, enter the URL for the deployed version of the app into the App URL text box.
Either add and @mention the app in a room or in a direct mention to engage with the app.
When added to a room or messaged, the app will respond with a simple reply.
- Start a virtual environment
virtualenv env
source env/bin/activate
- Install libraries using
pip
.pip install -r requirements.txt
- Run the sample.
python main.py
To verify that the sample is running and responds with the correct data to incoming requests, run the following command from the terminal:
curl -X POST -H 'Content-Type: application/json' 'http://localhost:8080' -d '{ "type": "MESSAGE", "message": { "text": "Hello!", "sender": { "displayName": "me"}}, "space": { "displayName": "some room"}}'
Run the following command from the tests/
directory:
python -m unittest tests/*
virtualenv deactivate
Note: When running this sample, you may receive an error about SpooledTemporaryFile class missing from the werkzeug module. To fix this, after you've downloaded all of the support libraries to lib/ open up lib/werkzeug/formparser.py and change the following line
from tempfile import SpooledTemporaryFile
to
from tempfile import TemporaryFile