chat-client/client_utils.py (661 lines of code) (raw):
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from googleapiclient import _auth as auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
chat_client = build(
"chat",
"v1",
http=auth.authorized_http(
auth.default_credentials(scopes=["https://www.googleapis.com/auth/chat.bot"])
),
)
def retrieve_dialog_response(notes, blogs):
return {
"action": {
"navigations": [
{
"pushCard": {
"sections": [
{
"widgets": [
{
"selectionInput": {
"name": "contactType",
"label": "Product",
"multiSelectMaxSelectedItems": "300",
"multiSelectMinQueryLength": "0",
"type": "MULTI_SELECT",
"items": notes,
}
},
{
"selectionInput": {
"name": "blogType",
"label": "Blog Category",
"multiSelectMaxSelectedItems": "300",
"multiSelectMinQueryLength": "0",
"type": "MULTI_SELECT",
"items": blogs,
}
},
# {
# "selectionInput": {
# "name": "interval",
# "label": "I would like to check for new updates every:",
# "type": "RADIO_BUTTON",
# "items": [
# {
# "text": "5 minutes",
# "value": "5m",
# "selected": False,
# },
# {
# "text": "30 minutes",
# "value": "30m",
# "selected": False,
# },
# {
# "text": "1 hour",
# "value": "1hr",
# "selected": False,
# },
# {
# "text": "8 hours",
# "value": "8hr",
# "selected": False,
# },
# {
# "text": "24 hours",
# "value": "24hr",
# "selected": False,
# },
# ],
# }
# },
{
"buttonList": {
"buttons": [
{
"text": "Subscribe",
"onClick": {
"action": {
"function": os.environ.get(
"BASE_URL"
),
"parameters": [
{
"key": "actionName",
"value": "submitDialog",
}
],
}
},
}
]
}
},
]
}
]
}
}
]
}
}
def send_chat_message(space_id, message_body):
try:
response = (
chat_client.spaces()
.messages()
.create(
parent=space_id,
body=message_body,
messageReplyOption="REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD",
)
.execute()
)
print(f"Response from sending chat message: {response}")
print(f"Successfully sent message to space {space_id}")
except HttpError as e:
print(f"Error sending message to space {space_id}: {e._get_reason()}")
categories = [
"All Blogs",
"AI & Machine Learning",
"API Management",
"Application Development",
"Application Modernization",
"Chrome Enterprise",
"Compute",
"Containers & Kubernetes",
"Data Analytics",
"Databases",
"DevOps & SRE",
"Financial Services",
"Healthcare & Life Sciences",
"Manufacturing",
"Media & Entertainment",
"Public Sector",
"Retail",
"Supply Chain & Logistics",
"Telecommunications",
"Partners",
"Startups & SMB",
"Inside Google Cloud",
"Google Cloud Consulting",
# "Maps & Geospatial", # RSS for this category is not available
"Security & Identity",
"Threat Intelligence",
"Infrastructure",
"Infrastructure Modernization",
"Networking",
"Productivity & Collaboration",
"SAP on Google Cloud",
"Storage & Data Transfer",
"Sustainability",
]
data_categories = [
"All Data Blogs",
"Data Analytics",
"Databases",
"SAP on Google Cloud",
"Storage & Data Transfer",
]
google_cloud_products = [
"All Products",
"All AI Products",
"All Data Products",
"All App Mod Products",
"All Security Products",
"Access Approval",
"Access Approval v1",
"Access Context Manager",
"Access Transparency",
"Advisory Notifications",
"Agent Assist",
"AI Hypercomputer",
"AI Platform",
"AlloyDB for PostgreSQL",
"Anthos Attached Clusters",
"Anthos clusters on AWS",
"Anthos clusters on Azure",
"Anthos Config Management",
"Anthos Service Mesh - Security Bulletins",
"Anti Money Laundering AI",
"API Gateway",
"API Gateway v1",
"Apigee",
"Apigee - Security Bulletins",
"Apigee Advanced API Security",
"Apigee API hub",
"Apigee hybrid",
"Apigee Integrated Portal",
"Apigee Integration",
"Apigee Monetization",
"Apigee UI",
"Apigee X",
"App Engine flexible environment .NET",
"App Engine flexible environment custom runtimes",
"App Engine flexible environment Go",
"App Engine flexible environment Java",
"App Engine flexible environment Node.js",
"App Engine flexible environment PHP",
"App Engine flexible environment Python",
"App Engine flexible environment Ruby",
"App Engine Standard 1.11",
"App Engine standard environment Go",
"App Engine standard environment Go 1.12",
"App Engine standard environment Java",
"App Engine standard environment Java 8",
"App Engine standard environment Java gen2",
"App Engine standard environment Node.js",
"App Engine standard environment PHP",
"App Engine standard environment PHP 5",
"App Engine standard environment PHP 7",
"App Engine standard environment Python",
"App Engine standard environment Python 2.7",
"App Engine standard environment Python 3",
"App Engine standard environment Ruby",
"App Hub",
"Application Integration",
"Artifact Registry",
"Artifact Registry v1",
"Assured Workloads",
"Assured Workloads v1",
"Assured Workloads v1beta1",
"Audit Manager",
"AutoML Natural Language",
"AutoML Tables",
"AutoML Translation",
"AutoML Vision Image Classification (ICN",
"AutoML Vision Object Detection",
"Backup and DR",
"Backup for GKE",
"Bare Metal Solution",
"Bare Metal Solution - Security Bulletins",
"Batch",
"BeyondCorp Enterprise",
"BigQuery",
"BigQuery Engine for Apache Flink",
"Bigtable",
"Binary Authorization",
"Blockchain Analytics",
"Blockchain Node Engine",
"Buildpacks",
"Capacity Planner",
"Carbon Footprint",
"Certificate Authority Service",
"Certificate Authority Service v1",
"Certificate Manager",
"Channel Services",
"Channel Services v1",
"Cloud Asset Inventory",
"Cloud Billing",
"Cloud Build",
"Cloud CDN",
"Cloud Composer",
"Cloud Data Fusion",
"Cloud Database Migration Service",
"Cloud Database Migration Service v1",
"Cloud Deploy",
"Cloud DNS",
"Cloud Domains",
"Cloud Endpoints",
"Cloud Healthcare API",
"Cloud Healthcare API v1",
"Cloud Healthcare API v1beta1",
"Cloud IAM - Permissions Change Log",
"Cloud Identity",
"Cloud Interconnect",
"Cloud Key Management Service",
"Cloud Life Sciences",
"Cloud Load Balancing",
"Cloud Logging",
"Cloud Monitoring",
"Cloud NAT",
"Cloud NGFW",
"Cloud NGFW v1",
"Cloud Quotas",
"Cloud Quotas v1",
"Cloud Quotas v1beta",
"Cloud Router",
"Cloud Run",
"Cloud Run functions",
"Cloud Service Mesh",
"Cloud Service Mesh - Security Bulletins",
"Cloud Shell",
"Cloud Source Repositories",
"Cloud SQL",
"Cloud SQL for MySQL",
"Cloud SQL for PostgreSQL",
"Cloud SQL for SQL Server",
"Cloud Storage",
"Cloud Talent Solution Job Search",
"Cloud Talent Solution Job Search v4",
"Cloud Tasks",
"Cloud Tasks v2",
"Cloud Tasks v2beta3",
"Cloud TPU",
"Cloud Trace",
"Cloud Translation",
"Cloud Vision",
"Cloud VPN",
"Cloud Workstations",
"Colab Enterprise",
"compute - Security Bulletins",
"Compute Engine",
"Compute Engine - Security Bulletins",
"Confidential Space",
"Confidential VM",
"Confidential VM - Security Bulletins",
"Config Connector",
"Config Controller",
"Contact Center AI Insights",
"Container Optimized OS",
"Container Registry",
"Cortex Framework",
"Data Catalog",
"Data Catalog v1",
"Data Catalog v1beta1",
"Database Center",
"Dataflow",
"Dataflow - Security Bulletins",
"Dataform",
"Dataplex",
"Dataproc",
"Dataproc Metastore",
"Datastream",
"Deep Learning Containers",
"Deep Learning VM Images",
"Developer Connect",
"Dialogflow",
"Document AI",
"Document AI Warehouse",
"Error Reporting",
"Eventarc",
"Filestore",
"Firestore",
"Firestore in Datastore mode",
"Gemini",
"Gemini Code Assist",
"Gemini Code Assist in Apigee",
"Generative AI on Vertex AI",
"GitLab on Google Cloud",
"GKE - Security Bulletins",
"Google Agentspace",
"Google Cloud - Security Bulletins",
"Google Cloud Architecture Center",
"Google Cloud Armor",
"Google Cloud Contact Center as a Service",
"Google Cloud Managed Service for Apache Kafka",
"Google Cloud Marketplace",
"Google Cloud Marketplace Partners",
"Google Cloud Observability",
"Google Cloud VMware Engine",
"Google Cloud VMware Engine - Security Bulletins",
"Google Distributed Cloud (software only) for bare metal",
"Google Distributed Cloud (software only) for VMware",
"Google Distributed Cloud connected",
"Google Distributed Cloud connected - Security Bulletins",
"Google Distributed Cloud Edge Distributed Cloud Edge management software",
"Google Kubernetes Engine",
"Google Kubernetes Engine Extended Channel",
"Google Kubernetes Engine Main",
"Google Kubernetes Engine New Features",
"Google Kubernetes Engine No Channel",
"Google Kubernetes Engine Rapid Channel",
"Google Kubernetes Engine Regular Channel",
"Google Kubernetes Engine Stable Channel",
"Google SecOps",
"Google SecOps SIEM",
"Google SecOps SOAR",
"Identity and Access Management",
"Identity Platform",
"Identity-Aware Proxy",
"Immersive Stream for XR",
"Infrastructure Manager",
"Integration Connectors",
"Kf",
"Live Stream API",
"Looker",
"Looker Looker (Google Cloud core) and Looker (original) changes",
"Looker Looker (Google Cloud core) only changes",
"Looker Looker (original) only changes",
"Looker Studio",
"Mainframe Assessment Tool",
"Mainframe Connector",
"Managed Anthos Service Mesh Managed Anthos Service Mesh",
"Managed Cloud Service Mesh Managed Cloud Service Mesh",
"Managed Service for Microsoft Active Directory",
"Manufacturing Data Engine",
"Media CDN",
"Memorystore for Memcached",
"Memorystore for Memcached v1",
"Memorystore for Redis",
"Migrate to Containers",
"Migrate to Containers - Security Bulletins",
"Migrate to Virtual Machines",
"Migrate to Virtual Machines - Security Bulletins",
"Migration Center",
"NetApp Volumes",
"Network Connectivity Center",
"Network Intelligence Center",
"Network Security Integration",
"Oracle Database@Google Cloud",
"Organization Policy",
"Parallelstore",
"Policy Controller",
"Policy Intelligence",
"Pub/Sub",
"Pub/Sub Lite",
"reCAPTCHA",
"Recommender",
"Recommender v1beta1",
"Resource Manager",
"Retail API",
"SAP on Google Cloud",
"Secret Manager",
"Secure Source Manager",
"Security Command Center",
"Sensitive Data Protection",
"Service Catalog",
"Service Extensions",
"Service Health",
"Sovereign Controls by Partners",
"Sovereign Controls by Partners for Partners",
"Spanner",
"Speech-to-Text",
"Storage Transfer Service",
"StratoZone",
"Terraform on Google Cloud",
"Text-to-Speech",
"Transcoder API",
"Unified Maintenance",
"Vertex AI",
"Vertex AI Agent Builder",
"Vertex AI Model Garden",
"Vertex AI Vision",
"Vertex AI Workbench",
"Vertex AI Workbench v1",
"Vertex AI Workbench v2",
"Video Stitcher API",
"Virtual Private Cloud",
"VM Runtime on Google Distributed Cloud",
"VPC Service Controls",
"Workflows",
"Workflows v1",
]
google_cloud_ai_products = [
"All AI Products",
"Agent Assist",
"AI Hypercomputer",
"AI Platform", # Note: Vertex AI is the successor, but listed separately
"Anti Money Laundering AI",
"AutoML Natural Language",
"AutoML Tables",
"AutoML Translation",
"AutoML Vision Image Classification (ICN)",
"AutoML Vision Object Detection",
"Cloud Healthcare API",
"Cloud Healthcare API v1",
"Cloud Healthcare API v1beta1",
"Cloud Life Sciences", # Processes data often using AI/ML pipelines
"Cloud Talent Solution Job Search",
"Cloud Talent Solution Job Search v4",
"Cloud TPU",
"Cloud Translation",
"Cloud Vision",
"Colab Enterprise",
"Contact Center AI Insights",
"Deep Learning Containers",
"Deep Learning VM Images",
"Dialogflow",
"Document AI",
"Document AI Warehouse",
"Gemini",
"Gemini Code Assist",
"Gemini Code Assist in Apigee",
"Generative AI on Vertex AI",
"Google Agentspace",
"Google Cloud Contact Center as a Service", # Often includes CCAI
"Retail API",
"Speech-to-Text",
"Text-to-Speech",
"Vertex AI",
"Vertex AI Agent Builder",
"Vertex AI Model Garden",
"Vertex AI Vision",
"Vertex AI Workbench",
"Vertex AI Workbench v1",
"Vertex AI Workbench v2",
]
# Application Modernization and General Compute Products
google_cloud_app_mod_products = [
"All App Mod Products",
"Anthos Attached Clusters",
"Anthos clusters on AWS",
"Anthos clusters on Azure",
"Anthos Config Management",
"API Gateway",
"API Gateway v1",
"Apigee",
"Apigee Advanced API Security", # Part of Apigee Suite
"Apigee API hub",
"Apigee hybrid",
"Apigee Integrated Portal",
"Apigee Integration",
"Apigee Monetization",
"Apigee UI",
"Apigee X",
"App Engine flexible environment .NET",
"App Engine flexible environment custom runtimes",
"App Engine flexible environment Go",
"App Engine flexible environment Java",
"App Engine flexible environment Node.js",
"App Engine flexible environment PHP",
"App Engine flexible environment Python",
"App Engine flexible environment Ruby",
"App Engine Standard 1.11",
"App Engine standard environment Go",
"App Engine standard environment Go 1.12",
"App Engine standard environment Java",
"App Engine standard environment Java 8",
"App Engine standard environment Java gen2",
"App Engine standard environment Node.js",
"App Engine standard environment PHP",
"App Engine standard environment PHP 5",
"App Engine standard environment PHP 7",
"App Engine standard environment Python",
"App Engine standard environment Python 2.7",
"App Engine standard environment Python 3",
"App Engine standard environment Ruby",
"App Hub",
"Application Integration",
"Artifact Registry",
"Artifact Registry v1",
"Backup and DR", # Infrastructure resilience/Ops
"Backup for GKE",
"Bare Metal Solution",
"Batch",
"Blockchain Node Engine",
"Buildpacks",
"Capacity Planner",
"Cloud Build",
"Cloud CDN",
"Cloud Deploy",
"Cloud DNS",
"Cloud Domains",
"Cloud Endpoints",
"Cloud Interconnect",
"Cloud Load Balancing",
"Cloud Logging", # Ops/Observability aspect
"Cloud Monitoring", # Ops/Observability aspect
"Cloud NAT",
"Cloud Quotas", # Ops aspect
"Cloud Quotas v1",
"Cloud Quotas v1beta",
"Cloud Router",
"Cloud Run",
"Cloud Run functions",
"Cloud Service Mesh",
"Cloud Shell",
"Cloud Source Repositories",
"Cloud Tasks",
"Cloud Tasks v2",
"Cloud Tasks v2beta3",
"Cloud Trace", # Ops/Observability aspect
"Cloud Workstations",
"Compute Engine",
"Config Connector",
"Config Controller",
"Container Optimized OS",
"Container Registry",
"Developer Connect",
"Error Reporting", # Ops/Observability aspect
"Eventarc",
"GitLab on Google Cloud",
"Google Cloud Observability", # Suite term
"Google Cloud VMware Engine",
"Google Distributed Cloud (software only) for bare metal",
"Google Distributed Cloud (software only) for VMware",
"Google Distributed Cloud connected",
"Google Distributed Cloud Edge Distributed Cloud Edge management software",
"Google Kubernetes Engine",
"Immersive Stream for XR",
"Infrastructure Manager",
"Integration Connectors",
"Kf",
"Live Stream API",
"Managed Anthos Service Mesh Managed Anthos Service Mesh", # Refers to managed service mesh
"Managed Cloud Service Mesh Managed Cloud Service Mesh", # Refers to managed service mesh
"Media CDN",
"Migrate to Containers",
"Migrate to Virtual Machines",
"Migration Center",
"Network Connectivity Center",
"Network Intelligence Center", # Network Ops aspect
"Recommender", # Performance/Ops aspect
"Recommender v1beta1", # Performance/Ops aspect
"SAP on Google Cloud", # Solutions often involve compute/infra
"Service Catalog",
"Service Extensions",
"StratoZone",
"Terraform on Google Cloud", # IaC/Ops
"Transcoder API",
"Video Stitcher API",
"Virtual Private Cloud",
"VM Runtime on Google Distributed Cloud",
"Workflows",
"Workflows v1",
]
# Security Products
google_cloud_security_products = [
"All Security Products",
"Access Approval",
"Access Approval v1",
"Access Context Manager",
"Access Transparency",
"Advisory Notifications", # Includes security advisories
"Assured Workloads",
"Assured Workloads v1",
"Assured Workloads v1beta1",
"Audit Manager",
"BeyondCorp Enterprise",
"Binary Authorization",
"Certificate Authority Service",
"Certificate Authority Service v1",
"Certificate Manager",
"Cloud Asset Inventory", # Security visibility
"Cloud IAM - Permissions Change Log",
"Cloud Identity",
"Cloud Key Management Service",
"Cloud Logging", # Security Auditing aspect
"Cloud NGFW",
"Cloud NGFW v1",
"Cloud VPN",
"Confidential Space",
"Confidential VM",
"Google Cloud Armor",
"Google SecOps",
"Google SecOps SIEM",
"Google SecOps SOAR",
"Identity and Access Management",
"Identity Platform",
"Identity-Aware Proxy",
"Managed Service for Microsoft Active Directory", # Identity/Security related
"Network Security Integration",
"Organization Policy", # Security controls
"Policy Controller",
"Policy Intelligence",
"reCAPTCHA",
"Recommender", # Security aspect
"Recommender v1beta1", # Security aspect
"Resource Manager", # Org structure/boundary control
"Secret Manager",
"Secure Source Manager", # Source code security focus
"Security Command Center",
"Sensitive Data Protection",
"Sovereign Controls by Partners",
"VPC Service Controls",
]
google_cloud_data_products = [
"All Data Products",
"AlloyDB for PostgreSQL",
"BigQuery",
"BigQuery Engine for Apache Flink",
"Bigtable",
"Cloud Composer",
"Cloud Data Fusion",
"Cloud Database Migration Service",
"Cloud Database Migration Service v1",
"Cloud SQL",
"Cloud SQL for MySQL",
"Cloud SQL for PostgreSQL",
"Cloud SQL for SQL Server",
"Cloud Storage",
"Data Catalog",
"Data Catalog v1",
"Data Catalog v1beta1",
"Database Center",
"Dataflow",
"Dataflow - Security Bulletins",
"Dataform",
"Dataplex",
"Dataproc",
"Dataproc Metastore",
"Datastream",
"Filestore",
"Firestore",
"Firestore in Datastore mode",
"Looker",
"Looker Looker (Google Cloud core) and Looker (original) changes",
"Looker Looker (Google Cloud core) only changes",
"Looker Looker (original) only changes",
"Looker Studio",
"Mainframe Assessment Tool",
"Mainframe Connector",
"Pub/Sub",
"Pub/Sub Lite",
]