Skip to content

feat: add Google Chat channel with Pub/Sub pull, Cards V2, Drive upload#196

Open
duhd-vnpay wants to merge 1 commit intonextlevelbuilder:mainfrom
duhd-vnpay:feat/google-chat-channel
Open

feat: add Google Chat channel with Pub/Sub pull, Cards V2, Drive upload#196
duhd-vnpay wants to merge 1 commit intonextlevelbuilder:mainfrom
duhd-vnpay:feat/google-chat-channel

Conversation

@duhd-vnpay
Copy link

@duhd-vnpay duhd-vnpay commented Mar 14, 2026

Summary

Full Google Chat channel integration using pure HTTP (no Google client libraries):

  • Auth: Service Account JWT → access token with auto-refresh (60s pre-expiry)
  • Inbound: Pub/Sub REST pull loop with dedup cache, base64 event parsing, DM/group routing
  • Outbound: Markdown→Google Chat format conversion (bold, italic, strikethrough, links), byte-aware chunking (3900B safety limit for Vietnamese/CJK), Cards V2 for tables
  • Media: Chat API attachment download, Google Drive multipart upload for long-form responses, retention cleanup loop
  • Send pipeline: Placeholder edit pattern (Thinking... → final), exponential backoff retry on 429/5xx, thread routing for groups
  • Factory: ChannelFactory pattern for DB-instance hot-reload, config-file fallback registration
  • Phase 2 stubs: webhook.go (push mode), stream.go (progressive edit)

New Files (14)

File Purpose
internal/channels/googlechat/constants.go API URLs, limits, scopes, retry config
internal/channels/googlechat/auth.go Service Account JWT auth with auto-refresh
internal/channels/googlechat/auth_test.go 6 auth tests
internal/channels/googlechat/format.go Markdown conversion, byte-aware chunking, summary extraction
internal/channels/googlechat/format_test.go 19 format tests (markdown, chunking, Unicode, summary)
internal/channels/googlechat/pubsub.go Pub/Sub pull loop, event parsing, dedup cache
internal/channels/googlechat/pubsub_test.go 9 pubsub tests
internal/channels/googlechat/media.go Attachment download, Drive upload, retention cleanup
internal/channels/googlechat/send.go Send pipeline, Cards V2, placeholder edit, retry
internal/channels/googlechat/send_test.go 3 send tests
internal/channels/googlechat/googlechat.go Channel struct, constructor, Start/Stop lifecycle
internal/channels/googlechat/factory.go ChannelFactory for DB-instance hot-reload
internal/channels/googlechat/webhook.go Phase 2 stub
internal/channels/googlechat/stream.go Phase 2 stub

Modified Files (4)

File Change
internal/channels/channel.go Added TypeGoogleChat = "google_chat"
internal/config/config_channels.go Added GoogleChatConfig struct (18 fields)
cmd/gateway_channels_setup.go Config-based Google Chat registration
cmd/gateway.go Factory registration for DB instances

Test Results (28/28 PASS)

=== RUN   TestNewServiceAccountAuth_ValidFile          --- PASS (0.09s)
=== RUN   TestNewServiceAccountAuth_InvalidFile        --- PASS (0.02s)
=== RUN   TestNewServiceAccountAuth_MissingFile         --- PASS (0.00s)
=== RUN   TestServiceAccountAuth_Token_CachesWithinTTL --- PASS (0.11s)
=== RUN   TestServiceAccountAuth_Token_RefreshesExpired --- PASS (0.28s)
=== RUN   TestServiceAccountAuth_Token_RefreshFailure  --- PASS (0.06s)
=== RUN   TestMarkdownToGoogleChat (10 sub-tests)      --- PASS (0.00s)
=== RUN   TestDetectStructuredContent (5 sub-tests)    --- PASS (0.00s)
=== RUN   TestChunkByBytes (3 sub-tests)               --- PASS (0.00s)
=== RUN   TestChunkByBytes_Unicode                     --- PASS (0.00s)
=== RUN   TestExtractSummary (5 sub-tests)             --- PASS (0.00s)
=== RUN   TestParseEvent_Message                       --- PASS (0.00s)
=== RUN   TestParseEvent_GroupSpace                    --- PASS (0.00s)
=== RUN   TestParseEvent_AddedToSpace                  --- PASS (0.00s)
=== RUN   TestParseEvent_MalformedJSON                 --- PASS (0.00s)
=== RUN   TestParseEvent_EmptyData                     --- PASS (0.00s)
=== RUN   TestParseEvent_MissingSender                  --- PASS (0.00s)
=== RUN   TestParseEvent_BotSelfFilter                 --- PASS (0.00s)
=== RUN   TestParseEvent_WithAttachment                --- PASS (0.00s)
=== RUN   TestDedupCache                               --- PASS (0.00s)
=== RUN   TestSendMessage_ShortDM                      --- PASS (0.00s)
=== RUN   TestSendMessage_EmptyContent                 --- PASS (0.00s)
=== RUN   TestBuildCardMessage_Table                   --- PASS (0.00s)
PASS
ok  github.com/nextlevelbuilder/goclaw/internal/channels/googlechat  0.625s

Test plan

  • Verify go build ./... compiles cleanly
  • Verify go test ./internal/channels/googlechat/... passes (28 tests)
  • Verify no regressions in existing channel tests
  • Integration test with real Google Chat workspace (requires SA + Pub/Sub setup)

🤖 Generated with Claude Code

Implements Google Chat as a new channel type (google_chat) in GoClaw:
- Service Account JWT auth with auto-refresh (no Google client libs)
- Pub/Sub REST pull loop for inbound messages with dedup cache
- Markdown → Google Chat text format conversion (bold, italic, links)
- Cards V2 for tables/structured content
- Byte-aware chunking for Vietnamese/CJK (3900-byte safety limit)
- Drive upload for long-form responses with retention cleanup
- Thread routing for group conversations
- Placeholder edit pattern (Thinking... → final response)
- Exponential backoff retry on 429/5xx
- 28 unit tests, all passing

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant