A demonstration Chat App that translates JSON payloads from the Cognigy platform into interactive Google Chat Card V2 messages. This project serves as a reference for integrating a conversational AI backend with a Google Chat frontend using a serverless GCP architecture.
This repository contains the source code and deployment instructions for a Google Chat application designed to act as a middleware and translator. The application receives proprietary JSON formats from a backend like Cognigy and transforms them into rich, interactive UI cards for display within Google Chat.
This showcase bot is pre-configured with five common Cognigy output formats (Gallery, Quick Replies, Buttons, List, and Image) and demonstrates their visual representation in Google Chat.
The solution uses a secure, scalable, and fully serverless architecture on Google Cloud Platform.
- Google Chat: The user interface where users interact with the application.
- API Gateway: Provides a secure, public-facing HTTPS endpoint to receive webhook events from Google Chat. It handles authentication and forwards requests to the backend service.
- Cloud Run: A serverless container platform that hosts the core application logic written in Python (Flask). It receives requests, performs the JSON translation, and returns the formatted card message.
- Modular Code Structure: The Python code is organized into separate files for routing (
main.py), payload storage (payloads.py), and card creation logic (cards.py) for improved readability and maintenance. - Interactive Showcase: The bot presents a welcome card with buttons, allowing users to easily trigger and view each of the five translated card types.
- Secure by Default: The Cloud Run service is deployed to require authentication, and API Gateway is configured to use a dedicated Service Account with the
Cloud Run Invokerrole to securely communicate with the backend.
This guide outlines the process for deploying the Showcase Bot using the Google Cloud Console.
- A Google Cloud Project with billing enabled.
- A Google Workspace account with permissions to configure Google Chat applications.
- The source code for
main.py,cards.py, andpayloads.pyready to be copied.
- In the Google Cloud Console, navigate to APIs & Services > Library.
- Search for and enable each of the following APIs one by one:
Cloud Run APICloud Build APIAPI Gateway APIService Management APIService Control APIIdentity and Access Management (IAM) API
- Initial Service Creation:
- Navigate to Cloud Run in the Google Cloud Console.
- Click Create Service.
- Select Function: Use an inline editor to create a function. (We will add the code in a later step).
- Enter a Service name, for example,
chatbot-vcard. - Select a Region.
- Under Authentication, select Require authentication.
- Under Ingress, select All: Allow direct access from the internet.
- Click Create. This will create the service shell.
- Add Source Code:
- On the service details page for your newly created service, click Edit Source or similar.
- This will open an inline code editor.
- In the editor's file explorer on the left:
- Click the
main.pyfile and replace all of its content with the code from the repository. - Click the
requirements.txtfile and add a single line:Flask. - Click in the
+at the top of the directory and select New File. Name itcards.py. Paste the corresponding code from the repository into this file. - Create another new file named
payloads.py. Paste the corresponding code from the repository into this file.
- Click the
- Click Deploy. Cloud Build will now build and deploy your service with the correct code.
- Once deployed, copy the Service URL from the top of the Cloud Run service page.
- Create a Service Account:
- Navigate to IAM & Admin > Service Accounts.
- Click Create Service Account.
- Enter a name (e.g.,
api-gateway-invoker) and click Create and Continue, then Done. - Copy the email address of the new service account.
- Grant Invoker Permissions:
- Navigate back to your Cloud Run service page.
- In "Services" check the box of the Cloud Run Function and click on "Permissions"
- Click Add Principal.
- In the New principals field, paste the service account's email.
- In the Assign roles dropdown, select the role
Cloud Run Invoker. - Click Save.
- Create the API Gateway Specification:
- Create a file on your local machine named
openapi.yaml. - Add the repository yaml content, replacing
[YOUR_CLOUDRUN_SERVICE_URL]in both places with your actual service URL from Step 2.
- Create a file on your local machine named
- Create and Deploy the Gateway:
- Navigate to API Gateway in the Cloud Console.
- Click Create Gateway.
- In the "API" section, select Create a new API and give it a name (e.g.,
chatbot-api) and a corresponding API ID. - In the "Config" section, select Create new API Config.
- Under "API Spec", click Browse and upload the
openapi.yamlfile you just created. - Give the configuration a name (e.g.,
chatbot-config-v1). - For the Service account dropdown, select the
api-gateway-invokerservice account you created. - Enter a Gateway name (e.g.,
chatbot-gateway) and select your region. - Click Create Gateway.
- After deployment is complete, go to the gateway's details page and copy the URL.
- Navigate to the "Google Chat API" > "Configuration" page in the Google Cloud Console.
- Fill out the "Application info" (App name, Avatar URL, Description).
- Important: Ensure the checkbox for "Build this Chat as a Workspace add-on" is NOT checked.
- In the "Connection settings" section:
- "HTTP endpoint URL": Paste your new API Gateway URL.
- "Authentication Audience": Select "HTTP endpoint URL".
- Set your desired "Visibility" and click "SAVE".