This is a sample chatbot for Google Hangouts Chat written in Elixir, using the Phoenix framework. This application comes with a Dockerfile and is ready to be packaged as a container and is perfect for running in your serverless environment.
This application was written as a demo for Cloud Next '19.
The chatbot is meant to receive messages from Google Hangouts Chat.
There is a runtime dependcy on Cloud Firestore in Datastore Mode.
The chatbot also depends on a meme service, and by default uses the one hosted at https://meme-fpz6derz7a-uc.a.run.app
- Generate a new secret key base.
SECRET_KEY_BASE=$(elixir -e ":crypto.strong_rand_bytes(48) |> Base.encode64 |> IO.puts")
sed "s|SECRET+KEY+BASE|$SECRET_KEY_BASE|" config/prod.secret.exs.sample >config/prod.secret.exs
- To build with Google Cloud Build, simply issue this gcloud command.
gcloud builds submit --tag=gcr.io/<GOOGLE CLOUD PROJECT>/chatbot:v1 .
These instructions are for deploying the meme-bot to Google's Cloud Run Service.
-
Enable Google Cloud Firestore and create a database in Datastore mode (use a geography based on where you will deploy the chatbot).
-
Give your default compute service account datatore read and write permissions
-
Deploy the built image to Cloud Run
You'll need to set a couple of environment variables.
- PROJECT = Your Google Cloud Project Name. This is required to connect to datastore.
- MEME = a URL for a MEME generation service. You can use the one in the example below.
gcloud beta run deploy chatbot --image gcr.io/<GOOGLE CLOUD PROJECT>/chatbot:v1 --memory=512M --set-env-vars=PROJECT=<PROJECT NAME>,MEME=https://meme-fpz6derz7a-uc.a.run.app
- Register the chatbot with Hangouts Chat in your GSuite domain.
This is done by creating a domain scoped project. Select synchronous / HTTP for the bot configuration and set the URL to be the deployed URL of your Cloud Run service, plus the path /api/hello
https://<your service>.a.run.app/api/hello