chatapps

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueueFull = &QueueError{Message: "queue is full"}

Functions

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError classifies errors as retryable or non-retryable

func RetryWithBackoff

func RetryWithBackoff(ctx context.Context, config RetryConfig, fn func() error) error

Types

type AdapterManager

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

func NewAdapterManager

func NewAdapterManager(logger *slog.Logger) *AdapterManager

func (*AdapterManager) GetAdapter

func (m *AdapterManager) GetAdapter(platform string) (ChatAdapter, bool)

func (*AdapterManager) ListPlatforms

func (m *AdapterManager) ListPlatforms() []string

func (*AdapterManager) Register

func (m *AdapterManager) Register(adapter ChatAdapter) error

func (*AdapterManager) SendMessage

func (m *AdapterManager) SendMessage(ctx context.Context, platform, sessionID string, msg *ChatMessage) error

SendMessage sends a message to a specific platform

func (*AdapterManager) StartAll

func (m *AdapterManager) StartAll(ctx context.Context) error

func (*AdapterManager) StopAll

func (m *AdapterManager) StopAll() error

func (*AdapterManager) Unregister

func (m *AdapterManager) Unregister(platform string) error

type AdapterMetrics

type AdapterMetrics struct {
	MessagesReceived atomic.Int64
	MessagesSent     atomic.Int64
	MessagesFailed   atomic.Int64
	LastMessageAt    atomic.Int64
	Uptime           atomic.Int64
}

func NewAdapterMetrics

func NewAdapterMetrics() *AdapterMetrics

func (*AdapterMetrics) GetStats

func (m *AdapterMetrics) GetStats() map[string]int64

func (*AdapterMetrics) RecordFailure

func (m *AdapterMetrics) RecordFailure()

func (*AdapterMetrics) RecordReceive

func (m *AdapterMetrics) RecordReceive()

func (*AdapterMetrics) RecordSend

func (m *AdapterMetrics) RecordSend()

type Attachment

type Attachment struct {
	Type     string `json:"type"`                // image, file, audio
	URL      string `json:"url"`                 // URL to the content
	Title    string `json:"title"`               // Optional title
	Text     string `json:"text"`                // Optional description
	ThumbURL string `json:"thumb_url,omitempty"` // Thumbnail for images
}

Attachment represents rich content attachments

type ChatAdapter

type ChatAdapter interface {
	Platform() string
	SystemPrompt() string
	Start(ctx context.Context) error
	Stop() error
	SendMessage(ctx context.Context, sessionID string, msg *ChatMessage) error
	HandleMessage(ctx context.Context, msg *ChatMessage) error
}

type ChatMessage

type ChatMessage struct {
	Platform    string
	SessionID   string
	UserID      string
	Content     string
	MessageID   string
	Timestamp   time.Time
	Metadata    map[string]any
	RichContent *RichContent `json:"rich_content,omitempty"` // Optional rich content
}

type ConfigLoader

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

func NewConfigLoader

func NewConfigLoader(configDir string, logger Logger) (*ConfigLoader, error)

func (*ConfigLoader) GetConfig

func (c *ConfigLoader) GetConfig(platform string) *PlatformConfig

func (*ConfigLoader) GetSystemPrompt

func (c *ConfigLoader) GetSystemPrompt(platform string) string

func (*ConfigLoader) GetTaskInstructions

func (c *ConfigLoader) GetTaskInstructions(platform string) string

func (*ConfigLoader) GetWhatsAppConfig

func (c *ConfigLoader) GetWhatsAppConfig(platform string) *WhatsAppAdapterConfig

GetWhatsAppConfig returns the WhatsApp-specific configuration for a platform

func (*ConfigLoader) HasPlatform

func (c *ConfigLoader) HasPlatform(platform string) bool

func (*ConfigLoader) Load

func (c *ConfigLoader) Load(configDir string) error

func (*ConfigLoader) Platforms

func (c *ConfigLoader) Platforms() []string

type DingTalkAdapter

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

func NewDingTalkAdapter

func NewDingTalkAdapter(config DingTalkConfig, logger *slog.Logger) *DingTalkAdapter

func (*DingTalkAdapter) HandleMessage

func (a *DingTalkAdapter) HandleMessage(ctx context.Context, msg *ChatMessage) error

func (*DingTalkAdapter) Platform

