googlechat

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

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 New

func New(cfg Config, opts ...messenger.Option) *Messenger

New creates a new Google Chat Messenger with the given config and options.

func (*Messenger) Connect

func (m *Messenger) Connect(ctx context.Context) (http.Handler, error)

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

func (m *Messenger) ConnectionInfo() string

ConnectionInfo returns connection instructions for the Google Chat adapter.

func (*Messenger) Disconnect

func (m *Messenger) Disconnect(ctx context.Context) error

Disconnect gracefully shuts down the Google Chat adapter.

func (*Messenger) FormatApproval

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

FormatClarification builds a Google Chat Cards v2 message for a clarification question.

func (*Messenger) Platform

func (m *Messenger) Platform() messenger.Platform

Platform returns the Google Chat platform identifier.

func (*Messenger) Receive

func (m *Messenger) Receive(_ context.Context) (<-chan messenger.IncomingMessage, error)

Receive returns a channel of incoming messages from Google Chat.

func (*Messenger) Send

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

func (m *Messenger) UpdateMessage(_ context.Context, _ messenger.UpdateRequest) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL