interaction

package
v0.4.35 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package interaction defines portable external card interactions. Permission replies use cap/permission exclusively and never enter this handler chain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseCard added in v0.4.28

func CloseCard(ctx context.Context, text string) error

func WithCardResponder added in v0.4.28

func WithCardResponder(ctx context.Context, r CardResponder) context.Context

Types

type Answer

type Answer struct {
	Control string `json:"control,omitempty"`
	Value   any    `json:"value"`
	Label   string `json:"label,omitempty"`
}

Answer retains the original value even when a display label can be resolved. Control is the card control name/action_id (or form field name).

type CardResponder added in v0.4.28

type CardResponder interface {
	CloseCard(context.Context, string) error
}

CardResponder lets a consuming plugin close its source card without importing a platform SDK. Closing changes presentation only; plugin state stays owned by that plugin. An empty text uses the normalized question and submitted answers.

type CardStatus

type CardStatus string
const (
	CardAvailable   CardStatus = "available"
	CardUnavailable CardStatus = "unavailable"
	CardFailed      CardStatus = "failed"
)

type Event

type Event struct {
	Purpose        Purpose         `json:"purpose,omitempty"`
	SubmissionMode SubmissionMode  `json:"submission_mode,omitempty"`
	EventID        string          `json:"event_id,omitempty"`
	InteractionID  string          `json:"interaction_id,omitempty"`
	RoutingStatus  string          `json:"routing_status,omitempty"`
	Platform       string          `json:"platform"`
	Type           string          `json:"type"`
	UserID         string          `json:"user_id"`
	ChatID         string          `json:"chat_id"`
	MessageID      string          `json:"message_id"`
	ThreadID       string          `json:"thread_id,omitempty"`
	SessionID      string          `json:"session_id"`
	Action         string          `json:"action,omitempty"`
	Answers        []Answer        `json:"answers,omitempty"`
	CardStatus     CardStatus      `json:"card_status"`
	CardError      string          `json:"card_error,omitempty"`
	CardText       string          `json:"card_text,omitempty"`
	RawCard        json.RawMessage `json:"raw_card,omitempty"`
	RawAction      json.RawMessage `json:"raw_action,omitempty"`
	RawCallback    json.RawMessage `json:"raw_callback,omitempty"`
}

Event is a snapshot owned by one asynchronous interaction worker. RawCallback and RawCard retain details not represented by the portable fields.

type Handler

type Handler interface {
	HandleInteraction(context.Context, Event) (handled bool, err error)
}

Handler is injected through platform deps.interactionHandlers. Handlers run in declaration order after builtins. Return true only when consumed. Errors are logged and the chain continues; a failed handler cannot suppress fallback. A consumed event is never automatically locked/closed by the platform. Use CloseCard(ctx, text) to opt into closing; the plugin owns repeated-click state. Implementations must support concurrent calls and honor ctx cancellation.

type Purpose added in v0.4.28

type Purpose string
const (
	PurposeSubmit   Purpose = "submit"
	PurposeChange   Purpose = "change"
	PurposeNavigate Purpose = "navigation"
)

type SubmissionMode added in v0.4.28

type SubmissionMode string
const (
	SubmissionOnce    SubmissionMode = "once"
	SubmissionPerUser SubmissionMode = "per_user"
	SubmissionRepeat  SubmissionMode = "repeat"
)

Jump to

Keyboard shortcuts

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