bot

package
v0.260219.1420-preview Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthTypeLabels = map[string]string{
	"token": "Token",
	"oauth": "OAuth",
	"qr":    "QR Code",
	"basic": "Basic Auth",
}

AuthTypeLabels provides display labels for auth types

View Source
var CategoryLabels = map[string]string{
	"im":         "IM Platforms",
	"enterprise": "Enterprise",
	"business":   "Business",
}

CategoryLabels provides display labels for categories

View Source
var PlatformConfigs = map[string]PlatformAuthConfig{
	"telegram": {
		Platform:    "telegram",
		AuthType:    "token",
		DisplayName: "Telegram",
		Category:    "im",
		Fields: []FieldSpec{
			{
				Key:         "token",
				Label:       "Bot Token",
				Placeholder: "123456789:ABCdefGHIjklMNOpqrsTUVwxyz",
				Required:    true,
				Secret:      true,
				HelperText:  "Get from @BotFather on Telegram",
			},
		},
	},
	"slack": {
		Platform:    "slack",
		AuthType:    "token",
		DisplayName: "Slack",
		Category:    "im",
		Fields: []FieldSpec{
			{
				Key:         "token",
				Label:       "Bot Token",
				Placeholder: "xoxb-your-token-here",
				Required:    true,
				Secret:      true,
				HelperText:  "Must start with 'xoxb-'. Get from Slack API",
			},
		},
	},
	"discord": {
		Platform:    "discord",
		AuthType:    "token",
		DisplayName: "Discord",
		Category:    "im",
		Fields: []FieldSpec{
			{
				Key:         "token",
				Label:       "Bot Token",
				Placeholder: "MTIzNDU2Nzg5OABCDEF123456789",
				Required:    true,
				Secret:      true,
				HelperText:  "Must start with 'Bot ' prefix. Get from Discord Developer Portal",
			},
		},
	},
	"dingtalk": {
		Platform:    "dingtalk",
		AuthType:    "oauth",
		DisplayName: "DingTalk",
		Category:    "enterprise",
		Fields: []FieldSpec{
			{
				Key:         "clientId",
				Label:       "App Key",
				Placeholder: "ding-your-app-key",
				Required:    true,
				Secret:      true,
				HelperText:  "Also known as AppKey or ClientId",
			},
			{
				Key:         "clientSecret",
				Label:       "App Secret",
				Placeholder: "Your app secret",
				Required:    true,
				Secret:      true,
				HelperText:  "Also known as AppSecret or ClientSecret",
			},
		},
	},
	"feishu": {
		Platform:    "feishu",
		AuthType:    "oauth",
		DisplayName: "Feishu / Lark",
		Category:    "enterprise",
		Fields: []FieldSpec{
			{
				Key:         "clientId",
				Label:       "App ID",
				Placeholder: "cli-your-app-id",
				Required:    true,
				Secret:      true,
				HelperText:  "Also known as AppID or ClientId",
			},
			{
				Key:         "clientSecret",
				Label:       "App Secret",
				Placeholder: "Your app secret",
				Required:    true,
				Secret:      true,
				HelperText:  "Also known as AppSecret or ClientSecret",
			},
		},
	},
	"whatsapp": {
		Platform:    "whatsapp",
		AuthType:    "token",
		DisplayName: "WhatsApp",
		Category:    "business",
		Fields: []FieldSpec{
			{
				Key:         "token",
				Label:       "Access Token",
				Placeholder: "Your WhatsApp access token",
				Required:    true,
				Secret:      true,
				HelperText:  "Get from Meta for Developers",
			},
			{
				Key:         "phoneNumberId",
				Label:       "Phone Number ID",
				Placeholder: "Your phone number ID",
				Required:    false,
				Secret:      false,
				HelperText:  "Optional: The phone number ID for sending messages",
			},
		},
	},
}

PlatformConfigs maps platform identifiers to their auth configurations

Functions

func GetPlatformsByCategory

func GetPlatformsByCategory() map[string][]PlatformAuthConfig

GetPlatformsByCategory returns platforms grouped by category

func IsValidPlatform

func IsValidPlatform(platform string) bool

IsValidPlatform checks if a platform identifier is valid

func RunTelegramBot

func RunTelegramBot(ctx context.Context, store *Store, sessionMgr *session.Manager) error

RunTelegramBot starts a Telegram bot that proxies messages to remote-coder sessions.

Types

type FieldSpec

type FieldSpec struct {
	Key         string `json:"key"`         // Field key in auth map
	Label       string `json:"label"`       // Display label for the field
	Placeholder string `json:"placeholder"` // Placeholder text
	Required    bool   `json:"required"`    // Whether this field is required
	Secret      bool   `json:"secret"`      // Whether this field should be masked (password/token)
	HelperText  string `json:"helperText"`  // Additional guidance for users
}

