imbot

package
v0.260430.0-rc Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package imbotsettings provides handlers for ImBot settings management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(router *swagger.RouteGroup, handler *Handler)

RegisterRoutes registers all ImBot settings routes with swagger documentation

Types

type BotManager

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

BotManager manages the lifecycle of ImBot instances. It encapsulates the internal bot.Manager and provides a clean interface for the imbotsettings module to control bot lifecycle.

func NewBotManager

func NewBotManager(ctx context.Context, cfg *config.Config) (*BotManager, error)

NewBotManager creates a new BotManager with all required dependencies.

func (*BotManager) GetStatus

func (bm *BotManager) GetStatus() []BotStatus

GetStatus returns the status of all configured bots.

func (*BotManager) GetStore

func (bm *BotManager) GetStore() *db.ImBotSettingsStore

GetStore returns the underlying settings store.

func (*BotManager) GetTBClient

func (bm *BotManager) GetTBClient() tbclient.TBClient

GetTBClient returns the TBClient for SmartGuide model configuration.

func (*BotManager) IsRunning

func (bm *BotManager) IsRunning(uuid string) bool

IsRunning checks if a bot is currently running.

func (*BotManager) Shutdown

func (bm *BotManager) Shutdown()

Shutdown stops all running bots and cleans up resources.

func (*BotManager) StartAllEnabled

func (bm *BotManager) StartAllEnabled(ctx context.Context) error

StartAllEnabled starts all bots that have enabled: true in their settings. Logs errors for individual bots but continues starting others.

func (*BotManager) StartBot

func (bm *BotManager) StartBot(ctx context.Context, uuid string) error

StartBot starts a single bot by UUID. If the bot is already running, this is a no-op.

func (*BotManager) StopAll

func (bm *BotManager) StopAll()

StopAll stops all running bots.

func (*BotManager) StopBot

func (bm *BotManager) StopBot(uuid string) error

StopBot stops a single bot by UUID. If the bot is not running, this is a no-op. Waits up to 5 seconds for the bot to fully stop before returning.

func (*BotManager) Sync

func (bm *BotManager) Sync(ctx context.Context) error

Sync ensures that running bots match the enabled settings. Starts bots that are enabled but not running, and stops bots that are running but disabled.

type BotStatus

type BotStatus struct {
	UUID     string `json:"uuid"`
	Name     string `json:"name"`
	Platform string `json:"platform"`
	Running  bool   `json:"running"`
	Error    string `json:"error,omitempty"`
}

BotStatus represents the runtime status of a bot.

type CreateRequest

type CreateRequest struct {
	UUID               string            `json:"uuid,omitempty"`
	Name               string            `json:"name,omitempty"`
	Platform           string            `json:"platform"`
	AuthType           string            `json:"auth_type"`
	Auth               map[string]string `json:"auth"`
	ProxyURL           string            `json:"proxy_url,omitempty"`
	ChatID             string            `json:"chat_id,omitempty"`
	BashAllowlist      []string          `json:"bash_allowlist,omitempty"`
	DefaultCwd         string            `json:"default_cwd,omitempty"`   // Default working directory
	DefaultAgent       string            `json:"default_agent,omitempty"` // Default Agent UUID
	Enabled            bool              `json:"enabled"`
	Token              string            `json:"token,omitempty"`               // Legacy field
	SmartGuideProvider string            `json:"smartguide_provider,omitempty"` // Provider UUID
	SmartGuideModel    string            `json:"smartguide_model,omitempty"`    // Model identifier
}

CreateRequest represents the request to create ImBot settings

type DeleteResponse

type DeleteResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

DeleteResponse represents the response for delete operations

type Handler

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

Handler handles ImBot settings HTTP requests

func NewHandler

func NewHandler(ctx context.Context, cfg *config.Config) (*Handler, error)

NewHandler creates a new ImBot settings handler

func (*Handler) BotManager

func (h *Handler) BotManager() *BotManager

BotManager returns the bot manager for server integration

func (*Handler) CreateSettings

func (h *Handler) CreateSettings(c *gin.Context)

CreateSettings creates a new ImBot configuration

func (*Handler) DeleteSettings

func (h *Handler) DeleteSettings(c *gin.Context)

DeleteSettings deletes an ImBot configuration

func (*Handler) GetPlatformConfig

func (h *Handler) GetPlatformConfig(c *gin.Context)

GetPlatformConfig returns auth configuration for a specific platform

func (*Handler) GetPlatforms

func (h *Handler) GetPlatforms(c *gin.Context)

GetPlatforms returns all supported ImBot platforms with their configurations

func (*Handler) GetSettings

func (h *Handler) GetSettings(c *gin.Context)

GetSettings returns a single ImBot configuration by UUID

func (*Handler) ListSettings

func (h *Handler) ListSettings(c *gin.Context)

ListSettings returns all ImBot configurations

func (*Handler) Shutdown

func (h *Handler) Shutdown()

Shutdown stops all running bots and cleans up resources

func (*Handler) StartAllEnabled

func (h *Handler) StartAllEnabled(ctx context.Context) error

StartAllEnabled starts all enabled bots (delegates to BotManager)

func (*Handler) StopAll

func (h *Handler) StopAll()

StopAll stops all running bots (delegates to BotManager)

