Documentation
¶
Overview ¶
Package googlechat provides a Messenger adapter for Google Chat using HTTP push for incoming events and the Chat API for outgoing messages.
The adapter wraps google.golang.org/api/chat/v1 and exposes an HTTP endpoint that receives push events from Google Chat. Outgoing messages are sent via the Chat API's spaces.messages.create method.
Transport: HTTP push (public endpoint required for incoming events).
Authentication ¶
Google Chat uses the same logged-in user OAuth token as Gmail/Calendar/Drive. The application must pass messenger.WithSecretProvider(sp) when creating the messenger so the adapter can resolve the token (TokenFile, keyring, or env). No service account credentials file is used.
Migration from service account ¶
Previous versions used credentials_file and listen_addr with a service account. That configuration has been removed. Existing deployments should migrate to logged-in user OAuth: run setup and connect Google (same token as Gmail/Calendar). See the installation documentation for migration steps.
Usage ¶
m := googlechat.New(googlechat.Config{}, messenger.WithSecretProvider(sp))
if err := m.Connect(ctx); err != nil { /* handle */ }
defer m.Disconnect(ctx)
Index ¶
- type Config
- type Messenger
- func (m *Messenger) Connect(ctx context.Context) (http.Handler, error)
- func (m *Messenger) ConnectionInfo() string
- func (m *Messenger) Disconnect(ctx context.Context) error
- func (m *Messenger) FormatApproval(req messenger.SendRequest, info messenger.ApprovalInfo) messenger.SendRequest
- func (m *Messenger) FormatClarification(req messenger.SendRequest, info messenger.ClarificationInfo) messenger.SendRequest
- func (m *Messenger) Platform() messenger.Platform
- func (m *Messenger) Receive(_ context.Context) (<-chan messenger.IncomingMessage, error)
- func (m *Messenger) Send(ctx context.Context, req messenger.SendRequest) (messenger.SendResponse, error)
- func (m *Messenger) UpdateMessage(_ context.Context, _ messenger.UpdateRequest) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct{}
Config holds Google Chat-specific configuration. Authentication uses the logged-in user token via SecretProvider (pass WithSecretProvider when creating the messenger).
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger implements the messenger.Messenger interface for Google Chat. It manages the Chat API client, returns an HTTP handler for incoming push events, and tracks connection state through an internal mutex.
func (*Messenger) Connect ¶
Connect initializes the Chat API client and returns an http.Handler for receiving Google Chat push events. The caller mounts this handler on a shared HTTP mux at the desired context path.
The adapter DOES NOT start its own http.Server.
func (*Messenger) ConnectionInfo ¶
ConnectionInfo returns connection instructions for the Google Chat adapter.
func (*Messenger) Disconnect ¶
Disconnect gracefully shuts down the Google Chat adapter.
func (*Messenger) FormatApproval ¶
func (m *Messenger) FormatApproval(req messenger.SendRequest, info messenger.ApprovalInfo) messenger.SendRequest
FormatApproval builds a Google Chat Cards v2 message for an approval notification. This satisfies the messenger.ApprovalFormatter interface, keeping all Google Chat-specific formatting inside the adapter.
func (*Messenger) FormatClarification ¶
func (m *Messenger) FormatClarification(req messenger.SendRequest, info messenger.ClarificationInfo) messenger.SendRequest
FormatClarification builds a Google Chat Cards v2 message for a clarification question.
func (*Messenger) Send ¶
func (m *Messenger) Send(ctx context.Context, req messenger.SendRequest) (messenger.SendResponse, error)
Send delivers a message to a Google Chat space. If req.Metadata["cards_v2"] contains a []*chat.CardWithId, the message is sent with Cards v2 formatting (the text field is used as the plaintext fallback).
func (*Messenger) UpdateMessage ¶
UpdateMessage is a no-op for Google Chat — the adapter does not currently support editing previously sent messages. Returns nil to satisfy the Messenger interface without error.