func (a *DingTalkAdapter) Platform() string

func (*DingTalkAdapter) SendMessage

func (a *DingTalkAdapter) SendMessage(ctx context.Context, sessionID string, msg *ChatMessage) error

func (*DingTalkAdapter) SetHandler

func (a *DingTalkAdapter) SetHandler(handler MessageHandler)

func (*DingTalkAdapter) Start

func (a *DingTalkAdapter) Start(ctx context.Context) error

func (*DingTalkAdapter) Stop

func (a *DingTalkAdapter) Stop() error

func (*DingTalkAdapter) SystemPrompt

func (a *DingTalkAdapter) SystemPrompt() string

SystemPrompt Returns system prompt

type DingTalkCallbackRequest

type DingTalkCallbackRequest struct {
	MsgType        string `json:"msgtype"`
	ConversationID string `json:"conversationId"`
	SenderID       string `json:"senderId"`
	SenderNick     string `json:"senderNick"`
	IsAdmin        bool   `json:"isAdmin"`
	RobotCode      string `json:"robotCode"`
	Text           struct {
		Content string `json:"content"`
	} `json:"text"`
	EventType string `json:"eventType"`
}

type DingTalkCallbackResponse

type DingTalkCallbackResponse struct {
	MsgType string `json:"msgtype"`
	Text    struct {
		Content string `json:"content"`
	} `json:"text"`
}

type DingTalkConfig

type DingTalkConfig struct {
	AppID         string
	AppSecret     string
	CallbackURL   string
	CallbackToken string
	CallbackKey   string
	ServerAddr    string
	MaxMessageLen int // Maximum message length (default 5000 for DingTalk)
	SystemPrompt  string
}

type DingTalkSession

type DingTalkSession struct {
	SessionID  string
	UserID     string
	Platform   string
	LastActive time.Time
}

type DiscordAdapter

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

DiscordAdapter Discord Bot Adapter

func NewDiscordAdapter

func NewDiscordAdapter(config DiscordConfig, logger *slog.Logger) *DiscordAdapter

NewDiscordAdapter Create new Discord adapter

func (*DiscordAdapter) HandleMessage

func (a *DiscordAdapter) HandleMessage(ctx context.Context, msg *ChatMessage) error

HandleMessage Handle incoming message

func (*DiscordAdapter) Platform

func (a *DiscordAdapter) Platform() string

Platform Returns platform name

func (*DiscordAdapter) SendEmbedMessage

func (a *DiscordAdapter) SendEmbedMessage(ctx context.Context, sessionID, channelID string, embeds []DiscordEmbed) error

SendEmbedMessage sends a message with embeds to Discord channel

func (*DiscordAdapter) SendMessage

func (a *DiscordAdapter) SendMessage(ctx context.Context, sessionID string, msg *ChatMessage) error

SendMessage Send message to Discord channel

func (*DiscordAdapter) SetHandler

func (a *DiscordAdapter) SetHandler(handler MessageHandler)

SetHandler Set message handler

func (*DiscordAdapter) Start

func (a *DiscordAdapter) Start(ctx context.Context) error

Start Start Discord adapter

func (*DiscordAdapter) Stop

func (a *DiscordAdapter) Stop() error

Stop Stop Discord adapter

func (*DiscordAdapter) SystemPrompt

func (a *DiscordAdapter) SystemPrompt() string

SystemPrompt Returns system prompt

type DiscordConfig

type DiscordConfig struct {
	BotToken     string // Discord Bot Token
	ServerAddr   string
	PublicKey    string // For interaction verification
	SystemPrompt string // Custom system prompt for the AI agent
}

DiscordConfig Discord Bot Configuration

type DiscordEmbed

type DiscordEmbed struct {
	Title       string                 `json:"title,omitempty"`
	Description string                 `json:"description,omitempty"`
	URL         string                 `json:"url,omitempty"`
	Color       int                    `json:"color,omitempty"`
	Fields      []DiscordEmbedField    `json:"fields,omitempty"`
	Footer      *DiscordEmbedFooter    `json:"footer,omitempty"`
	Thumbnail   *DiscordEmbedThumbnail `json:"thumbnail,omitempty"`
	Image       *DiscordEmbedImage     `json:"image,omitempty"`
	Timestamp   string                 `json:"timestamp,omitempty"`
}

