chat

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chat is the interface every chat surface implements: Slack, Microsoft Teams, Discord and Mattermost.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	ApprovalID string `json:"approval_id"`
	Value      string `json:"value"`
	UserID     string `json:"user_id"`
	UserName   string `json:"user_name,omitempty"`
	UserEmail  string `json:"user_email,omitempty"`
	// Roles: see Incoming.Roles.
	Roles   []string   `json:"roles,omitempty"`
	Message MessageRef `json:"message"`
}

Action is a click on an approval button.

type Adapter

type Adapter interface {
	// Name is the surface name: slack, teams, discord or mattermost.
	Name() string
	// Routes returns the HTTP handlers the adapter needs mounted on the
	// public server, by path ("/slack/events"). Socket-mode adapters return
	// none.
	Routes(h Handler) map[string]http.Handler
	// Run holds the adapter's own connection (Slack Socket Mode) until ctx
	// ends. HTTP-only adapters block on ctx and return nil.
	Run(ctx context.Context, h Handler) error
	// Post sends a message to a thread.
	Post(ctx context.Context, t Thread, m Outgoing) (MessageRef, error)
	// Update replaces a posted message.
	Update(ctx context.Context, ref MessageRef, m Outgoing) error
	// AskApproval posts a message with buttons.
	AskApproval(ctx context.Context, t Thread, a Approval) (MessageRef, error)
	// ResolveApproval replaces the buttons with the outcome.
	ResolveApproval(ctx context.Context, ref MessageRef, a Approval, outcome string) error
	// Check verifies the tokens work. It is what kojo doctor runs.
	Check(ctx context.Context) error
}

Adapter is one chat surface.

type Approval

type Approval struct {
	// ID comes back in the Action when a button is clicked.
	ID    string `json:"id"`
	Title string `json:"title"`
	Text  string `json:"text"`
	// Options are the buttons. Default: approve and deny.
	Options []Option `json:"options,omitempty"`
}

Approval asks a human to choose: "Open PR?", "Merge?".

type Handler

type Handler interface {
	OnMessage(ctx context.Context, m Incoming) error
	OnAction(ctx context.Context, a Action) error
}

Handler receives what users do on a chat surface. Both methods must return quickly: they enqueue work, they do not do it.

type Incoming

type Incoming struct {
	Thread Thread `json:"thread"`
	// MessageID is the message itself (Slack: ts).
	MessageID string `json:"message_id"`
	// UserID and UserName identify the sender on the chat surface.
	UserID   string `json:"user_id"`
	UserName string `json:"user_name,omitempty"`
	// UserEmail is used to map the sender onto a kōjō user and role.
	UserEmail string `json:"user_email,omitempty"`
	// Roles are kōjō roles the surface itself vouches for, for surfaces
	// that do not give a bot the sender's email (Discord: mapped from the
	// sender's server roles in kojo.yaml). They add to what the rbac
	// object gives the email.
	Roles []string `json:"roles,omitempty"`
	// Text is the message with the bot mention removed.
	Text string `json:"text"`
	// Direct is true for a DM.
	Direct bool `json:"direct,omitempty"`
	// ReplyTo is, on a surface without threads (Discord), the message the
	// conversation this one continues started from: the message a reply
	// answers, or the one kōjō's message it answers was a reply to. Empty
	// elsewhere, where Thread.ThreadID says it.
	ReplyTo string `json:"reply_to,omitempty"`
}

Incoming is a message addressed to kōjō: a DM or a mention.

type MessageRef

type MessageRef struct {
	Thread    Thread `json:"thread"`
	MessageID string `json:"message_id"`
}

MessageRef names a posted message, to update it later.

type Option

type Option struct {
	Value string `json:"value"` // approve, deny
	Label string `json:"label"`
	// Style is primary, danger or empty.
	Style string `json:"style,omitempty"`
}

Option is one button of an approval.

type Outgoing

type Outgoing struct {
	Text string `json:"text"`
}

Outgoing is a message kōjō posts. Text is Markdown; the adapter converts it to the surface's own syntax.

type Thread

type Thread struct {
	// Surface is the adapter's name: slack, teams, discord or mattermost.
	Surface string `json:"surface"`
	Channel string `json:"channel"`
	// ThreadID is the thread's root message (Slack: thread_ts). Empty means
	// a new top-level message.
	ThreadID string `json:"thread_id,omitempty"`
}

Thread is where a conversation lives.

Jump to

Keyboard shortcuts

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