message

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetRef

type AssetRef struct {
	ContentHash string `json:"content_hash"`
	Role        string `json:"role"`
	Ordinal     int    `json:"ordinal"`
	Mime        string `json:"mime,omitempty"`
	SizeBytes   int64  `json:"size_bytes,omitempty"`
	StorageKey  string `json:"storage_key,omitempty"`
}

AssetRef links a media asset to a persisted message. ContentHash is the content-addressed identifier for the media file.

type DBService

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

DBService persists and reads bot history messages.

func NewService

func NewService(log *slog.Logger, queries *sqlc.Queries, publishers ...event.Publisher) *DBService

NewService creates a message service.

func (*DBService) DeleteByBot

func (s *DBService) DeleteByBot(ctx context.Context, botID string) error

DeleteByBot deletes all messages for a bot.

func (*DBService) List

func (s *DBService) List(ctx context.Context, botID string) ([]Message, error)

List returns all messages for a bot.

func (*DBService) ListActiveSince

func (s *DBService) ListActiveSince(ctx context.Context, botID string, since time.Time) ([]Message, error)

ListActiveSince returns bot messages since a given time, excluding passive_sync messages.

func (*DBService) ListBefore

func (s *DBService) ListBefore(ctx context.Context, botID string, before time.Time, limit int32) ([]Message, error)

ListBefore returns up to limit messages older than before (created_at < before), ordered oldest-first.

func (*DBService) ListLatest

func (s *DBService) ListLatest(ctx context.Context, botID string, limit int32) ([]Message, error)

ListLatest returns the latest N bot messages (newest first in DB; caller may reverse for ASC).

func (*DBService) ListSince

func (s *DBService) ListSince(ctx context.Context, botID string, since time.Time) ([]Message, error)

ListSince returns bot messages since a given time.

func (*DBService) Persist

func (s *DBService) Persist(ctx context.Context, input PersistInput) (Message, error)

Persist writes a single message to bot_history_messages.

type Message

type Message struct {
	ID                      string          `json:"id"`
	BotID                   string          `json:"bot_id"`
	RouteID                 string          `json:"route_id,omitempty"`
	SenderChannelIdentityID string          `json:"sender_channel_identity_id,omitempty"`
	SenderUserID            string          `json:"sender_user_id,omitempty"`
	SenderDisplayName       string          `json:"sender_display_name,omitempty"`
	SenderAvatarURL         string          `json:"sender_avatar_url,omitempty"`
	Platform                string          `json:"platform,omitempty"`
	ExternalMessageID       string          `json:"external_message_id,omitempty"`
	SourceReplyToMessageID  string          `json:"source_reply_to_message_id,omitempty"`
	Role                    string          `json:"role"`
	Content                 json.RawMessage `json:"content"`
	Metadata                map[string]any  `json:"metadata,omitempty"`
	Usage                   json.RawMessage `json:"usage,omitempty"`
	Assets                  []MessageAsset  `json:"assets,omitempty"`
	CreatedAt               time.Time       `json:"created_at"`
}

Message represents a single persisted bot message.

type MessageAsset

type MessageAsset struct {
	ContentHash string `json:"content_hash"`
	Role        string `json:"role"`
	Ordinal     int    `json:"ordinal"`
	Mime        string `json:"mime"`
	SizeBytes   int64  `json:"size_bytes"`
	StorageKey  string `json:"storage_key"`
}

MessageAsset carries media asset metadata attached to a message. ContentHash is the content-addressed identifier for the media file.

type PersistInput

type PersistInput struct {
	BotID                   string
	RouteID                 string
	SenderChannelIdentityID string
	SenderUserID            string
	Platform                string
	ExternalMessageID       string
	SourceReplyToMessageID  string
	Role                    string
	Content                 json.RawMessage
	Metadata                map[string]any
	Usage                   json.RawMessage
	Assets                  []AssetRef
}

PersistInput is the input for persisting a message.

type Service

type Service interface {
	Writer
	List(ctx context.Context, botID string) ([]Message, error)
	ListSince(ctx context.Context, botID string, since time.Time) ([]Message, error)
	ListActiveSince(ctx context.Context, botID string, since time.Time) ([]Message, error)
	ListLatest(ctx context.Context, botID string, limit int32) ([]Message, error)
	ListBefore(ctx context.Context, botID string, before time.Time, limit int32) ([]Message, error)
	DeleteByBot(ctx context.Context, botID string) error
}

Service defines message read/write behavior.

type Writer

type Writer interface {
	Persist(ctx context.Context, input PersistInput) (Message, error)
}

Writer defines write behavior needed by the inbound router.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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