DiscordEmbed represents a Discord embed

type DiscordEmbedField

type DiscordEmbedField struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

type DiscordEmbedFooter

type DiscordEmbedFooter struct {
	Text    string `json:"text"`
	IconURL string `json:"icon_url,omitempty"`
}

type DiscordEmbedImage

type DiscordEmbedImage struct {
	URL string `json:"url"`
}

type DiscordEmbedThumbnail

type DiscordEmbedThumbnail struct {
	URL string `json:"url"`
}

type DiscordGuildMember

type DiscordGuildMember struct {
	User struct {
		ID       string `json:"id"`
		Username string `json:"username"`
		Bot      bool   `json:"bot"`
	} `json:"user"`
	Nick     string   `json:"nick"`
	Roles    []string `json:"roles"`
	JoinedAt string   `json:"joined_at"`
}

DiscordGuildMember Guild member info

type DiscordInteraction

type DiscordInteraction struct {
	Type    int             `json:"type"`
	Data    json.RawMessage `json:"data"`
	GuildID string          `json:"guild_id"`
	Channel string          `json:"channel_id"`
	Member  struct {
		User struct {
			ID       string `json:"id"`
			Username string `json:"username"`
		} `json:"user"`
	} `json:"member"`
	Message json.RawMessage `json:"message"`
}

DiscordInteraction Discord interaction payload

type DiscordMessage

type DiscordMessage struct {
	Content string `json:"content"`
}

DiscordMessage Discord message structure

type DiscordMessageResponse

type DiscordMessageResponse struct {
	ID        string `json:"id"`
	ChannelID string `json:"channel_id"`
	Content   string `json:"content"`
	Timestamp string `json:"timestamp"`
}

DiscordMessageResponse Response from Discord API

type DiscordSession

type DiscordSession struct {
	SessionID  string
	UserID     string
	ChannelID  string
	GuildID    string
	Platform   string
	LastActive time.Time
}

DiscordSession Session for Discord user

type EngineHolder

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

EngineHolder holds the Engine instance and configuration for ChatApps integration

func NewEngineHolder

func NewEngineHolder(opts EngineHolderOptions) (*EngineHolder, error)

NewEngineHolder creates a new EngineHolder with the given options

func (*EngineHolder) GetAdapterManager

func (h *EngineHolder) GetAdapterManager() *AdapterManager

GetAdapterManager returns the AdapterManager for sending messages

func (*EngineHolder) GetEngine

func (h *EngineHolder) GetEngine() *engine.Engine

GetEngine returns the underlying Engine instance

type EngineHolderOptions

type EngineHolderOptions struct {
	Logger           *slog.Logger
	Adapters         *AdapterManager
	Timeout          time.Duration
	IdleTimeout      time.Duration
	Namespace        string
	PermissionMode   string
	AllowedTools     []string
	DisallowedTools  []string
	DefaultWorkDir   string
	DefaultTaskInstr string
}

EngineHolderOptions configures the EngineHolder

type EngineMessageHandler

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

EngineMessageHandler implements MessageHandler and integrates with Engine

func NewEngineMessageHandler

func NewEngineMessageHandler(engine *engine.Engine, adapters *AdapterManager, opts ...EngineMessageHandlerOption) *EngineMessageHandler

NewEngineMessageHandler creates a new EngineMessageHandler

func (*EngineMessageHandler) Handle

func (h *EngineMessageHandler) Handle(ctx context.Context, msg *ChatMessage) error

Handle implements MessageHandler

type EngineMessageHandlerOption

type EngineMessageHandlerOption func(*EngineMessageHandler)

EngineMessageHandlerOption configures the EngineMessageHandler

func WithConfigLoader

func WithConfigLoader(loader *ConfigLoader) EngineMessageHandlerOption

func WithLogger

func WithLogger(logger *slog.Logger) EngineMessageHandlerOption

func WithTaskInstrFn

func WithTaskInstrFn(fn func(sessionID string) string) EngineMessageHandlerOption

func WithWorkDirFn

func WithWorkDirFn(fn func(sessionID string) string) EngineMessageHandlerOption

type HealthCheck

type HealthCheck struct {
	Name      string
	Status    string
	LastCheck time.Time
	LastError string
	Interval  time.Duration
	CheckFunc func() error
}

type HealthChecker

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

func NewHealthChecker