func (*Handler) Sync

func (h *Handler) Sync(ctx context.Context) error

Sync ensures running bots match enabled settings (delegates to BotManager)

func (*Handler) ToggleSettings

func (h *Handler) ToggleSettings(c *gin.Context)

ToggleSettings toggles the enabled status of an ImBot configuration

func (*Handler) UpdateSettings

func (h *Handler) UpdateSettings(c *gin.Context)

UpdateSettings updates an existing ImBot configuration

type ListResponse

type ListResponse struct {
	Success  bool          `json:"success"`
	Settings []db.Settings `json:"settings"`
}

ListResponse represents the response for listing ImBot settings

type PlatformConfig

type PlatformConfig struct {
	Platform    string            `json:"platform"`
	DisplayName string            `json:"display_name"`
	AuthType    string            `json:"auth_type"`
	Category    string            `json:"category"`
	Fields      []imbot.FieldSpec `json:"fields"`
}

PlatformConfig represents a platform configuration

type PlatformConfigResponse

type PlatformConfigResponse struct {
	Success  bool           `json:"success"`
	Platform PlatformConfig `json:"platform"`
}

PlatformConfigResponse represents the response for platform config

type PlatformsResponse

type PlatformsResponse struct {
	Success    bool             `json:"success"`
	Platforms  []PlatformConfig `json:"platforms"`
	Categories gin.H            `json:"categories"`
}

PlatformsResponse represents the response for listing platforms

type QRStartData

type QRStartData struct {
	QrCodeID   string `json:"qrcode_id"`
	QrCodeData string `json:"qrcode_data"`
	ExpiresIn  int    `json:"expires_in"`
}

QRStartData is the data for QR start response

type QRStartRequest

type QRStartRequest struct {
	BotUUID     string `json:"bot_uuid" binding:"required"`
	BotType     string `json:"bot_type,omitempty"`     // Optional bot type (default: "3")
	BotName     string `json:"bot_name,omitempty"`     // Optional: bot display name (for deferred creation)
	BotPlatform string `json:"bot_platform,omitempty"` // Optional: platform (for deferred creation)
}

QRStartRequest is the request to start QR login

type QRStartResponse

type QRStartResponse struct {
	Success bool        `json:"success"`
	Data    QRStartData `json:"data"`
	Error   string      `json:"error,omitempty"`
}

QRStartResponse is the response for QR start

type QRStatusData

type QRStatusData struct {
	Status  string `json:"status"`             // wait, scaned, confirmed, expired
	BotUUID string `json:"bot_uuid,omitempty"` // Real bot UUID after confirmed (may differ from session UUID for new bots)
}

QRStatusData is the data for QR status response

type QRStatusResponse

type QRStatusResponse struct {
	Success bool         `json:"success"`
	Data    QRStatusData `json:"data,omitempty"`
	Error   string       `json:"error,omitempty"`
}

QRStatusResponse is the response for QR status

type SettingsResponse

type SettingsResponse struct {
	Success  bool        `json:"success"`
	Settings db.Settings `json:"settings"`
}

SettingsResponse represents the response for a single ImBot settings

type ToggleResponse

type ToggleResponse struct {
	Success bool `json:"success"`
	Enabled bool `json:"enabled"`
}

ToggleResponse represents the response for toggling ImBot settings

type UpdateRequest

type UpdateRequest struct {
	Name               string            `json:"name,omitempty"`
	Platform           string            `json:"platform,omitempty"`
	AuthType           string            `json:"auth_type,omitempty"`
	Auth               map[string]string `json:"auth,omitempty"`
	ProxyURL           string            `json:"proxy_url,omitempty"`
	ChatID             string            `json:"chat_id,omitempty"`
	BashAllowlist      []string          `json:"bash_allowlist,omitempty"`
	DefaultCwd         *string           `json:"default_cwd,omitempty"`         // Pointer for partial update
	DefaultAgent       *string           `json:"default_agent,omitempty"`       // Pointer for partial update
	Enabled            *bool             `json:"enabled,omitempty"`             // Pointer to allow partial update
	Token              string            `json:"token,omitempty"`               // Legacy field
	SmartGuideProvider *string           `json:"smartguide_provider,omitempty"` // Provider UUID
	SmartGuideModel    *string           `json:"smartguide_model,omitempty"`    // Model identifier
}

UpdateRequest represents the request to update ImBot settings

type WeChatQRLoginHandler

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

WeChatQRLoginHandler handles Weixin QR code login flow

func NewWeChatQRLoginHandler

func NewWeChatQRLoginHandler(settingsStore *db.ImBotSettingsStore) *WeChatQRLoginHandler

NewWeChatQRLoginHandler creates a new Weixin QR login handler

func (*WeChatQRLoginHandler) QRCancel

func (h *WeChatQRLoginHandler) QRCancel(c *gin.Context)

QRCancel cancels the pending QR login

func (*WeChatQRLoginHandler) QRStart

func (h *WeChatQRLoginHandler) QRStart(c *gin.Context)

QRStart initiates the QR code login flow

func (*WeChatQRLoginHandler) QRStatus

func (h *WeChatQRLoginHandler) QRStatus(c *gin.Context)

QRStatus polls the QR code login status

Jump to

Keyboard shortcuts

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