Documentation
¶
Index ¶
- Variables
- func BuildActionKeyboard() *imbot.KeyboardBuilder
- func BuildCancelKeyboard() *imbot.KeyboardBuilder
- func BuildCreateConfirmKeyboard(path string) (*imbot.KeyboardBuilder, string)
- func BuildCustomPathPrompt() string
- func ExpandPath(path string) (string, error)
- func GetPlatformsByCategory() map[string][]PlatformAuthConfig
- func InitChatSchema(db *sql.DB) error
- func IsValidPlatform(platform string) bool
- func RunTelegramBot(ctx context.Context, store *Store, sessionMgr *session.Manager, ...) error
- func SendDirectoryBrowser(ctx context.Context, bot imbot.Bot, browser *DirectoryBrowser, chatID string, ...) (string, error)
- func ValidateProjectPath(path string) error
- type BindFlowState
- type Chat
- type ChatStore
- func (s *ChatStore) AddToWhitelist(chatID, platform, addedBy string) error
- func (s *ChatStore) BindProject(chatID, platform, projectPath, ownerID string) error
- func (s *ChatStore) GetBashCwd(chatID string) (string, bool, error)
- func (s *ChatStore) GetChat(chatID string) (*Chat, error)
- func (s *ChatStore) GetOrCreateChat(chatID, platform string) (*Chat, error)
- func (s *ChatStore) GetProjectPath(chatID string) (string, bool, error)
- func (s *ChatStore) GetSession(chatID string) (string, bool, error)
- func (s *ChatStore) IsWhitelisted(chatID string) bool
- func (s *ChatStore) ListChatsByOwner(ownerID, platform string) ([]*Chat, error)
- func (s *ChatStore) RemoveFromWhitelist(chatID string) error
- func (s *ChatStore) SetBashCwd(chatID, cwd string) error
- func (s *ChatStore) SetSession(chatID, sessionID string) error
- func (s *ChatStore) UpdateChat(chatID string, fn func(*Chat)) error
- func (s *ChatStore) UpsertChat(chat *Chat) error
- type DirectoryBrowser
- func (b *DirectoryBrowser) BuildKeyboard(chatID string) (*BindFlowState, *imbot.KeyboardBuilder, string, error)
- func (b *DirectoryBrowser) Clear(chatID string)
- func (b *DirectoryBrowser) GetCurrentPath(chatID string) string
- func (b *DirectoryBrowser) GetState(chatID string) *BindFlowState
- func (b *DirectoryBrowser) IsWaitingInput(chatID string) bool
- func (b *DirectoryBrowser) Navigate(chatID string, path string) error
- func (b *DirectoryBrowser) NavigateByIndex(chatID string, index int) error
- func (b *DirectoryBrowser) NavigateUp(chatID string) error
- func (b *DirectoryBrowser) NextPage(chatID string) error
- func (b *DirectoryBrowser) PrevPage(chatID string) error
- func (b *DirectoryBrowser) SetMessageID(chatID string, messageID string)
- func (b *DirectoryBrowser) SetWaitingInput(chatID string, waiting bool, promptMsgID string)
- func (b *DirectoryBrowser) Start(chatID string) (*BindFlowState, error)
- type FieldSpec
- type Manager
- type PlatformAuthConfig
- type ResponseMeta
- type Settings
- type Store
- func (s *Store) AddGroupToWhitelist(groupID, platform, addedBy string) error
- func (s *Store) ChatStore() *ChatStore
- func (s *Store) Close() error
- func (s *Store) CreateSettings(settings Settings) (Settings, error)
- func (s *Store) DB() *sql.DB
- func (s *Store) DeleteSettings(uuid string) error
- func (s *Store) GetBashCwd(chatID string) (string, bool, error)
- func (s *Store) GetSessionForChat(chatID string) (string, bool, error)
- func (s *Store) GetSettings() (Settings, error)
- func (s *Store) GetSettingsByUUID(uuid string) (Settings, error)
- func (s *Store) IsGroupWhitelisted(groupID string) bool
- func (s *Store) ListEnabledSettings() ([]Settings, error)
- func (s *Store) ListSettings() ([]Settings, error)
- func (s *Store) ListWhitelistedGroups() ([]struct{ ... }, error)
- func (s *Store) RemoveGroupFromWhitelist(groupID string) error
- func (s *Store) SaveSettings(settings Settings) error
- func (s *Store) SetBashCwd(chatID, cwd string) error
- func (s *Store) SetSessionForChat(chatID, sessionID string) error
- func (s *Store) ToggleSettings(uuid string) (bool, error)
- func (s *Store) UpdateSettings(uuid string, settings Settings) error
Constants ¶
This section is empty.
Variables ¶
var AuthTypeLabels = map[string]string{
"token": "Token",
"oauth": "OAuth",
"qr": "QR Code",
"basic": "Basic Auth",
}
AuthTypeLabels provides display labels for auth types
var CategoryLabels = map[string]string{
"im": "IM Platforms",
"enterprise": "Enterprise",
"business": "Business",
}
CategoryLabels provides display labels for categories
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 BuildActionKeyboard ¶
func BuildActionKeyboard() *imbot.KeyboardBuilder
BuildActionKeyboard builds the inline keyboard for actions (Clear/Bind)
func BuildCancelKeyboard ¶
func BuildCancelKeyboard() *imbot.KeyboardBuilder
BuildCancelKeyboard builds a simple cancel keyboard
func BuildCreateConfirmKeyboard ¶
func BuildCreateConfirmKeyboard(path string) (*imbot.KeyboardBuilder, string)
BuildCreateConfirmKeyboard builds the confirmation keyboard for creating a directory
func BuildCustomPathPrompt ¶
func BuildCustomPathPrompt() string
BuildCustomPathPrompt returns the text for custom path input prompt
func ExpandPath ¶
ExpandPath expands ~ to home directory and returns absolute path
func GetPlatformsByCategory ¶
func GetPlatformsByCategory() map[string][]PlatformAuthConfig
GetPlatformsByCategory returns platforms grouped by category
func InitChatSchema ¶
InitChatSchema initializes the chat schema
func IsValidPlatform ¶
IsValidPlatform checks if a platform identifier is valid
func RunTelegramBot ¶
func RunTelegramBot(ctx context.Context, store *Store, sessionMgr *session.Manager, agentBoot *agentboot.AgentBoot, permHandler permission.Handler) error
RunTelegramBot starts a Telegram bot that proxies messages to remote-coder sessions.
func SendDirectoryBrowser ¶
func SendDirectoryBrowser(ctx context.Context, bot imbot.Bot, browser *DirectoryBrowser, chatID string, editMessageID string) (string, error)
SendDirectoryBrowser sends or updates the directory browser message
func ValidateProjectPath ¶
ValidateProjectPath checks if the path exists and is accessible
Types ¶
type BindFlowState ¶
type BindFlowState struct {
ChatID string
CurrentPath string
Page int
TotalDirs int
PageSize int
MessageID string // Message ID to edit
ExpiresAt time.Time
WaitingInput bool // Waiting for custom path input
PromptMsgID string // Prompt message ID for cleanup
Dirs []string // Current directory list (for navigation by index)
}
BindFlowState represents the state of an ongoing bind flow
type Chat ¶
type Chat struct {
ChatID string `json:"chat_id"`
Platform string `json:"platform"`
ProjectPath string `json:"project_path,omitempty"`
OwnerID string `json:"owner_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
// Group-specific
IsWhitelisted bool `json:"is_whitelisted"`
WhitelistedBy string `json:"whitelisted_by,omitempty"`
// Bash state
BashCwd string `json:"bash_cwd,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Chat represents all state associated with a chat (direct or group)
type ChatStore ¶
type ChatStore struct {
// contains filtered or unexported fields
}
ChatStore handles unified chat persistence
func NewChatStore ¶
NewChatStore creates a new chat store
func (*ChatStore) AddToWhitelist ¶
AddToWhitelist adds a chat to the whitelist
func (*ChatStore) BindProject ¶
BindProject binds a project to a chat (creates chat if not exists)
func (*ChatStore) GetBashCwd ¶
GetBashCwd retrieves the bash working directory for a chat
func (*ChatStore) GetOrCreateChat ¶
GetOrCreateChat gets a chat or creates it if not exists
func (*ChatStore) GetProjectPath ¶
GetProjectPath retrieves the project path for a chat
func (*ChatStore) GetSession ¶
GetSession retrieves the session for a chat
func (*ChatStore) IsWhitelisted ¶
IsWhitelisted checks if a chat is whitelisted
func (*ChatStore) ListChatsByOwner ¶
ListChatsByOwner lists all chats owned by a user
func (*ChatStore) RemoveFromWhitelist ¶
RemoveFromWhitelist removes a chat from the whitelist
func (*ChatStore) SetBashCwd ¶
SetBashCwd sets the bash working directory for a chat
func (*ChatStore) SetSession ¶
SetSession sets the session for a chat (creates chat if not exists)
func (*ChatStore) UpdateChat ¶
UpdateChat updates specific fields of a chat
func (*ChatStore) UpsertChat ¶
UpsertChat creates or updates a chat
type DirectoryBrowser ¶
type DirectoryBrowser struct {
// contains filtered or unexported fields
}
DirectoryBrowser manages directory navigation for bind flow
func NewDirectoryBrowser ¶
func NewDirectoryBrowser() *DirectoryBrowser
NewDirectoryBrowser creates a new directory browser
func (*DirectoryBrowser) BuildKeyboard ¶
func (b *DirectoryBrowser) BuildKeyboard(chatID string) (*BindFlowState, *imbot.KeyboardBuilder, string, error)
BuildKeyboard builds the inline keyboard for directory browsing
func (*DirectoryBrowser) Clear ¶
func (b *DirectoryBrowser) Clear(chatID string)
Clear removes the state for a chat
func (*DirectoryBrowser) GetCurrentPath ¶
func (b *DirectoryBrowser) GetCurrentPath(chatID string) string
GetCurrentPath returns the current path for a chat
func (*DirectoryBrowser) GetState ¶
func (b *DirectoryBrowser) GetState(chatID string) *BindFlowState
GetState returns the current state for a chat
func (*DirectoryBrowser) IsWaitingInput ¶
func (b *DirectoryBrowser) IsWaitingInput(chatID string) bool
IsWaitingInput checks if the chat is waiting for custom path input
func (*DirectoryBrowser) Navigate ¶
func (b *DirectoryBrowser) Navigate(chatID string, path string) error
Navigate navigates to a subdirectory
func (*DirectoryBrowser) NavigateByIndex ¶
func (b *DirectoryBrowser) NavigateByIndex(chatID string, index int) error
NavigateByIndex navigates to a subdirectory by index (stored in state.Dirs)
func (*DirectoryBrowser) NavigateUp ¶
func (b *DirectoryBrowser) NavigateUp(chatID string) error
NavigateUp navigates to the parent directory
func (*DirectoryBrowser) NextPage ¶
func (b *DirectoryBrowser) NextPage(chatID string) error
NextPage moves to the next page of directories
func (*DirectoryBrowser) PrevPage ¶
func (b *DirectoryBrowser) PrevPage(chatID string) error
PrevPage moves to the previous page of directories
func (*DirectoryBrowser) SetMessageID ¶
func (b *DirectoryBrowser) SetMessageID(chatID string, messageID string)
SetMessageID sets the message ID for editing
func (*DirectoryBrowser) SetWaitingInput ¶
func (b *DirectoryBrowser) SetWaitingInput(chatID string, waiting bool, promptMsgID string)
SetWaitingInput sets the waiting for input state
func (*DirectoryBrowser) Start ¶
func (b *DirectoryBrowser) Start(chatID string) (*BindFlowState, error)
Start begins a new bind flow for a chat
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, agentBoot *agentboot.AgentBoot, permHandler permission.Handler) *Manager
NewManager creates a new bot manager
func (*Manager) StartEnabled ¶
StartEnabled starts all enabled 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 ResponseMeta ¶
ResponseMeta contains metadata for response formatting
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 (*Store) AddGroupToWhitelist ¶
func (*Store) CreateSettings ¶
CreateSettings creates a new bot configuration
func (*Store) DeleteSettings ¶
DeleteSettings deletes a bot configuration
func (*Store) GetSessionForChat ¶
func (*Store) GetSettings ¶
func (*Store) GetSettingsByUUID ¶
GetSettingsByUUID returns a single bot configuration by UUID
func (*Store) IsGroupWhitelisted ¶
func (*Store) ListEnabledSettings ¶
ListEnabledSettings returns all enabled bot configurations
func (*Store) ListSettings ¶
ListSettings returns all bot configurations from v2 table
func (*Store) ListWhitelistedGroups ¶
func (s *Store) ListWhitelistedGroups() ([]struct { GroupID string Platform string AddedBy string CreatedAt string }, error)
ListWhitelistedGroups returns all whitelisted groups
func (*Store) RemoveGroupFromWhitelist ¶
func (*Store) SaveSettings ¶
func (*Store) SetBashCwd ¶
func (*Store) SetSessionForChat ¶
func (*Store) ToggleSettings ¶
ToggleSettings toggles the enabled status of a bot configuration