func NewHealthChecker(interval time.Duration) *HealthChecker

func (*HealthChecker) GetStatus

func (h *HealthChecker) GetStatus() map[string]HealthCheck

func (*HealthChecker) Register

func (h *HealthChecker) Register(check HealthCheck)

func (*HealthChecker) Start

func (h *HealthChecker) Start()

func (*HealthChecker) Stop

func (h *HealthChecker) Stop()

type InlineKeyboardButton

type InlineKeyboardButton struct {
	Text         string `json:"text"`
	URL          string `json:"url,omitempty"`
	CallbackData string `json:"callback_data,omitempty"`
}

InlineKeyboardButton represents a button in inline keyboard

type InlineKeyboardMarkup

type InlineKeyboardMarkup struct {
	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
}

InlineKeyboard represents inline keyboard markup

type LifecycleManager

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

func NewLifecycleManager

func NewLifecycleManager() *LifecycleManager

func (*LifecycleManager) OnStart

func (m *LifecycleManager) OnStart(hook func(ChatAdapter) error)

func (*LifecycleManager) OnStop

func (m *LifecycleManager) OnStop(hook func(ChatAdapter) error)

func (*LifecycleManager) RegisterAdapter

func (m *LifecycleManager) RegisterAdapter(adapter ChatAdapter, startPriority int)

func (*LifecycleManager) StartAll

func (m *LifecycleManager) StartAll(ctx context.Context) error

func (*LifecycleManager) StopAll

func (m *LifecycleManager) StopAll() error

type Logger

type Logger interface {
	Info(msg string, args ...any)
	Debug(msg string, args ...any)
	Error(msg string, args ...any)
	Warn(msg string, args ...any)
}

type MessageHandler

type MessageHandler func(ctx context.Context, msg *ChatMessage) error

type MessageQueue

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

func NewMessageQueue

func NewMessageQueue(logger *slog.Logger, maxSize, dlqSize, workers int) *MessageQueue

func (*MessageQueue) AddToDLQ

func (q *MessageQueue) AddToDLQ(msg *QueuedMessage)

AddToDLQ stores a failed message to the Dead Letter Queue

func (*MessageQueue) DLQLen

func (q *MessageQueue) DLQLen() int

DLQLen returns the number of messages in the Dead Letter Queue

func (*MessageQueue) Dequeue

func (q *MessageQueue) Dequeue() (*QueuedMessage, bool)

func (*MessageQueue) Enqueue

func (q *MessageQueue) Enqueue(platform, sessionID string, msg *ChatMessage) error

func (*MessageQueue) GetDLQ

func (q *MessageQueue) GetDLQ() []*QueuedMessage

GetDLQ returns all messages in the Dead Letter Queue

func (*MessageQueue) Requeue

func (q *MessageQueue) Requeue(msg *QueuedMessage) error

Requeue adds a message back to the queue for retry

func (*MessageQueue) Size

func (q *MessageQueue) Size() int

func (*MessageQueue) Start

func (q *MessageQueue) Start(adapterGetter func(string) (ChatAdapter, bool), sendFn func(context.Context, string, string, *ChatMessage) error)

func (*MessageQueue) Stop

func (q *MessageQueue) Stop()

type ParseMode

type ParseMode string

ParseMode defines message formatting mode

const (
	ParseModeNone     ParseMode = ""
	ParseModeMarkdown ParseMode = "markdown" // Telegram: Markdown, Slack: mrkdwn
	ParseModeHTML     ParseMode = "html"     // Telegram: HTML
)

type PlatformConfig

type PlatformConfig struct {
	Platform         string `yaml:"platform"`
	SystemPrompt     string `yaml:"system_prompt"`
	TaskInstructions string `yaml:"task_instructions"`

	// WhatsApp specific (optional)
	WhatsApp *WhatsAppAdapterConfig `yaml:"whatsapp,omitempty"`
}

type QueueError

type QueueError struct {
	Message string
}

func (*QueueError) Error

func (e *QueueError) Error() string

type QueuedMessage

type QueuedMessage struct {
	Platform  string
	SessionID string
	Message   *ChatMessage
	Retries   int
	CreatedAt time.Time
}

type RateLimiter

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

func NewRateLimiter

func NewRateLimiter(maxTokens float64, refillRate float64) *RateLimiter

func (*RateLimiter) Allow

