Skip to main content

Google Chat adapter for chat-py

Project description

chat-adapter-gchat

Google Chat adapter for chat-py. Python port of upstream packages/adapter-gchat.

Supports both HTTP-endpoint Chat apps (Workspace Add-ons event envelopes) and Pub/Sub-delivered Workspace Events subscriptions.

Install

uv add chat-py chat-py-adapter-gchat chat-py-adapter-state-pg

Auth / config

GoogleChatAdapterConfig — four auth modes mirror upstream:

Mode Config fields
Service account JSON credentials (a ServiceAccountCredentials dict)
Application Default Credentials useApplicationDefaultCredentials=True
Custom auth auth (callable returning a bearer token)
Auto from env none — relies on GOOGLE_APPLICATION_CREDENTIALS etc.

Additional config: googleChatProjectNumber, impersonateUser, pubsubAudience, pubsubTopic, endpointUrl.

Minimal example

from chat import Chat
from chat_adapter_gchat import create_google_chat_adapter
from chat_adapter_state_pg import create_postgres_state

bot = Chat(
    user_name="mybot",
    adapters={"gchat": create_google_chat_adapter(
        credentials=...,  # service account JSON dict
    )},
    state=create_postgres_state(url="postgres://localhost/chat"),
)


@bot.on_new_mention
async def greet(thread, message):
    await thread.post("Hi!")

Mount bot.handle_webhook("gchat", body, headers) under /api/webhooks/gchat. The adapter verifies incoming requests via bearer tokens (HTTP-endpoint apps) or Pub/Sub-signed JWTs (Workspace Events subscriptions — see decode_pubsub_message).

Thread ID

Google Chat thread IDs: gchat:spaces/{spaceId}:{base64(threadName)}.

Features

  • HTTP-endpoint and Pub/Sub Workspace Events dispatch paths
  • Space-subscription management (create_space_subscription, list_space_subscriptions, delete_space_subscription) with TTL-based refresh
  • UserInfoCache for bot-to-user display-name lookups
  • Card v2 translation (card_to_google_card) — sections, headers, buttons, images, grids
  • Markdown ↔ mdast via GoogleChatFormatConverter

Parity notes

  • Matches upstream's cache TTLs (SUBSCRIPTION_CACHE_TTL_MS, SUBSCRIPTION_REFRESH_BUFFER_MS).
  • Bearer-token verification (verify_bearer_token) uses the same issuer allowlist as upstream.
  • Supplying both credentials and useApplicationDefaultCredentials raises ValidationError.

Test

uv run pytest packages/chat-adapter-gchat

# Live — requires a configured project and credentials
GCHAT_PROJECT=... uv run pytest packages/chat-integration-tests -k gchat

Upstream

https://github.com/vercel/chat/tree/main/packages/adapter-gchat

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chat_py_adapter_gchat-0.1.0.tar.gz (40.1 kB view details)

Uploaded Source

File details

Details for the file chat_py_adapter_gchat-0.1.0.tar.gz.

File metadata

  • Download URL: chat_py_adapter_gchat-0.1.0.tar.gz
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for chat_py_adapter_gchat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0517db4aae678c26011e7c06fbb1bd0e80552c1473d12f7e1387383fbb0cd002
MD5 98eb6c85ee1620e33dcf094edf13a366
BLAKE2b-256 d30da54bb2470dc271846284c994b5801730e7146cc43c72b7584d71213bfed8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page