Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Latest commit

 

History

History
94 lines (77 loc) · 2.79 KB

README.md

File metadata and controls

94 lines (77 loc) · 2.79 KB

DEMO!

Demo

Hangouts Chat card bot

This code sample creates a simple Hangouts Chat bot that responds to events and messages from a room synchronously. The bot formats the response using cards, inserting widgets based upon the user's original input

The sample is built using Python on Google App Engine, Standard Environment.

Run the sample in Hangouts Chat

  1. Create a new project in the Google Cloud Console
  2. Create a service account for the bot, as documented here. Replace the contents of the service-acct.json file with the service account secrets that you download.
  3. Download the Google App Engine Python SDK.
  4. Start a virtual environment
    virtualenv env
    source env/bin/activate
    
  5. Install any extra libraries using pip.
    pip2 install -t lib -r requirements.txt
    pip2 install --upgrade -t lib oauth2client
    pip2 install --upgrade -t lib google-api-python-client
    pip2 install --upgrade -t lib httplib2
    
  6. Create an App Engine instance for the bot.
    gcloud app create --region <REGION>
    
  7. Deploy the sample to Google App Engine.
    gcloud app deploy
    
  8. To configure the bot to respond to @ mentions in Hangouts Chat, follow the steps to enable the API in Publishing bots.
  9. When configuring the bot on the Configuration tab on the Hangouts Chat API page, enter the URL for the deployed version of the bot into the Bot URL text box.
  10. Add the bot to a room or direct message.
  11. Send the message to the bot with an @-message or directly in a DM.

In the message to the bot, send a list of the widgets for the bot to send back. For example, if you want the bot to send a header and a text paragraph widget, type 'header textparagraph'.

The bot responds to the following user input:

  • header
  • textparagraph
  • image
  • textbutton
  • imagebutton
  • keyvalue
  • interactivetextbutton
  • interactiveimagebutton

Note: When running this sample, you may receive an error about SpooledTemporaryFile class missing from the werkzeug package. 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

Shut down the local environment

virtualenv deactivate

Format of secret file:

{ "ElasticsearchIP": "", "user": "", "secret": "" }