func (r *RateLimiter) Allow() bool

func (*RateLimiter) Wait

func (r *RateLimiter) Wait(ctx context.Context) error

type RetryConfig

type RetryConfig struct {
	MaxAttempts int
	BaseDelay   time.Duration
	MaxDelay    time.Duration
}

type RichContent

type RichContent struct {
	// Formatting
	ParseMode ParseMode `json:"parse_mode,omitempty"`

	// Telegram specific
	InlineKeyboard *InlineKeyboardMarkup `json:"inline_keyboard,omitempty"`

	// Slack specific
	Blocks []SlackBlock `json:"blocks,omitempty"`

	// Discord specific
	Embeds []DiscordEmbed `json:"embeds,omitempty"`

	// Common attachments
	Attachments []Attachment `json:"attachments,omitempty"`
}

RichContent holds rich message content for advanced platforms

type SlackAdapter

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

SlackAdapter Slack Bot Adapter

func NewSlackAdapter

func NewSlackAdapter(config SlackConfig, logger *slog.Logger) *SlackAdapter

NewSlackAdapter Create new Slack adapter

func (*SlackAdapter) HandleMessage

func (a *SlackAdapter) HandleMessage(ctx context.Context, msg *ChatMessage) error

HandleMessage Handle incoming message

func (*SlackAdapter) Platform

func (a *SlackAdapter) Platform() string

Platform Returns platform name

func (*SlackAdapter) SendBlockMessage

func (a *SlackAdapter) SendBlockMessage(ctx context.Context, sessionID, channelID string, blocks []SlackBlock, text string) error

SendBlockMessage sends a message with Block Kit blocks

func (*SlackAdapter) SendMessage

func (a *SlackAdapter) SendMessage(ctx context.Context, sessionID string, msg *ChatMessage) error

SendMessage Send message to Slack channel/user

func (*SlackAdapter) SetHandler

func (a *SlackAdapter) SetHandler(handler MessageHandler)

SetHandler Set message handler

func (*SlackAdapter) Start

func (a *SlackAdapter) Start(ctx context.Context) error

Start Start Slack adapter

func (*SlackAdapter) Stop

func (a *SlackAdapter) Stop() error

Stop Stop Slack adapter

func (*SlackAdapter) SystemPrompt

func (a *SlackAdapter) SystemPrompt() string

SystemPrompt Returns system prompt

type SlackBlock

type SlackBlock map[string]any

SlackBlock represents a Slack Block Kit block

type SlackConfig

type SlackConfig struct {
	BotToken      string // xoxb- token
	AppToken      string // xapp- token for Socket Mode
	SigningSecret string
	ServerAddr    string
	SystemPrompt  string
}

SlackConfig Slack Bot Configuration

type SlackEvent

type SlackEvent struct {
	Token     string          `json:"token"`
	TeamID    string          `json:"team_id"`
	APIAppID  string          `json:"api_app_id"`
	Type      string          `json:"type"`
	EventID   string          `json:"event_id"`
	EventTime int64           `json:"event_time"`
	Event     json.RawMessage `json:"event"`
	Challenge string          `json:"challenge"`
}

SlackEvent Slack Event API payload

type SlackEventResponse

type SlackEventResponse struct {
	Challenge string `json:"challenge"`
}

SlackEventResponse Response to Slack URL verification

type SlackInteractivePayload

type SlackInteractivePayload struct {
	Type           string          `json:"type"`
	Challenge      string          `json:"challenge,omitempty"`
	Token          string          `json:"token"`
	TeamID         string          `json:"team_id"`
	TeamDomain     string          `json:"team_domain"`
	EnterpriseID   string          `json:"enterprise_id,omitempty"`
	EnterpriseName string          `json:"enterprise_name,omitempty"`
	ChannelID      string          `json:"channel_id"`
	ChannelName    string          `json:"channel_name"`
	UserID         string          `json:"user_id"`
	UserName       string          `json:"user_name"`
	Command        string          `json:"command,omitempty"`
	Text           string          `json:"text"`
	ResponseURL    string          `json:"response_url"`
	TriggerID      string          `json:"trigger_id"`
	View           json.RawMessage `json:"view,omitempty"`
}

SlackInteractivePayload Interactive payload from Slack

type SlackMessageEvent