FieldSpec defines a single auth field

type Manager

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

Manager manages the lifecycle of running bot instances

func NewManager

func NewManager(store *Store, sessionMgr *session.Manager) *Manager

NewManager creates a new bot manager

func (*Manager) IsRunning

func (m *Manager) IsRunning(uuid string) bool

IsRunning checks if a bot is running

func (*Manager) Start

func (m *Manager) Start(parentCtx context.Context, uuid string) error

Start starts a bot by UUID

func (*Manager) StartEnabled

func (m *Manager) StartEnabled(ctx context.Context) error

StartEnabled starts all enabled bots

func (*Manager) Stop

func (m *Manager) Stop(uuid string)

Stop stops a bot by UUID

func (*Manager) StopAll

func (m *Manager) StopAll()

StopAll stops all running bots

type PlatformAuthConfig

type PlatformAuthConfig struct {
	Platform    string      `json:"platform"`     // Platform identifier
	AuthType    string      `json:"auth_type"`    // "token", "oauth", "qr", "basic"
	DisplayName string      `json:"display_name"` // Human-readable platform name
	Category    string      `json:"category"`     // "im", "enterprise", "business"
	Fields      []FieldSpec `json:"fields"`       // Required/optional auth fields
}

PlatformAuthConfig defines the authentication requirements for each platform

func GetAllPlatforms

func GetAllPlatforms() []PlatformAuthConfig

GetAllPlatforms returns all platform configurations as a slice

func GetPlatformConfig

func GetPlatformConfig(platform string) (PlatformAuthConfig, bool)

GetPlatformConfig returns the auth config for a given platform

type Settings

type Settings struct {
	UUID          string            `json:"uuid,omitempty"`
	Name          string            `json:"name,omitempty"`           // User-defined name for the bot
	Token         string            `json:"token,omitempty"`          // Legacy: for backward compatibility
	Platform      string            `json:"platform"`                 // Platform identifier
	AuthType      string            `json:"auth_type"`                // Auth type: token, oauth, qr
	Auth          map[string]string `json:"auth"`                     // Dynamic auth fields based on platform
	ProxyURL      string            `json:"proxy_url,omitempty"`      // Optional proxy URL
	ChatIDLock    string            `json:"chat_id,omitempty"`        // Optional chat ID lock
	BashAllowlist []string          `json:"bash_allowlist,omitempty"` // Optional bash command allowlist
	Enabled       bool              `json:"enabled"`                  // Whether this bot is enabled
	CreatedAt     string            `json:"created_at,omitempty"`
	UpdatedAt     string            `json:"updated_at,omitempty"`
}

Settings represents bot configuration with platform-specific auth

type Store

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

func NewStore

func NewStore(dbPath string) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) CreateSettings

func (s *Store) CreateSettings(settings Settings) (Settings, error)

CreateSettings creates a new bot configuration

func (*Store) DeleteSettings

func (s *Store) DeleteSettings(uuid string) error

DeleteSettings deletes a bot configuration

func (*Store) GetBashCwd

func (s *Store) GetBashCwd(chatID string) (string, bool, error)

func (*Store) GetSessionForChat

func (s *Store) GetSessionForChat(chatID string) (string, bool, error)

func (*Store) GetSettings

func (s *Store) GetSettings() (Settings, error)

func (*Store) GetSettingsByUUID

func (s *Store) GetSettingsByUUID(uuid string) (Settings, error)

GetSettingsByUUID returns a single bot configuration by UUID

func (*Store) ListEnabledSettings

func (s *Store) ListEnabledSettings() ([]Settings, error)

ListEnabledSettings returns all enabled bot configurations

func (*Store) ListSettings

func (s *Store) ListSettings() ([]Settings, error)

ListSettings returns all bot configurations from v2 table

func (*Store) SaveSettings

func (s *Store) SaveSettings(settings Settings) error

func (*Store) SetBashCwd

func (s *Store) SetBashCwd(chatID, cwd string) error

func (*Store) SetSessionForChat

func (s *Store) SetSessionForChat(chatID, sessionID string) error

func (*Store) ToggleSettings

func (s *Store) ToggleSettings(uuid string) (bool, error)

ToggleSettings toggles the enabled status of a bot configuration

func (*Store) UpdateSettings

func (s *Store) UpdateSettings(uuid string, settings Settings) error

UpdateSettings updates an existing bot configuration

Jump to

Keyboard shortcuts

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