Sample chatbot to demonstrate various capabilities include:
- Receive messages from Google Chat
- Process slash commands
- Create simple and card Google Chat messages
- Connect to AWS services
These instructions are based on Google Cloud Platform, Google Apps Script, and Google Chat as of October, 2020.
The general vision of chatbots within a persistent group chat channel / room is to create a single shared command console so that everyone within the team can interact with other services to accomplish team tasks. A way of realizing this vision is to create a collection of chatbots that can perform either atomic or composite tasks. These automated tasks enable the team to handle a variety of different situations such as handling incidents that are reported by users of the digital business services / capabilities that the team supports.
By using a persistent group chat channel for human-to-human, human-to-systems, and systems-to-human communications, everyone on the team has visibility to both the current situation as well as the history of events and actions taken by other team members.
The following diagram illustrates the architecture of this sample chatbot.
- Have a valid AWS access key and secret key pair
- Have a developer user account at Google Cloud Platform (https://console.developers.google.com/)
- Navigate in a web browser to Google Apps Script - https://script.google.com/
- Select "My Projects"
- Select "New project"
- Type in the name of your project
- Copy the files in this git repo over your Google Apps Script project using the same file names
- If you want to log debug messages, set the debug variable in Code.gs to true
- Select save button
- From your Apps Script project screen, select File > "Project Properties"
- Select the "Script properties" tab
- Select "Add row"
- In the property name field, type in "aws_iam_accesskey"
- In the property value field, type in the AWS access key that you have access to
- Select "Add row"
- In the property name field, type in "aws_iam_secretkey"
- In the property value field, type in the AWS secret key that is associated with the AWS access key
- Select "Add row"
- In the property name field, type in "aws_default_region"
- In the property value field, type in the default AWS region (e.g. "us-east-2")
- Select "Save"
- From your Apps Script project screen, select View and enable "Show manifest file"
- Edit the appsscript.json file
- Add the following to JSON object:
{
....
"chat": {
"addToSpaceFallbackMessage": "Thank you for adding me!"
}
....
}
- Save the file
- From your Apps Script project screen, select Publish > "Deploy from manifest"
- Note that there is a deployment called "Latest Version (Head)"
- This will point to your latest published version.
- Use the ID of this deployment to configure your Google Hangouts Chat API.
- Get the ID for this deployment by selecting "Get ID"
- Copy the "Deployment ID" value
- Select "Close"
- Select "Create"
- Type in a name for the deployment
- Select "Save"
If you want to customize the avatar icon that Google Chat uses for your chatbot and you need a place to host the icon file, you can use GitHub Pages. If you store your git repo for this project in GitHub, this gives you the added convenience of storing the icon file with your source code. To find a free icon, simply use Google Search with the search phrase "free bot icon". Download the icon and add to your project repo.
- Create a repo for your project on GitHub
- Push your code to the repo with the icon file
- Navigate to the Settings page for the repository
- Scroll down to the "GitHub Pages" section
- Select the source for your GitHub Pages for th project
- Select "Save
- Select "Choose a theme"
- Select a theme
- Use a web browser to navigate to your GitHub Pages for the project. The URL follows the pattern: https://.github.io/
- The URL to the icon file is: https://.github.io//
- Use that URL when you configure Google Chat Hangouts API setting in you GCP project
- Read https://cloud.google.com/resource-manager/docs/creating-managing-projects
- Navigate in a web browser to GCP Resource Manager - https://console.cloud.google.com/cloud-resource-manager
- Select "Create Project"
- NOTE: There seems to be a bug in GCP here where the new project does not appear on the webpage. Simply refresh the webpage.
- Navigate in a web browser to GCP Console - https://console.developers.google.com/
- Select Navigation Menu (upper lefthand corner) > IAM & Admin > Service Accounts
- Select the GCP project that you want to create the service account for
- Select "Create Service Account"
- Enter the service account details that you want to use
- Select "Create"
- Select "Done"
- Select the "Email"(or Edit) of the new service account to navigate to the service account details
- Select "Add Key"
- Navigate in a web browser to GCP Console - https://console.developers.google.com/
- Select Navigation Menu (upper lefthand corner) > API & Services > Library
- Type "hangouts chat" in the search bar
- Select "Hangouts Chat API"
- If not already enabled, select "Enable"; otherwise, select "Manage"
- Select "Configuration"
- Set "Bot status" to "LIVE"
- Set "Bot name" that will be the name used for the bot as it appears in Google Chat - use something easy to type (e.g. "aws")
- Set "Functionality" to be enabled for both direct messages and rooms
- Set "Connection settings" to "Apps Script project"
- Set the Deployment ID for the deployment of your Google Apps Script implementation of your ChatBot (we recommend that you use the deployment ID that points to the Latest Version)
- Set slash commands as follows:
- "/aws" = Command ID 1 with a description of "Issue AWS commands"
- Set permissions to the individual users or user groups that you want to allow access to install the bot
- Select "Save"
- Navigate in a web browser to Google Chats - https://chat.google.com/
- Scroll down to the "Bots" section
- Select the "+" symbol to add a bot
- In the search bar, type in the name of the chatbot that you configured in the GCP Google Hangouts Chat API settings.
- When you use a bot for the first time, you may get a response with a link displayed as "Configure"
- Select "Configure" and allow the bot to have the authorizations it needs
- Once added, test out the bot commands such as:
- "/aws help"
- "/aws iam"
- "/aws vpc"
- "/aws s3"
- "/aws s3 ls"
- "/aws ec2"
- NOTE: When using the Google Chat slash commands, you will need to either select them from the list as you type the command or type the tab key. Otherwise, Google Chat does not recognize the text literal "/aws" as a slash command. (Stupid)
- Navigate in a web browser to Google Apps Script Executions - https://script.google.com/home/executions
- Select "My Executions"
- Select the execution that you want to view - the details of the execution should expand
- View the log messages created from the Logger.log statements
- ECMAscript - https://tc39.es/ecma262/#sec-intro
- V8 Engine - https://v8.dev/
- Google Apps Script Guide - https://developers.google.com/apps-script/overview
- Google Apps Script Reference - https://developers.google.com/apps-script/reference
- Google Apps Script Manifest File for Google Chat API - https://developers.google.com/hangouts/chat/how-tos/bots-apps-script#manifest_file
- GCP Resource Manager - https://console.cloud.google.com/cloud-resource-manager
- GCP Developer Console - https://console.developers.google.com/
- GCP Hangouts Chat Bot - https://developers.google.com/hangouts/chat/how-tos/bots-publish
- AWS JavaScript Client - https://github.com/smithy545/aws-apps-scripts
- AWS JavaScript SDK (for reference - does not work in Google Apps Script) - https://github.com/aws/aws-sdk-js
- GitHub Pages - https://pages.github.com/
- Getting Started With GitHub Pages - https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages/getting-started-with-github-pages