type SlackMessageEvent struct {
	Type        string `json:"type"`
	Channel     string `json:"channel"`
	ChannelType string `json:"channel_type"`
	User        string `json:"user"`
	Text        string `json:"text"`
	TS          string `json:"ts"`
	EventTS     string `json:"event_ts"`
	BotID       string `json:"bot_id,omitempty"`
	SubType     string `json:"subtype,omitempty"`
}

SlackMessageEvent Message event from Slack

type SlackSession

type SlackSession struct {
	SessionID  string
	UserID     string
	ChannelID  string
	Platform   string
	LastActive time.Time
}

SlackSession Session for Slack user

type StreamAdapter

type StreamAdapter interface {
	ChatAdapter
	// SendStreamMessage sends a message and returns a stream handler for updates
	SendStreamMessage(ctx context.Context, sessionID string, msg *ChatMessage) (StreamHandler, error)
	// UpdateMessage updates an existing message (for edit support)
	UpdateMessage(ctx context.Context, sessionID, messageID string, msg *ChatMessage) error
}

StreamAdapter extends ChatAdapter for streaming message support

type StreamCallback

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

StreamCallback implements event.Callback to receive Engine events and forward to ChatApp

func NewStreamCallback

func NewStreamCallback(ctx context.Context, sessionID, platform string, adapters *AdapterManager, logger *slog.Logger) *StreamCallback

NewStreamCallback creates a new StreamCallback

func (*StreamCallback) Handle

func (c *StreamCallback) Handle(eventType string, data any) error

Handle implements event.Callback

type StreamHandler

type StreamHandler func(ctx context.Context, sessionID string, chunk string, isFinal bool) error

StreamHandler handles streaming message responses

type TelegramAdapter

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

TelegramAdapter Telegram Bot Adapter

func NewTelegramAdapter

func NewTelegramAdapter(config TelegramConfig, logger *slog.Logger) *TelegramAdapter

NewTelegramAdapter Create new Telegram adapter

func (*TelegramAdapter) HandleMessage

func (a *TelegramAdapter) HandleMessage(ctx context.Context, msg *ChatMessage) error

HandleMessage Handle incoming message (not used for webhook mode)

func (*TelegramAdapter) Platform

func (a *TelegramAdapter) Platform() string

Platform Returns platform name

func (*TelegramAdapter) SendMessage

func (a *TelegramAdapter) SendMessage(ctx context.Context, sessionID string, msg *ChatMessage) error

SendMessage Send message to Telegram user

func (*TelegramAdapter) SetHandler

func (a *TelegramAdapter) SetHandler(handler MessageHandler)

SetHandler Set message handler

func (*TelegramAdapter) Start

func (a *TelegramAdapter) Start(ctx context.Context) error

Start Start Telegram adapter

func (*TelegramAdapter) Stop

func (a *TelegramAdapter) Stop() error

Stop Stop Telegram adapter

func (*TelegramAdapter) SystemPrompt

func (a *TelegramAdapter) SystemPrompt() string

type TelegramConfig

type TelegramConfig struct {
	BotToken     string // Bot Token from @BotFather
	WebhookURL   string // Public URL for webhook
	ServerAddr   string // Local server address
	SecretToken  string // Secret token for webhook verification (required for security)
	SystemPrompt string // Custom system prompt for the AI agent
}

TelegramConfig Telegram Bot Configuration

type TelegramMessageResponse

type TelegramMessageResponse struct {
	OK     bool         `json:"ok"`
	Result *TelegramMsg `json:"result"`
}

TelegramMessageResponse Telegram API response for sending messages

type TelegramMsg

type TelegramMsg struct {
	MessageID int64 `json:"message_id"`
	Chat      struct {
		ID int64 `json:"id"`
	} `json:"chat"`
	Date int64  `json:"date"`
	Text string `json:"text"`
}

TelegramMsg represents sent message

type TelegramSession

type TelegramSession struct {
	SessionID  string
	UserID     string
	ChatID     int64
	Platform   string
	LastActive time.Time
}

TelegramSession Session for Telegram user

type TelegramUpdate

