autoreply

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package autoreply provides automatic response handling for messages.

Auto-reply allows configuring rules to automatically respond to messages without invoking the LLM, useful for:

  • FAQ responses
  • Out-of-office messages
  • Command shortcuts
  • Rate limiting responses

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conditions

type Conditions struct {
	// Patterns are regex patterns to match against the message.
	// If multiple patterns are specified, any match triggers the rule.
	Patterns []string `json:"patterns,omitempty" yaml:"patterns,omitempty"`

	// Keywords are exact words to match (case-insensitive).
	Keywords []string `json:"keywords,omitempty" yaml:"keywords,omitempty"`

	// Channels limits the rule to specific channel types.
	Channels []string `json:"channels,omitempty" yaml:"channels,omitempty"`

	// Senders limits the rule to specific sender IDs.
	Senders []string `json:"senders,omitempty" yaml:"senders,omitempty"`

	// TimeRange limits the rule to specific times.
	TimeRange *TimeRange `json:"time_range,omitempty" yaml:"time_range,omitempty"`
}

Conditions defines when a rule should trigger.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler evaluates messages against auto-reply rules.

func NewHandler

func NewHandler() *Handler

NewHandler creates a new auto-reply handler.

func (*Handler) AddRule

func (h *Handler) AddRule(rule *Rule) error

AddRule adds a rule to the handler.

func (*Handler) Evaluate

func (h *Handler) Evaluate(ctx context.Context, msg *Message) *Result

Evaluate checks a message against all rules and returns a result.

func (*Handler) GetRule

func (h *Handler) GetRule(id string) (*Rule, bool)

GetRule returns a rule by ID.

func (*Handler) ListRules

func (h *Handler) ListRules() []*Rule

ListRules returns all rules.

func (*Handler) RemoveRule

func (h *Handler) RemoveRule(id string) bool

RemoveRule removes a rule by ID.

type Message

type Message struct {
	// Content is the message text.
	Content string

	// SenderID is the sender identifier.
	SenderID string

	// Channel is the channel type (telegram, discord, etc.).
	Channel string

	// Timestamp is when the message was received.
	Timestamp time.Time

	// Metadata contains additional message data.
	Metadata map[string]any
}

Message represents an incoming message for auto-reply evaluation.

type RateLimit

type RateLimit struct {
	// MaxCount is the maximum triggers allowed in the window.
	MaxCount int `json:"max_count" yaml:"max_count"`

	// Window is the time window for rate limiting.
	Window time.Duration `json:"window" yaml:"window"`

	// PerSender applies rate limiting per sender (default: global).
	PerSender bool `json:"per_sender" yaml:"per_sender"`
}

RateLimit controls how often a rule can trigger.

type Response

type Response struct {
	// Text is the response message.
	Text string `json:"text" yaml:"text"`

	// Template is a Go template for dynamic responses.
	// Available variables: .Message, .Sender, .Channel, .Time
	Template string `json:"template,omitempty" yaml:"template,omitempty"`

	// StopProcessing prevents further rule evaluation if true.
	StopProcessing bool `json:"stop_processing" yaml:"stop_processing"`

	// PassThrough allows the message to continue to the LLM if true.
	PassThrough bool `json:"pass_through" yaml:"pass_through"`
}

Response defines what to send when a rule matches.

type Result

type Result struct {
	// Matched indicates if any rule matched.
	Matched bool

	// RuleID is the ID of the matched rule.
	RuleID string

	// Response is the response to send.
	Response string

	// StopProcessing indicates if processing should stop.
	StopProcessing bool

	// PassThrough indicates if the message should continue to LLM.
	PassThrough bool
}

Result represents the auto-reply evaluation result.

type Rule

type Rule struct {
	// ID is a unique identifier for the rule.
	ID string `json:"id" yaml:"id"`

	// Name is a human-readable name for the rule.
	Name string `json:"name" yaml:"name"`

	// Enabled controls whether the rule is active.
	Enabled bool `json:"enabled" yaml:"enabled"`

	// Priority determines rule evaluation order (lower = higher priority).
	Priority int `json:"priority" yaml:"priority"`

	// Conditions that must match for the rule to trigger.
	Conditions Conditions `json:"conditions" yaml:"conditions"`

	// Response to send when the rule matches.
	Response Response `json:"response" yaml:"response"`

	// RateLimit controls how often the rule can trigger.
	RateLimit *RateLimit `json:"rate_limit,omitempty" yaml:"rate_limit,omitempty"`
	// contains filtered or unexported fields
}

Rule defines an auto-reply rule.

type RuleError

type RuleError struct {
	RuleID string
	Err    error
}

RuleError represents an error with a specific rule.

func (*RuleError) Error

func (e *RuleError) Error() string

func (*RuleError) Unwrap

func (e *RuleError) Unwrap() error

type TimeRange

type TimeRange struct {
	// Start time in HH:MM format (24-hour).
	Start string `json:"start" yaml:"start"`

	// End time in HH:MM format (24-hour).
	End string `json:"end" yaml:"end"`

	// Days of the week (0=Sunday, 6=Saturday).
	// Empty means all days.
	Days []int `json:"days,omitempty" yaml:"days,omitempty"`

	// Timezone for time calculations (default: UTC).
	Timezone string `json:"timezone,omitempty" yaml:"timezone,omitempty"`
}

TimeRange defines a time window for rule activation.

Jump to

Keyboard shortcuts

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