This code sample creates a simple Google Chat app that responds to events and messages from a space. The sample is built using Node.JS 20 and ExpressJS on Google App Engine, Standard Environment.
-
Follow the steps in Setting Up Your Development Environment to install Node.JS 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 space or in a direct mention to engage with the app.
When added to a space or messaged, the app will respond with a simple reply.
- Install libraries:
npm install - Run the sample:
npm start
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"}}'
This code sample supports request verification but it's disabled by default. To enable it you need to:
-
Set the constant
audienceTypetoAPP_URLorPROJECT_NUMBERin the fileindex.jsdepending on the type of authentication audience you want to use. -
Set the constant
audiencein the fileindex.jsto the app URL or project number depending on what you specified in the previous step. -
Set the parameter
Authentication AudienceunderConnection settingsfrom the Google Chat app configuration to the same audience type you specified in theaudienceTypeconstant. -
Redeploy or restart the sample in AppEngine or locally and interact with the app as described in other sections.
You can learn more about Google Chat app request verification from the guide Verify requests from Google Chat.