type TelegramUpdate struct {
	UpdateID int64 `json:"update_id"`
	Message  struct {
		MessageID int64 `json:"message_id"`
		From      struct {
			ID        int64  `json:"id"`
			FirstName string `json:"first_name"`
			LastName  string `json:"last_name"`
			Username  string `json:"username"`
		} `json:"from"`
		Chat struct {
			ID    int64  `json:"id"`
			Type  string `json:"type"`
			Title string `json:"title,omitempty"`
		} `json:"chat"`
		Date     int64  `json:"date"`
		Text     string `json:"text"`
		Entities []struct {
			Type   string `json:"type"`
			Offset int    `json:"offset"`
			Length int    `json:"length"`
		} `json:"entities,omitempty"`
	} `json:"message"`
	CallbackQuery *struct {
		ID   string `json:"id"`
		From struct {
			ID        int64  `json:"id"`
			FirstName string `json:"first_name"`
			LastName  string `json:"last_name"`
			Username  string `json:"username"`
		} `json:"from"`
		Message struct {
			Chat struct {
				ID int64 `json:"id"`
			} `json:"chat"`
			MessageID int64  `json:"message_id"`
			Data      string `json:"data"`
		} `json:"message,omitempty"`
	} `json:"callback_query,omitempty"`
}

TelegramUpdate represents incoming Telegram update

type TelegramWebhookResponse

type TelegramWebhookResponse struct {
	OK          bool   `json:"ok"`
	Description string `json:"description"`
}

TelegramWebhookResponse Response for Telegram webhook verification

type WhatsAppAdapter

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

func NewWhatsAppAdapter

func NewWhatsAppAdapter(config WhatsAppConfig, logger *slog.Logger) *WhatsAppAdapter

func (*WhatsAppAdapter) HandleMessage

func (a *WhatsAppAdapter) HandleMessage(ctx context.Context, msg *ChatMessage) error

func (*WhatsAppAdapter) Platform

func (a *WhatsAppAdapter) Platform() string

func (*WhatsAppAdapter) SendMessage

func (a *WhatsAppAdapter) SendMessage(ctx context.Context, sessionID string, msg *ChatMessage) error

func (*WhatsAppAdapter) SetHandler

func (a *WhatsAppAdapter) SetHandler(handler MessageHandler)

func (*WhatsAppAdapter) Start

func (a *WhatsAppAdapter) Start(ctx context.Context) error

func (*WhatsAppAdapter) Stop

func (a *WhatsAppAdapter) Stop() error

func (*WhatsAppAdapter) SystemPrompt

func (a *WhatsAppAdapter) SystemPrompt() string

SystemPrompt Returns system prompt

type WhatsAppAdapterConfig

type WhatsAppAdapterConfig struct {
	PhoneNumberID string `yaml:"phone_number_id"`
	AccessToken   string `yaml:"access_token"`
	VerifyToken   string `yaml:"verify_token"`
	ServerAddr    string `yaml:"server_addr"`
	APIVersion    string `yaml:"api_version"`
}

WhatsAppAdapterConfig holds WhatsApp-specific configuration

type WhatsAppConfig

type WhatsAppConfig struct {
	PhoneNumberID string
	AccessToken   string
	VerifyToken   string
	ServerAddr    string
	APIVersion    string
	SystemPrompt  string
}

type WhatsAppIncomingMessage

type WhatsAppIncomingMessage struct {
	Object string `json:"object"`
	Entry  []struct {
		ID      string `json:"id"`
		Changes []struct {
			Value struct {
				MessagingProduct string `json:"messaging_product"`
				Metadata         struct {
					DisplayPhoneNumber string `json:"display_phone_number"`
					PhoneNumberID      string `json:"phone_number_id"`
				} `json:"metadata"`
				Messages []struct {
					From string `json:"from"`
					ID   string `json:"id"`
					Text struct {
						Body string `json:"body"`
					} `json:"text"`
					Type string `json:"type"`
				} `json:"messages"`
			} `json:"value"`
		} `json:"changes"`
	} `json:"entry"`
}

type WhatsAppResponse

type WhatsAppResponse struct {
	MessagingProduct string            `json:"messaging_product"`
	To               string            `json:"to"`
	Type             string            `json:"type"`
	Text             *WhatsAppTextBody `json:"text,omitempty"`
}

type WhatsAppSession

type WhatsAppSession struct {
	SessionID  string
	UserID     string
	Platform   string
	LastActive time.Time
}

type WhatsAppTextBody

type WhatsAppTextBody struct {
	Body string `json:"body"`
}

Jump to

Keyboard shortcuts

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