Documentation
¶
Overview ¶
Package gateway - WeChat iLink Bot Gateway implementation
This implements the Tencent iLink Bot REST API (微信企点 iLink 机器人), the same API used by picoclaw (https://github.com/sipeed/picoclaw/tree/main/pkg/channels/weixin).
The iLink Bot API enables WeChat bots to:
- Long-poll for incoming messages via GetUpdates
- Send text, image, video, and file messages
- Send typing indicators
- Upload/download media via CDN
- Login via QR code scanning
- Handle voice messages with built-in ASR transcription
API Base URL: https://ilinkai.weixin.qq.com/ Endpoints:
- GET /ilink/bot/get_bot_qrcode - Get QR code for login
- GET /ilink/bot/get_qrcode_status - Poll QR code scanning status
- POST /ilink/bot/getupdates - Long-poll for new messages
- POST /ilink/bot/sendmessage - Send a message
- POST /ilink/bot/getuploadurl - Get CDN upload URL
- POST /ilink/bot/getconfig - Get bot config (typing ticket, etc.)
- POST /ilink/bot/sendtyping - Send typing indicator
Index ¶
- Constants
- func BuildCDNDownloadURL(base, encryptedQueryParam string) string
- func BuildCDNUploadURL(base, uploadParam, filekey string) string
- func ConvertToChannelSet(channels []string) map[string]bool
- func DecryptAESECB(ciphertext, key []byte) ([]byte, error)
- func DetectMediaMetadata(data []byte, fallbackName, fallbackContentType string) (string, string)
- func EncodeWeixinAESKey(aesKeyHex string) string
- func EncryptAESECB(plaintext, key []byte) ([]byte, error)
- func ForceDisplayQR(qrData string)
- func GenerateQRCodePNG(data string) (string, error)
- func GenerateQRCodePNGBytes(data string) ([]byte, error)
- func GetQRCodeURL(qrData string) string
- func ParseWeixinMediaAESKey(aesKeyBase64 string) ([]byte, error)
- func PerformILinkLogin(ctx context.Context, opts ILinkLoginOpts) (botToken, userID, botID, baseURL string, err error)
- func PerformILinkLoginTerminal(ctx context.Context, opts ILinkLoginOpts) (botToken, userID, botID, baseURL string, err error)
- func ShouldProcessChannel(channelID string, allowed, blocked []string) bool
- type AgentHandler
- type AgentHandlerWithStats
- type AgentSession
- type BlacklistMiddleware
- type CDNDownloader
- type CDNUploader
- type DingTalkGateway
- func (g *DingTalkGateway) CheckHealth() *HealthStatus
- func (g *DingTalkGateway) Connect(ctx context.Context) error
- func (g *DingTalkGateway) Disconnect() error
- func (g *DingTalkGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *DingTalkGateway) IsConnected() bool
- func (g *DingTalkGateway) Name() string
- func (g *DingTalkGateway) Receive() <-chan Message
- func (g *DingTalkGateway) Reconnect(ctx context.Context) error
- func (g *DingTalkGateway) Send(ctx context.Context, resp Response) error
- func (g *DingTalkGateway) SendText(userID, content string) error
- func (g *DingTalkGateway) SendToConversation(conversationID, content string) error
- func (g *DingTalkGateway) SetAESKey(key string)
- func (g *DingTalkGateway) SetAgentID(agentID string)
- func (g *DingTalkGateway) SetCallbackPort(port int)
- type DiscordGateway
- func (g *DiscordGateway) CheckHealth() *HealthStatus
- func (g *DiscordGateway) Connect(ctx context.Context) error
- func (g *DiscordGateway) Disconnect() error
- func (g *DiscordGateway) GetSession() *discordgo.Session
- func (g *DiscordGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *DiscordGateway) IsConnected() bool
- func (g *DiscordGateway) Name() string
- func (g *DiscordGateway) Receive() <-chan Message
- func (g *DiscordGateway) Send(ctx context.Context, resp Response) error
- func (g *DiscordGateway) SetCallbackPort(port int)
- func (g *DiscordGateway) SetChannelFilter(allowed, blocked []string)
- type FeishuGateway
- func (g *FeishuGateway) CheckHealth() *HealthStatus
- func (g *FeishuGateway) Connect(ctx context.Context) error
- func (g *FeishuGateway) Disconnect() error
- func (g *FeishuGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *FeishuGateway) IsConnected() bool
- func (g *FeishuGateway) Name() string
- func (g *FeishuGateway) Receive() <-chan Message
- func (g *FeishuGateway) Reconnect(ctx context.Context) error
- func (g *FeishuGateway) Send(ctx context.Context, resp Response) error
- func (g *FeishuGateway) SendRichText(chatID string, paragraphs []map[string]string) error
- func (g *FeishuGateway) SendText(chatID, text string) error
- func (g *FeishuGateway) SetCallbackPort(port int)
- func (g *FeishuGateway) SetChannelFilter(allowed, blocked []string)
- type Gateway
- func (g *Gateway) AddQRCodeHandler(platform string, handler PlatformHandler)
- func (g *Gateway) Broadcast(content string)
- func (g *Gateway) GetAllLoginStatuses() []*LoginStatus
- func (g *Gateway) GetSession(userID, platform string) *Session
- func (g *Gateway) HealthCheck() *HealthStatus
- func (g *Gateway) IsRunning() bool
- func (g *Gateway) ListSessions() []Session
- func (g *Gateway) RegisterPlatform(name string, handler PlatformHandler)
- func (g *Gateway) ResetSession(userID, platform string)
- func (g *Gateway) Restart(ctx context.Context) error
- func (g *Gateway) SetMessageHandler(handler func(Message))
- func (g *Gateway) SetSessionEndHandler(handler func(Session))
- func (g *Gateway) SetSessionStore(store *session.Store)
- func (g *Gateway) Start(ctx context.Context) error
- func (g *Gateway) Stats() GatewayStats
- func (g *Gateway) Stop() error
- func (g *Gateway) Use(m Middleware)
- type GatewayConfig
- type GatewayStats
- type HealthCheckable
- type HealthStatus
- type ILinkAPIClient
- func (c *ILinkAPIClient) GetConfig(ctx context.Context, req ILinkGetConfigReq) (*ILinkGetConfigResp, error)
- func (c *ILinkAPIClient) GetQRCode(ctx context.Context, botType string) (*ILinkQRCodeResponse, error)
- func (c *ILinkAPIClient) GetQRCodeStatus(ctx context.Context, qrcode string) (*ILinkStatusResponse, error)
- func (c *ILinkAPIClient) GetUpdates(ctx context.Context, req ILinkGetUpdatesReq) (*ILinkGetUpdatesResp, error)
- func (c *ILinkAPIClient) GetUploadURL(ctx context.Context, req ILinkGetUploadURLReq) (*ILinkGetUploadURLResp, error)
- func (c *ILinkAPIClient) SendMessage(ctx context.Context, req ILinkSendMessageReq) error
- func (c *ILinkAPIClient) SendTyping(ctx context.Context, req ILinkSendTypingReq) error
- type ILinkAPIStatus
- type ILinkBaseInfo
- type ILinkCDNMedia
- type ILinkFileItem
- type ILinkGetConfigReq
- type ILinkGetConfigResp
- type ILinkGetUpdatesReq
- type ILinkGetUpdatesResp
- type ILinkGetUploadURLReq
- type ILinkGetUploadURLResp
- type ILinkImageItem
- type ILinkLoginOpts
- type ILinkMessage
- type ILinkMessageItem
- type ILinkQRCodeResponse
- type ILinkRefMessage
- type ILinkSendMessageReq
- type ILinkSendMessageResp
- type ILinkSendTypingReq
- type ILinkSendTypingResp
- type ILinkStatusResponse
- type ILinkTextItem
- type ILinkVideoItem
- type ILinkVoiceItem
- type LineGateway
- func (g *LineGateway) CheckHealth() *HealthStatus
- func (g *LineGateway) Connect(ctx context.Context) error
- func (g *LineGateway) Disconnect() error
- func (g *LineGateway) GetGroupMemberProfile(groupID, userID string) (map[string]interface{}, error)
- func (g *LineGateway) GetUserProfile(userID string) (map[string]interface{}, error)
- func (g *LineGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *LineGateway) IsConnected() bool
- func (g *LineGateway) LeaveGroup(groupID string) error
- func (g *LineGateway) LeaveRoom(roomID string) error
- func (g *LineGateway) Name() string
- func (g *LineGateway) Receive() <-chan Message
- func (g *LineGateway) Reply(replyToken, text string) error
- func (g *LineGateway) Send(ctx context.Context, resp Response) error
- func (g *LineGateway) SendImage(to, originalURL, previewURL string) error
- func (g *LineGateway) SendLocation(to, title, address string, lat, lon float64) error
- func (g *LineGateway) SendTemplate(to, altText string, template interface{}) error
- func (g *LineGateway) SendText(to, text string) error
- type LoginStatus
- type MatrixGateway
- func (g *MatrixGateway) CheckHealth() *HealthStatus
- func (g *MatrixGateway) Connect(ctx context.Context) error
- func (g *MatrixGateway) Disconnect() error
- func (g *MatrixGateway) GetJoinedRooms() ([]string, error)
- func (g *MatrixGateway) GetRoomMembers(roomID string) ([]string, error)
- func (g *MatrixGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *MatrixGateway) IsConnected() bool
- func (g *MatrixGateway) JoinRoom(ctx context.Context, roomIDOrAlias string) error
- func (g *MatrixGateway) LeaveRoom(ctx context.Context, roomID string) error
- func (g *MatrixGateway) Name() string
- func (g *MatrixGateway) Receive() <-chan Message
- func (g *MatrixGateway) Send(ctx context.Context, resp Response) error
- func (g *MatrixGateway) SendFormattedMessage(ctx context.Context, roomID, body, formattedBody string) error
- func (g *MatrixGateway) SetTypingIndicator(roomID string, isTyping bool, timeout time.Duration) error
- func (g *MatrixGateway) UploadContent(content []byte, contentType, filename string) (string, error)
- type MediaAttachment
- type Message
- type Middleware
- type MiddlewareFunc
- type PlatformHandler
- type PlatformQRGenerator
- type PlatformStatus
- type QQGateway
- func (g *QQGateway) CheckHealth() *HealthStatus
- func (g *QQGateway) Connect(ctx context.Context) error
- func (g *QQGateway) Disconnect() error
- func (g *QQGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *QQGateway) IsConnected() bool
- func (g *QQGateway) Name() string
- func (g *QQGateway) Receive() <-chan Message
- func (g *QQGateway) Send(ctx context.Context, resp Response) error
- func (g *QQGateway) SendText(channelID string, text string) error
- func (g *QQGateway) SetCallbackPort(port int)
- type QRCodeAPIResponse
- type QRCodeHandler
- type QRCodeManager
- func (m *QRCodeManager) CreateSession(platform string, qrData string, qrImage string) (*QRCodeSession, error)
- func (m *QRCodeManager) GenerateDingTalkQR(ctx context.Context, appKey, appSecret, redirectURI string) (*QRCodeSession, error)
- func (m *QRCodeManager) GenerateFeishuQR(ctx context.Context, appID, appSecret, redirectURI string) (*QRCodeSession, error)
- func (m *QRCodeManager) GenerateWeComQR(ctx context.Context, corpID, agentID, redirectURI string) (*QRCodeSession, error)
- func (m *QRCodeManager) GenerateWhatsAppQR(ctx context.Context, mode string) (*QRCodeSession, error)
- func (m *QRCodeManager) GetSession(platform string) *QRCodeSession
- func (m *QRCodeManager) ListSessions() []*QRCodeSession
- func (m *QRCodeManager) UpdateSessionStatus(platform string, status string, message string)
- type QRCodeResponse
- type QRCodeSession
- type QRPollContext
- type RateLimitMiddleware
- type Response
- type RichMenu
- type SensitiveWordMiddleware
- type Session
- type SlackGateway
- func (g *SlackGateway) CheckHealth() *HealthStatus
- func (g *SlackGateway) Connect(ctx context.Context) error
- func (g *SlackGateway) Disconnect() error
- func (g *SlackGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *SlackGateway) IsConnected() bool
- func (g *SlackGateway) Name() string
- func (g *SlackGateway) Receive() <-chan Message
- func (g *SlackGateway) Send(ctx context.Context, resp Response) error
- func (g *SlackGateway) SetChannelFilter(allowed, blocked []string)
- type TelegramConfig
- type TelegramHandler
- func (t *TelegramHandler) CheckHealth() *HealthStatus
- func (t *TelegramHandler) Connect(ctx context.Context) error
- func (t *TelegramHandler) Disconnect() error
- func (t *TelegramHandler) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (t *TelegramHandler) IsConnected() bool
- func (t *TelegramHandler) Name() string
- func (t *TelegramHandler) Receive() <-chan Message
- func (t *TelegramHandler) Send(ctx context.Context, resp Response) error
- type WeChatCallbackGateway
- func (g *WeChatCallbackGateway) CheckHealth() *HealthStatus
- func (g *WeChatCallbackGateway) Connect(ctx context.Context) error
- func (g *WeChatCallbackGateway) Disconnect() error
- func (g *WeChatCallbackGateway) GetAccessToken() string
- func (g *WeChatCallbackGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *WeChatCallbackGateway) IsConnected() bool
- func (g *WeChatCallbackGateway) Name() string
- func (g *WeChatCallbackGateway) Receive() <-chan Message
- func (g *WeChatCallbackGateway) RefreshToken() error
- func (g *WeChatCallbackGateway) Send(ctx context.Context, resp Response) error
- func (g *WeChatCallbackGateway) SendText(openID, text string) error
- func (g *WeChatCallbackGateway) SetCallbackPort(port int)
- type WeChatILinkConfig
- type WeChatILinkGateway
- func (g *WeChatILinkGateway) CheckHealth() *HealthStatus
- func (g *WeChatILinkGateway) Connect(ctx context.Context) error
- func (g *WeChatILinkGateway) Disconnect() error
- func (g *WeChatILinkGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *WeChatILinkGateway) IsConnected() bool
- func (g *WeChatILinkGateway) Name() string
- func (g *WeChatILinkGateway) Receive() <-chan Message
- func (g *WeChatILinkGateway) Send(ctx context.Context, resp Response) error
- func (g *WeChatILinkGateway) SendText(ctx context.Context, toUserID, text string) error
- func (g *WeChatILinkGateway) StartTyping(ctx context.Context, chatID string) (func(), error)
- func (g *WeChatILinkGateway) StopTyping(chatID string)
- type WeChatMessage
- type WeChatQRGateway
- func (g *WeChatQRGateway) CheckHealth() *HealthStatus
- func (g *WeChatQRGateway) Connect(ctx context.Context) error
- func (g *WeChatQRGateway) Disconnect() error
- func (g *WeChatQRGateway) GetOpenID() string
- func (g *WeChatQRGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *WeChatQRGateway) IsAuthenticated() bool
- func (g *WeChatQRGateway) IsConnected() bool
- func (g *WeChatQRGateway) Name() string
- func (g *WeChatQRGateway) Receive() <-chan Message
- func (g *WeChatQRGateway) Send(ctx context.Context, resp Response) error
- func (g *WeChatQRGateway) SendText(openID, text string) error
- func (g *WeChatQRGateway) SetQRCallback(cb func(url string))
- func (g *WeChatQRGateway) SetQRCallbackPort(port int)
- func (g *WeChatQRGateway) TriggerReauth(ctx context.Context)
- type WeChatSession
- type WeComAppGateway
- func (g *WeComAppGateway) CheckHealth() *HealthStatus
- func (g *WeComAppGateway) Connect(ctx context.Context) error
- func (g *WeComAppGateway) Disconnect() error
- func (g *WeComAppGateway) GetAccessToken() string
- func (g *WeComAppGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *WeComAppGateway) IsConnected() bool
- func (g *WeComAppGateway) Name() string
- func (g *WeComAppGateway) Receive() <-chan Message
- func (g *WeComAppGateway) Reconnect(ctx context.Context) error
- func (g *WeComAppGateway) Send(ctx context.Context, resp Response) error
- func (g *WeComAppGateway) SendText(userID, content string) error
- func (g *WeComAppGateway) SendToUser(userID, content string) error
- func (g *WeComAppGateway) SetAESKey(key string)
- func (g *WeComAppGateway) SetCallbackPort(port int)
- func (g *WeComAppGateway) SetChannelFilter(allowed, blocked []string)
- type WeComQRGateway
- func (g *WeComQRGateway) CheckHealth() *HealthStatus
- func (g *WeComQRGateway) Connect(ctx context.Context) error
- func (g *WeComQRGateway) Disconnect() error
- func (g *WeComQRGateway) GetUserID() string
- func (g *WeComQRGateway) GetUserName() string
- func (g *WeComQRGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *WeComQRGateway) IsAuthenticated() bool
- func (g *WeComQRGateway) IsConnected() bool
- func (g *WeComQRGateway) Name() string
- func (g *WeComQRGateway) Receive() <-chan Message
- func (g *WeComQRGateway) Send(ctx context.Context, resp Response) error
- func (g *WeComQRGateway) SendText(userID, content string) error
- func (g *WeComQRGateway) SetChannelFilter(allowed, blocked []string)
- func (g *WeComQRGateway) SetQRCallback(cb func(url string))
- func (g *WeComQRGateway) SetQRCallbackPort(port int)
- func (g *WeComQRGateway) TriggerReauth(ctx context.Context)
- type WeComSession
- type WhatsAppBusinessGateway
- func (g *WhatsAppBusinessGateway) CheckHealth() *HealthStatus
- func (g *WhatsAppBusinessGateway) Connect(ctx context.Context) error
- func (g *WhatsAppBusinessGateway) Disconnect() error
- func (g *WhatsAppBusinessGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *WhatsAppBusinessGateway) IsConnected() bool
- func (g *WhatsAppBusinessGateway) Name() string
- func (g *WhatsAppBusinessGateway) Receive() <-chan Message
- func (g *WhatsAppBusinessGateway) Send(ctx context.Context, resp Response) error
- func (g *WhatsAppBusinessGateway) SetChannelFilter(allowed, blocked []string)
- type WhatsAppGateway
- func (g *WhatsAppGateway) CheckHealth() *HealthStatus
- func (g *WhatsAppGateway) Connect(ctx context.Context) error
- func (g *WhatsAppGateway) Disconnect() error
- func (g *WhatsAppGateway) ExportSession() ([]byte, error)
- func (g *WhatsAppGateway) GetContactName(jid types.JID) string
- func (g *WhatsAppGateway) GetLatestQR() string
- func (g *WhatsAppGateway) GetLoginStatus() string
- func (g *WhatsAppGateway) GetQRCode() string
- func (g *WhatsAppGateway) GetQRCodeForAPI() *QRCodeResponse
- func (g *WhatsAppGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
- func (g *WhatsAppGateway) IsConnected() bool
- func (g *WhatsAppGateway) IsLoggedIn() bool
- func (g *WhatsAppGateway) Name() string
- func (g *WhatsAppGateway) Receive() <-chan Message
- func (g *WhatsAppGateway) RequestAppState() error
- func (g *WhatsAppGateway) Send(ctx context.Context, resp Response) error
- func (g *WhatsAppGateway) SendPresence(presence types.Presence) error
- func (g *WhatsAppGateway) SendTyping(chatJID types.JID) error
- func (g *WhatsAppGateway) SetChannelFilter(allowed, blocked []string)
- func (g *WhatsAppGateway) SetQRCallback(cb func(qr string))
- func (g *WhatsAppGateway) StartQRLogin(ctx context.Context) (string, error)
Constants ¶
const ( ILinkMsgTypeNone = 0 ILinkMsgTypeUser = 1 ILinkMsgTypeBot = 2 )
Message types (message_type field).
const ( ILinkItemTypeNone = 0 ILinkItemTypeText = 1 ILinkItemTypeImage = 2 ILinkItemTypeVoice = 3 ILinkItemTypeFile = 4 ILinkItemTypeVideo = 5 )
Message item types (type field in ILinkMessageItem).
const ( ILinkMsgStateNone = 0 ILinkMsgStateGenerating = 1 ILinkMsgStateFinish = 2 )
Message states.
const ( ILinkTypingTyping = 1 ILinkTypingCancel = 2 )
Typing status values.
const ( ILinkUploadMediaImage = 1 ILinkUploadMediaVideo = 2 ILinkUploadMediaFile = 3 ILinkUploadMediaVoice = 4 )
Upload media type constants.
Variables ¶
This section is empty.
Functions ¶
func BuildCDNDownloadURL ¶
BuildCDNDownloadURL constructs the CDN download URL from base URL and encrypted query param.
func BuildCDNUploadURL ¶
BuildCDNUploadURL constructs the CDN upload URL.
func ConvertToChannelSet ¶
ConvertToChannelSet 将字符串切片转换为 map[string]bool 集合
func DecryptAESECB ¶
DecryptAESECB decrypts data using AES-128-ECB with PKCS7 unpad.
func DetectMediaMetadata ¶
DetectMediaMetadata determines file name and content type from data.
func EncodeWeixinAESKey ¶
EncodeWeixinAESKey encodes a hex AES key to base64 format used by the API.
func EncryptAESECB ¶
EncryptAESECB encrypts data using AES-128-ECB with PKCS7 padding.
func ForceDisplayQR ¶ added in v0.3.0
func ForceDisplayQR(qrData string)
func GenerateQRCodePNG ¶ added in v0.3.1
GenerateQRCodePNG generates a proper PNG QR code image
func GenerateQRCodePNGBytes ¶ added in v0.4.0
GenerateQRCodePNGBytes generates QR code as raw PNG bytes
func GetQRCodeURL ¶ added in v0.3.0
GetQRCodeURL returns a URL to display the QR code in a browser
func ParseWeixinMediaAESKey ¶
ParseWeixinMediaAESKey parses a WeChat media AES key (base64 to raw bytes).
func PerformILinkLogin ¶
func PerformILinkLogin(ctx context.Context, opts ILinkLoginOpts) (botToken, userID, botID, baseURL string, err error)
PerformILinkLogin starts the WeChat QR login flow and blocks until login is successful or times out. It prints a QR code to the terminal for the user to scan.
Returns the BotToken, IlinkUserID, IlinkBotID, and BaseUrl on success.
func PerformILinkLoginTerminal ¶
func PerformILinkLoginTerminal(ctx context.Context, opts ILinkLoginOpts) (botToken, userID, botID, baseURL string, err error)
PerformILinkLoginTerminal performs QR login with terminal QR rendering support. If the terminal supports it, it will render the QR code as ASCII art. Otherwise, it provides the QR URL for manual scanning.
func ShouldProcessChannel ¶
ShouldProcessChannel 检查频道是否在白名单/黑名单中 规则: 1. 如果黑名单中有该频道,返回 false 2. 如果白名单非空且不包含该频道(或 "*"),返回 false 3. 否则返回 true
Types ¶
type AgentHandler ¶
type AgentHandler interface {
// Process processes a message and returns the response
Process(ctx context.Context, msg Message) (string, error)
// ProcessWithStats processes a message and returns response with token stats
ProcessWithStats(ctx context.Context, msg Message) (string, int, int, int, error)
// ResetSession resets a user's session
ResetSession(userID string)
}
AgentHandler defines the interface for the agent
type AgentHandlerWithStats ¶ added in v0.3.0
type AgentHandlerWithStats interface {
ProcessWithStats(ctx context.Context, msg Message) (string, int, int, int, error)
}
AgentHandlerWithStats is an optional interface for agent handlers that support token stats
type AgentSession ¶
type AgentSession struct {
UserID interface{} `json:"user_id"` // Platform-specific user ID (string, int64, etc.)
SessionID string `json:"session_id"`
State map[string]interface{}
CreatedAt time.Time
}
AgentSession represents a platform-specific agent session
type BlacklistMiddleware ¶
type BlacklistMiddleware struct {
// contains filtered or unexported fields
}
BlacklistMiddleware blocks users in a blacklist
func NewBlacklistMiddleware ¶
func NewBlacklistMiddleware() *BlacklistMiddleware
NewBlacklistMiddleware creates a new blacklist middleware
func (*BlacklistMiddleware) Add ¶
func (m *BlacklistMiddleware) Add(userID string)
Add adds a user to the blacklist
func (*BlacklistMiddleware) IsBlocked ¶
func (m *BlacklistMiddleware) IsBlocked(userID string) bool
IsBlocked checks if a user is blocked
func (*BlacklistMiddleware) Name ¶
func (m *BlacklistMiddleware) Name() string
func (*BlacklistMiddleware) Process ¶
func (m *BlacklistMiddleware) Process(msg *Message) (bool, error)
func (*BlacklistMiddleware) Remove ¶
func (m *BlacklistMiddleware) Remove(userID string)
Remove removes a user from the blacklist
type CDNDownloader ¶
type CDNDownloader struct {
// contains filtered or unexported fields
}
CDNDownloader handles downloading and decrypting media from WeChat CDN.
func NewCDNDownloader ¶
func NewCDNDownloader(cdnBaseURL string, proxy string) *CDNDownloader
NewCDNDownloader creates a CDN downloader.
func (*CDNDownloader) DownloadMedia ¶
func (d *CDNDownloader) DownloadMedia(ctx context.Context, encryptedQueryParam, fullURL string, key []byte) ([]byte, error)
DownloadMedia downloads and decrypts media from the CDN. If key is nil or empty, the data is returned as-is (no decryption).
type CDNUploader ¶
type CDNUploader struct {
// contains filtered or unexported fields
}
CDNUploader handles uploading and encrypting media to WeChat CDN.
func NewCDNUploader ¶
func NewCDNUploader(api *ILinkAPIClient, cdnBaseURL string, proxy string) *CDNUploader
NewCDNUploader creates a CDN uploader.
func (*CDNUploader) UploadFile ¶
func (u *CDNUploader) UploadFile(ctx context.Context, localPath, filename, toUserID string, mediaType int) (downloadParam, aesKeyHex string, err error)
UploadFile uploads a file to the WeChat CDN and returns the download param.
type DingTalkGateway ¶
type DingTalkGateway struct {
// contains filtered or unexported fields
}
DingTalkGateway implements the DingTalk platform handler
func NewDingTalkGateway ¶
func NewDingTalkGateway(appKey, appSecret string) *DingTalkGateway
NewDingTalkGateway creates a new DingTalk gateway
func (*DingTalkGateway) CheckHealth ¶
func (g *DingTalkGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for DingTalk gateway
func (*DingTalkGateway) Connect ¶
func (g *DingTalkGateway) Connect(ctx context.Context) error
Connect establishes connection to DingTalk
func (*DingTalkGateway) Disconnect ¶
func (g *DingTalkGateway) Disconnect() error
Disconnect closes the connection
func (*DingTalkGateway) HandleSlashCommand ¶
func (g *DingTalkGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles a slash command
func (*DingTalkGateway) IsConnected ¶
func (g *DingTalkGateway) IsConnected() bool
IsConnected checks if connected to DingTalk
func (*DingTalkGateway) Name ¶
func (g *DingTalkGateway) Name() string
Name returns the platform name
func (*DingTalkGateway) Receive ¶
func (g *DingTalkGateway) Receive() <-chan Message
Receive returns a channel of incoming messages
func (*DingTalkGateway) Reconnect ¶
func (g *DingTalkGateway) Reconnect(ctx context.Context) error
Reconnect attempts to reconnect with exponential backoff
func (*DingTalkGateway) Send ¶
func (g *DingTalkGateway) Send(ctx context.Context, resp Response) error
Send sends a message (enhanced to support rich content)
func (*DingTalkGateway) SendText ¶
func (g *DingTalkGateway) SendText(userID, content string) error
SendText sends a text message
func (*DingTalkGateway) SendToConversation ¶
func (g *DingTalkGateway) SendToConversation(conversationID, content string) error
SendToConversation sends a message to a conversation
func (*DingTalkGateway) SetAESKey ¶
func (g *DingTalkGateway) SetAESKey(key string)
SetAESKey sets the AES key for callback encryption
func (*DingTalkGateway) SetAgentID ¶
func (g *DingTalkGateway) SetAgentID(agentID string)
SetAgentID sets the DingTalk agent ID
func (*DingTalkGateway) SetCallbackPort ¶
func (g *DingTalkGateway) SetCallbackPort(port int)
SetCallbackPort sets the callback server port
type DiscordGateway ¶
type DiscordGateway struct {
// contains filtered or unexported fields
}
func NewDiscordGateway ¶
func NewDiscordGateway(token string) (*DiscordGateway, error)
func (*DiscordGateway) CheckHealth ¶
func (g *DiscordGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for Discord gateway
func (*DiscordGateway) Disconnect ¶
func (g *DiscordGateway) Disconnect() error
func (*DiscordGateway) GetSession ¶
func (g *DiscordGateway) GetSession() *discordgo.Session
GetSession returns the Discord session for advanced use
func (*DiscordGateway) HandleSlashCommand ¶
func (g *DiscordGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles slash commands
func (*DiscordGateway) IsConnected ¶
func (g *DiscordGateway) IsConnected() bool
func (*DiscordGateway) Name ¶
func (g *DiscordGateway) Name() string
func (*DiscordGateway) Receive ¶
func (g *DiscordGateway) Receive() <-chan Message
Receive returns a channel of incoming messages
func (*DiscordGateway) Send ¶
func (g *DiscordGateway) Send(ctx context.Context, resp Response) error
Send sends a message via Discord
func (*DiscordGateway) SetCallbackPort ¶
func (g *DiscordGateway) SetCallbackPort(port int)
SetCallbackPort sets the callback server port
func (*DiscordGateway) SetChannelFilter ¶
func (g *DiscordGateway) SetChannelFilter(allowed, blocked []string)
SetChannelFilter sets the channel allowlist and blocklist
type FeishuGateway ¶
type FeishuGateway struct {
// contains filtered or unexported fields
}
FeishuGateway implements the Feishu (Lark) platform handler
func NewFeishuGateway ¶
func NewFeishuGateway(appID, appSecret string) *FeishuGateway
NewFeishuGateway creates a new Feishu gateway
func (*FeishuGateway) CheckHealth ¶
func (g *FeishuGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for Feishu gateway
func (*FeishuGateway) Connect ¶
func (g *FeishuGateway) Connect(ctx context.Context) error
Connect establishes connection to Feishu
func (*FeishuGateway) Disconnect ¶
func (g *FeishuGateway) Disconnect() error
Disconnect closes the connection
func (*FeishuGateway) HandleSlashCommand ¶
func (g *FeishuGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles a slash command
func (*FeishuGateway) IsConnected ¶
func (g *FeishuGateway) IsConnected() bool
IsConnected checks if connected to Feishu
func (*FeishuGateway) Receive ¶
func (g *FeishuGateway) Receive() <-chan Message
Receive returns a channel of incoming messages
func (*FeishuGateway) Reconnect ¶
func (g *FeishuGateway) Reconnect(ctx context.Context) error
Reconnect attempts to reconnect with exponential backoff
func (*FeishuGateway) Send ¶
func (g *FeishuGateway) Send(ctx context.Context, resp Response) error
Send sends a message (enhanced to support rich text)
func (*FeishuGateway) SendRichText ¶
func (g *FeishuGateway) SendRichText(chatID string, paragraphs []map[string]string) error
SendRichText sends a rich text message with paragraphs
func (*FeishuGateway) SendText ¶
func (g *FeishuGateway) SendText(chatID, text string) error
SendText sends a text message
func (*FeishuGateway) SetCallbackPort ¶
func (g *FeishuGateway) SetCallbackPort(port int)
SetCallbackPort sets the callback server port
func (*FeishuGateway) SetChannelFilter ¶
func (g *FeishuGateway) SetChannelFilter(allowed, blocked []string)
SetChannelFilter sets the channel allowlist and blocklist
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway manages multiple platform connections and routes messages to the agent
func NewGateway ¶
func NewGateway(agent AgentHandler, config *GatewayConfig) *Gateway
NewGateway creates a new gateway
func (*Gateway) AddQRCodeHandler ¶ added in v0.3.1
func (g *Gateway) AddQRCodeHandler(platform string, handler PlatformHandler)
AddQRCodeHandler registers a platform handler that supports QR login
func (*Gateway) GetAllLoginStatuses ¶ added in v0.3.1
func (g *Gateway) GetAllLoginStatuses() []*LoginStatus
GetAllLoginStatuses returns login status for all platforms
func (*Gateway) GetSession ¶
GetSession gets a session by user ID and platform
func (*Gateway) HealthCheck ¶
func (g *Gateway) HealthCheck() *HealthStatus
HealthCheck performs a health check on the gateway
func (*Gateway) ListSessions ¶
ListSessions returns all active sessions
func (*Gateway) RegisterPlatform ¶
func (g *Gateway) RegisterPlatform(name string, handler PlatformHandler)
RegisterPlatform registers a platform handler
func (*Gateway) ResetSession ¶
ResetSession resets a user's session
func (*Gateway) SetMessageHandler ¶
SetMessageHandler sets the message handler callback
func (*Gateway) SetSessionEndHandler ¶
SetSessionEndHandler sets the session end handler callback
func (*Gateway) SetSessionStore ¶ added in v0.3.0
SetSessionStore sets the session store for persistence
func (*Gateway) Stats ¶
func (g *Gateway) Stats() GatewayStats
type GatewayConfig ¶
type GatewayConfig struct {
MaxSessions int
SessionTimeout time.Duration
EnableSlashCmd bool
PlatformTimeout time.Duration
APIPort int
EnableAPI bool
}
GatewayConfig holds gateway configuration
func DefaultGatewayConfig ¶
func DefaultGatewayConfig() *GatewayConfig
DefaultGatewayConfig returns default gateway configuration
type GatewayStats ¶
type GatewayStats struct {
Platforms int `json:"platforms"`
ActiveSessions int `json:"active_sessions"`
TotalProcessed int `json:"total_processed"`
PlatformList []string `json:"platform_list"`
}
Stats returns gateway statistics
type HealthCheckable ¶
type HealthCheckable interface {
CheckHealth() error
}
HealthCheckable is an interface for health-checkable handlers
type HealthStatus ¶
type HealthStatus struct {
Status string `json:"status"`
Timestamp time.Time `json:"timestamp"`
Platforms map[string]PlatformStatus `json:"platforms"`
// Legacy compatibility fields (actively used by platform implementations)
Platform string `json:"platform,omitempty"`
Connected bool `json:"connected,omitempty"`
CallbackOK bool `json:"callback_ok,omitempty"`
CallbackPort int `json:"callback_port,omitempty"`
HTTPClientOK bool `json:"http_client_ok,omitempty"`
TokenValid bool `json:"token_valid,omitempty"`
TokenExpiry *time.Time `json:"token_expiry,omitempty"`
LatencyMs int64 `json:"latency_ms,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
Error string `json:"error,omitempty"`
}
HealthStatus represents the health status of the gateway
type ILinkAPIClient ¶
ILinkAPIClient communicates with the Tencent iLink Bot REST API.
func NewILinkAPIClient ¶
func NewILinkAPIClient(baseURL, token, proxy string) (*ILinkAPIClient, error)
NewILinkAPIClient creates a new iLink API client.
func (*ILinkAPIClient) GetConfig ¶
func (c *ILinkAPIClient) GetConfig(ctx context.Context, req ILinkGetConfigReq) (*ILinkGetConfigResp, error)
GetConfig retrieves bot configuration (typing ticket, etc.).
func (*ILinkAPIClient) GetQRCode ¶
func (c *ILinkAPIClient) GetQRCode(ctx context.Context, botType string) (*ILinkQRCodeResponse, error)
GetQRCode gets a QR code for bot login.
func (*ILinkAPIClient) GetQRCodeStatus ¶
func (c *ILinkAPIClient) GetQRCodeStatus(ctx context.Context, qrcode string) (*ILinkStatusResponse, error)
GetQRCodeStatus polls the QR code scanning status.
func (*ILinkAPIClient) GetUpdates ¶
func (c *ILinkAPIClient) GetUpdates(ctx context.Context, req ILinkGetUpdatesReq) (*ILinkGetUpdatesResp, error)
GetUpdates long-polls for new messages.
func (*ILinkAPIClient) GetUploadURL ¶
func (c *ILinkAPIClient) GetUploadURL(ctx context.Context, req ILinkGetUploadURLReq) (*ILinkGetUploadURLResp, error)
GetUploadURL gets a CDN upload URL for media.
func (*ILinkAPIClient) SendMessage ¶
func (c *ILinkAPIClient) SendMessage(ctx context.Context, req ILinkSendMessageReq) error
SendMessage sends a message to a WeChat user.
func (*ILinkAPIClient) SendTyping ¶
func (c *ILinkAPIClient) SendTyping(ctx context.Context, req ILinkSendTypingReq) error
SendTyping sends a typing indicator.
type ILinkAPIStatus ¶
type ILinkAPIStatus struct {
Ret int `json:"ret,omitempty"`
Errcode int `json:"errcode,omitempty"`
Errmsg string `json:"errmsg,omitempty"`
}
ILinkAPIStatus is the base response status embedded in all API responses.
type ILinkBaseInfo ¶
type ILinkBaseInfo struct {
ChannelVersion string `json:"channel_version,omitempty"`
}
ILinkBaseInfo is attached to every outgoing CGI request.
type ILinkCDNMedia ¶
type ILinkCDNMedia struct {
EncryptQueryParam string `json:"encrypt_query_param,omitempty"`
AesKey string `json:"aes_key,omitempty"` // base64 encoded
EncryptType int `json:"encrypt_type,omitempty"`
FullURL string `json:"full_url,omitempty"`
}
ILinkCDNMedia represents a CDN media reference with encryption.
type ILinkFileItem ¶
type ILinkFileItem struct {
Media *ILinkCDNMedia `json:"media,omitempty"`
FileName string `json:"file_name,omitempty"`
MD5 string `json:"md5,omitempty"`
Len string `json:"len,omitempty"`
}
ILinkFileItem represents a file message item.
type ILinkGetConfigReq ¶
type ILinkGetConfigReq struct {
IlinkUserID string `json:"ilink_user_id,omitempty"`
ContextToken string `json:"context_token,omitempty"`
BaseInfo ILinkBaseInfo `json:"base_info,omitempty"`
}
ILinkGetConfigReq is the request for the getconfig endpoint.
type ILinkGetConfigResp ¶
type ILinkGetConfigResp struct {
ILinkAPIStatus
TypingTicket string `json:"typing_ticket,omitempty"`
}
ILinkGetConfigResp is the response from the getconfig endpoint.
type ILinkGetUpdatesReq ¶
type ILinkGetUpdatesReq struct {
SyncBuf string `json:"sync_buf,omitempty"`
GetUpdatesBuf string `json:"get_updates_buf,omitempty"`
BaseInfo ILinkBaseInfo `json:"base_info,omitempty"`
}
ILinkGetUpdatesReq is the request for the getupdates endpoint.
type ILinkGetUpdatesResp ¶
type ILinkGetUpdatesResp struct {
ILinkAPIStatus
Msgs []ILinkMessage `json:"msgs,omitempty"`
SyncBuf string `json:"sync_buf,omitempty"`
GetUpdatesBuf string `json:"get_updates_buf,omitempty"`
LongpollingTimeoutMs int `json:"longpolling_timeout_ms,omitempty"`
}
ILinkGetUpdatesResp is the response from the getupdates endpoint.
type ILinkGetUploadURLReq ¶
type ILinkGetUploadURLReq struct {
Filekey string `json:"filekey,omitempty"`
MediaType int `json:"media_type,omitempty"`
ToUserID string `json:"to_user_id,omitempty"`
Rawsize int64 `json:"rawsize,omitempty"`
RawfileMD5 string `json:"rawfilemd5,omitempty"`
Filesize int64 `json:"filesize,omitempty"`
ThumbRawsize int64 `json:"thumb_rawsize,omitempty"`
ThumbRawfileMD5 string `json:"thumb_rawfilemd5,omitempty"`
ThumbFilesize int64 `json:"thumb_filesize,omitempty"`
NoNeedThumb bool `json:"no_need_thumb,omitempty"`
Aeskey string `json:"aeskey,omitempty"` // hex-encoded 16-byte AES key
BaseInfo ILinkBaseInfo `json:"base_info,omitempty"`
}
ILinkGetUploadURLReq is the request for the getuploadurl endpoint.
type ILinkGetUploadURLResp ¶
type ILinkGetUploadURLResp struct {
ILinkAPIStatus
UploadParam string `json:"upload_param,omitempty"`
ThumbUploadParam string `json:"thumb_upload_param,omitempty"`
UploadFullURL string `json:"upload_full_url,omitempty"`
}
ILinkGetUploadURLResp is the response from the getuploadurl endpoint.
type ILinkImageItem ¶
type ILinkImageItem struct {
Media *ILinkCDNMedia `json:"media,omitempty"`
ThumbMedia *ILinkCDNMedia `json:"thumb_media,omitempty"`
Aeskey string `json:"aeskey,omitempty"`
Url string `json:"url,omitempty"`
MidSize int64 `json:"mid_size,omitempty"`
ThumbSize int64 `json:"thumb_size,omitempty"`
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbWidth int `json:"thumb_width,omitempty"`
HDSize int64 `json:"hd_size,omitempty"`
}
ILinkImageItem represents an image message item.
type ILinkLoginOpts ¶
type ILinkLoginOpts struct {
// Base URL for the iLink API (default: https://ilinkai.weixin.qq.com/)
BaseURL string
// Bot type (default: "3")
BotType string
// Proxy URL (optional)
Proxy string
// Timeout for the login flow (default: 5 minutes)
Timeout time.Duration
// Silent mode - if true, don't print QR code to terminal (for Web QR mode)
Silent bool
}
ILinkLoginOpts configures the interactive QR login flow.
type ILinkMessage ¶
type ILinkMessage struct {
Seq int `json:"seq,omitempty"`
MessageID int64 `json:"message_id,omitempty"`
FromUserID string `json:"from_user_id,omitempty"`
ToUserID string `json:"to_user_id,omitempty"`
ClientID string `json:"client_id,omitempty"`
CreateTimeMs int64 `json:"create_time_ms,omitempty"`
UpdateTimeMs int64 `json:"update_time_ms,omitempty"`
DeleteTimeMs int64 `json:"delete_time_ms,omitempty"`
SessionID string `json:"session_id,omitempty"`
GroupID string `json:"group_id,omitempty"`
MessageType int `json:"message_type,omitempty"`
MessageState int `json:"message_state,omitempty"`
ItemList []ILinkMessageItem `json:"item_list,omitempty"`
ContextToken string `json:"context_token,omitempty"`
}
ILinkMessage is a WeChat message from the iLink API.
type ILinkMessageItem ¶
type ILinkMessageItem struct {
Type int `json:"type,omitempty"`
CreateTimeMs int64 `json:"create_time_ms,omitempty"`
UpdateTimeMs int64 `json:"update_time_ms,omitempty"`
IsCompleted bool `json:"is_completed,omitempty"`
MsgID string `json:"msg_id,omitempty"`
RefMsg *ILinkRefMessage `json:"ref_msg,omitempty"`
TextItem *ILinkTextItem `json:"text_item,omitempty"`
ImageItem *ILinkImageItem `json:"image_item,omitempty"`
VoiceItem *ILinkVoiceItem `json:"voice_item,omitempty"`
FileItem *ILinkFileItem `json:"file_item,omitempty"`
VideoItem *ILinkVideoItem `json:"video_item,omitempty"`
}
ILinkMessageItem is a single item in a message's item_list.
type ILinkQRCodeResponse ¶
type ILinkQRCodeResponse struct {
Qrcode string `json:"qrcode"`
QrcodeImgContent string `json:"qrcode_img_content"`
}
ILinkQRCodeResponse is the response from get_bot_qrcode.
type ILinkRefMessage ¶
type ILinkRefMessage struct {
MessageItem *ILinkMessageItem `json:"message_item,omitempty"`
Title string `json:"title,omitempty"`
}
ILinkRefMessage represents a referenced/replied-to message.
type ILinkSendMessageReq ¶
type ILinkSendMessageReq struct {
Msg ILinkMessage `json:"msg,omitempty"`
BaseInfo ILinkBaseInfo `json:"base_info,omitempty"`
}
ILinkSendMessageReq is the request for the sendmessage endpoint.
type ILinkSendMessageResp ¶
type ILinkSendMessageResp struct {
ILinkAPIStatus
}
ILinkSendMessageResp is the response from the sendmessage endpoint.
type ILinkSendTypingReq ¶
type ILinkSendTypingReq struct {
IlinkUserID string `json:"ilink_user_id,omitempty"`
TypingTicket string `json:"typing_ticket,omitempty"`
Status int `json:"status,omitempty"` // 1=typing, 2=cancel
BaseInfo ILinkBaseInfo `json:"base_info,omitempty"`
}
ILinkSendTypingReq is the request for the sendtyping endpoint.
type ILinkSendTypingResp ¶
type ILinkSendTypingResp struct {
ILinkAPIStatus
}
ILinkSendTypingResp is the response from the sendtyping endpoint.
type ILinkStatusResponse ¶
type ILinkStatusResponse struct {
Status string `json:"status"` // "wait", "scaned", "confirmed", "expired", "scaned_but_redirect"
BotToken string `json:"bot_token,omitempty"`
IlinkBotID string `json:"ilink_bot_id,omitempty"`
Baseurl string `json:"baseurl,omitempty"`
IlinkUserID string `json:"ilink_user_id,omitempty"`
RedirectHost string `json:"redirect_host,omitempty"`
}
ILinkStatusResponse is the response from get_qrcode_status.
type ILinkTextItem ¶
type ILinkTextItem struct {
Text string `json:"text,omitempty"`
}
ILinkTextItem represents a text message item.
type ILinkVideoItem ¶
type ILinkVideoItem struct {
Media *ILinkCDNMedia `json:"media,omitempty"`
VideoSize int64 `json:"video_size,omitempty"`
PlayLength int `json:"play_length,omitempty"`
VideoMD5 string `json:"video_md5,omitempty"`
ThumbMedia *ILinkCDNMedia `json:"thumb_media,omitempty"`
ThumbSize int64 `json:"thumb_size,omitempty"`
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbWidth int `json:"thumb_width,omitempty"`
}
ILinkVideoItem represents a video message item.
type ILinkVoiceItem ¶
type ILinkVoiceItem struct {
Media *ILinkCDNMedia `json:"media,omitempty"`
EncodeType int `json:"encode_type,omitempty"`
BitsPerSample int `json:"bits_per_sample,omitempty"`
SampleRate int `json:"sample_rate,omitempty"`
Playtime int `json:"playtime,omitempty"`
Text string `json:"text,omitempty"`
}
ILinkVoiceItem represents a voice message item. Text field contains server-side ASR transcription when available.
type LineGateway ¶
type LineGateway struct {
// contains filtered or unexported fields
}
LineGateway implements the LINE Messaging API platform handler
func NewLineGateway ¶
func NewLineGateway(channelSecret, channelToken string) *LineGateway
NewLineGateway creates a new LINE gateway
func (*LineGateway) CheckHealth ¶
func (g *LineGateway) CheckHealth() *HealthStatus
CheckHealth returns health status
func (*LineGateway) Connect ¶
func (g *LineGateway) Connect(ctx context.Context) error
Connect establishes connection to LINE
func (*LineGateway) Disconnect ¶
func (g *LineGateway) Disconnect() error
Disconnect closes the connection
func (*LineGateway) GetGroupMemberProfile ¶
func (g *LineGateway) GetGroupMemberProfile(groupID, userID string) (map[string]interface{}, error)
GetGroupMemberProfile gets group member profile
func (*LineGateway) GetUserProfile ¶
func (g *LineGateway) GetUserProfile(userID string) (map[string]interface{}, error)
GetUserProfile gets user profile information
func (*LineGateway) HandleSlashCommand ¶
func (g *LineGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles commands (not applicable for LINE)
func (*LineGateway) IsConnected ¶ added in v0.3.1
func (g *LineGateway) IsConnected() bool
IsConnected returns whether the gateway is connected
func (*LineGateway) LeaveGroup ¶
func (g *LineGateway) LeaveGroup(groupID string) error
LeaveGroup makes the bot leave a group
func (*LineGateway) LeaveRoom ¶
func (g *LineGateway) LeaveRoom(roomID string) error
LeaveRoom makes the bot leave a room
func (*LineGateway) Receive ¶
func (g *LineGateway) Receive() <-chan Message
Receive returns the message channel
func (*LineGateway) Reply ¶
func (g *LineGateway) Reply(replyToken, text string) error
Reply sends a reply using reply token
func (*LineGateway) Send ¶
func (g *LineGateway) Send(ctx context.Context, resp Response) error
Send sends a push message via LINE
func (*LineGateway) SendImage ¶
func (g *LineGateway) SendImage(to, originalURL, previewURL string) error
SendImage sends an image message
func (*LineGateway) SendLocation ¶
func (g *LineGateway) SendLocation(to, title, address string, lat, lon float64) error
SendLocation sends a location message
func (*LineGateway) SendTemplate ¶
func (g *LineGateway) SendTemplate(to, altText string, template interface{}) error
SendTemplate sends a template message
func (*LineGateway) SendText ¶
func (g *LineGateway) SendText(to, text string) error
SendText sends a text message
type LoginStatus ¶ added in v0.3.1
type LoginStatus struct {
Platform string `json:"platform"`
Status string `json:"status"` // "not_configured", "waiting_qr", "scanning", "confirmed", "error"
Message string `json:"message,omitempty"`
QRCode string `json:"qr_code,omitempty"`
QRStatus string `json:"qr_status,omitempty"`
QRExpires int `json:"qr_expires_in,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
LoginStatus represents the current login status
type MatrixGateway ¶
type MatrixGateway struct {
// contains filtered or unexported fields
}
MatrixGateway implements the Matrix protocol platform handler
func NewMatrixGateway ¶
func NewMatrixGateway(homeserver, userID, accessToken string) *MatrixGateway
NewMatrixGateway creates a new Matrix gateway
func NewMatrixGatewayWithLogin ¶
func NewMatrixGatewayWithLogin(homeserver, userID, password, deviceID string) (*MatrixGateway, error)
NewMatrixGatewayWithLogin creates a Matrix gateway with login
func (*MatrixGateway) CheckHealth ¶
func (g *MatrixGateway) CheckHealth() *HealthStatus
CheckHealth returns health status
func (*MatrixGateway) Connect ¶
func (g *MatrixGateway) Connect(ctx context.Context) error
Connect establishes connection to Matrix homeserver
func (*MatrixGateway) Disconnect ¶
func (g *MatrixGateway) Disconnect() error
Disconnect closes the connection
func (*MatrixGateway) GetJoinedRooms ¶
func (g *MatrixGateway) GetJoinedRooms() ([]string, error)
GetJoinedRooms returns list of joined rooms
func (*MatrixGateway) GetRoomMembers ¶
func (g *MatrixGateway) GetRoomMembers(roomID string) ([]string, error)
GetRoomMembers returns members of a room
func (*MatrixGateway) HandleSlashCommand ¶
func (g *MatrixGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles Matrix commands
func (*MatrixGateway) IsConnected ¶ added in v0.3.1
func (g *MatrixGateway) IsConnected() bool
IsConnected returns whether the gateway is connected
func (*MatrixGateway) JoinRoom ¶
func (g *MatrixGateway) JoinRoom(ctx context.Context, roomIDOrAlias string) error
JoinRoom joins a Matrix room
func (*MatrixGateway) LeaveRoom ¶
func (g *MatrixGateway) LeaveRoom(ctx context.Context, roomID string) error
LeaveRoom leaves a Matrix room
func (*MatrixGateway) Receive ¶
func (g *MatrixGateway) Receive() <-chan Message
Receive returns the message channel
func (*MatrixGateway) Send ¶
func (g *MatrixGateway) Send(ctx context.Context, resp Response) error
Send sends a message to a Matrix room
func (*MatrixGateway) SendFormattedMessage ¶
func (g *MatrixGateway) SendFormattedMessage(ctx context.Context, roomID, body, formattedBody string) error
SendFormattedMessage sends a formatted message (HTML)
func (*MatrixGateway) SetTypingIndicator ¶
func (g *MatrixGateway) SetTypingIndicator(roomID string, isTyping bool, timeout time.Duration) error
SetTypingIndicator sends a typing indicator
func (*MatrixGateway) UploadContent ¶
func (g *MatrixGateway) UploadContent(content []byte, contentType, filename string) (string, error)
UploadContent uploads media content
type MediaAttachment ¶
type MediaAttachment struct {
Type string `json:"type"` // "image", "video", "audio", "file"
URL string `json:"url"` // 下载URL或本地路径
MimeType string `json:"mime_type,omitempty"`
Filename string `json:"filename,omitempty"`
Caption string `json:"caption,omitempty"`
Size int64 `json:"size,omitempty"`
}
MediaAttachment represents a media file attachment
type Message ¶
type Message struct {
ID string `json:"id"`
Platform string `json:"platform"`
ChannelID string `json:"channel_id"`
UserID string `json:"user_id"`
Content string `json:"content"`
Role string `json:"role,omitempty"`
From string `json:"from,omitempty"`
Timestamp time.Time `json:"timestamp"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
// 媒体附件列表
MediaURLs []MediaAttachment `json:"media_urls,omitempty"`
}
Message represents an incoming or outgoing message
type Middleware ¶
type Middleware interface {
// Process processes a message and returns whether to continue
Process(msg *Message) (bool, error)
Name() string
}
Middleware defines a message processing middleware
type MiddlewareFunc ¶
MiddlewareFunc is a function-based middleware
func (MiddlewareFunc) Name ¶
func (f MiddlewareFunc) Name() string
type PlatformHandler ¶
type PlatformHandler interface {
// Connect establishes connection to the platform
Connect(ctx context.Context) error
// Disconnect closes the connection
Disconnect() error
// Send sends a message
Send(ctx context.Context, resp Response) error
// Receive returns a channel of incoming messages
Receive() <-chan Message
// HandleSlashCommand handles a slash command
HandleSlashCommand(cmd string, msg Message) (Response, error)
// Name returns the platform name
Name() string
// CheckHealth returns detailed health status
CheckHealth() *HealthStatus
// IsConnected returns whether the platform is connected
IsConnected() bool
}
PlatformHandler defines the interface for platform implementations
type PlatformQRGenerator ¶ added in v0.4.0
type PlatformQRGenerator interface {
GenerateQRCode(ctx context.Context) (qrData string, err error)
PollQRStatus(ctx context.Context, qrData string) (status string, err error)
}
PlatformQRGenerator defines the interface for platforms that can generate QR codes
type PlatformStatus ¶
type PlatformStatus struct {
Name string `json:"name"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
}
PlatformStatus represents the status of a platform
type QQGateway ¶
type QQGateway struct {
// contains filtered or unexported fields
}
QQGateway implements the QQ platform handler
func NewQQGateway ¶
NewQQGateway creates a new QQ gateway
func (*QQGateway) CheckHealth ¶
func (g *QQGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for QQ gateway
func (*QQGateway) Disconnect ¶
Disconnect closes the connection
func (*QQGateway) HandleSlashCommand ¶
HandleSlashCommand handles a slash command
func (*QQGateway) IsConnected ¶
IsConnected checks if connected to QQ
func (*QQGateway) SetCallbackPort ¶
SetCallbackPort sets the callback server port
type QRCodeAPIResponse ¶ added in v0.3.1
type QRCodeAPIResponse struct {
ID string `json:"id"`
Platform string `json:"platform"`
Status string `json:"status"`
QRCode string `json:"qr_code,omitempty"` // base64 encoded PNG
Message string `json:"message,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresIn int `json:"expires_in"` // seconds remaining
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
QRCodeAPIResponse represents QR code data for API response
type QRCodeHandler ¶ added in v0.3.1
type QRCodeHandler interface {
// StartQRLogin initiates QR code login and returns the QR data
StartQRLogin(ctx context.Context) (string, error)
// GetLoginStatus returns the current login status
GetLoginStatus() string
// IsLoggedIn returns true if successfully logged in
IsLoggedIn() bool
}
QRCodeHandler defines the interface for platforms that support QR login
type QRCodeManager ¶ added in v0.3.1
type QRCodeManager struct {
// contains filtered or unexported fields
}
QRCodeManager handles QR code generation and login for all platforms
func GetQRManager ¶ added in v0.3.1
func GetQRManager() *QRCodeManager
GetQRManager returns the global QR code manager instance
func (*QRCodeManager) CreateSession ¶ added in v0.3.1
func (m *QRCodeManager) CreateSession(platform string, qrData string, qrImage string) (*QRCodeSession, error)
CreateSession creates a new QR code session for a platform qrData is the raw QR data string (used for status polling) qrImage is an optional base64 image (if empty, will be generated from qrData)
func (*QRCodeManager) GenerateDingTalkQR ¶ added in v0.4.0
func (m *QRCodeManager) GenerateDingTalkQR(ctx context.Context, appKey, appSecret, redirectURI string) (*QRCodeSession, error)
GenerateDingTalkQR generates a DingTalk QR code for login
func (*QRCodeManager) GenerateFeishuQR ¶ added in v0.4.0
func (m *QRCodeManager) GenerateFeishuQR(ctx context.Context, appID, appSecret, redirectURI string) (*QRCodeSession, error)
GenerateFeishuQR generates a Feishu (Lark) QR code for login
func (*QRCodeManager) GenerateWeComQR ¶ added in v0.4.0
func (m *QRCodeManager) GenerateWeComQR(ctx context.Context, corpID, agentID, redirectURI string) (*QRCodeSession, error)
GenerateWeComQR generates a WeCom QR code for login
func (*QRCodeManager) GenerateWhatsAppQR ¶ added in v0.4.0
func (m *QRCodeManager) GenerateWhatsAppQR(ctx context.Context, mode string) (*QRCodeSession, error)
GenerateWhatsAppQR generates a WhatsApp QR code for login
func (*QRCodeManager) GetSession ¶ added in v0.3.1
func (m *QRCodeManager) GetSession(platform string) *QRCodeSession
GetSession returns the current QR code session for a platform
func (*QRCodeManager) ListSessions ¶ added in v0.3.1
func (m *QRCodeManager) ListSessions() []*QRCodeSession
ListSessions returns all active QR code sessions
func (*QRCodeManager) UpdateSessionStatus ¶ added in v0.3.1
func (m *QRCodeManager) UpdateSessionStatus(platform string, status string, message string)
UpdateSessionStatus updates the status of a QR code session
type QRCodeResponse ¶ added in v0.3.0
type QRCodeResponse struct {
QRCode string `json:"qr_code"`
Expiry int `json:"expires_in_seconds"`
}
QRCodeResponse represents QR code data for API response
type QRCodeSession ¶ added in v0.3.1
type QRCodeSession struct {
ID string `json:"id"`
Platform string `json:"platform"`
Status string `json:"status"` // pending, scanning, confirmed, expired, error
QRCode string `json:"qr_code,omitempty"` // base64 encoded PNG
QRData string `json:"qr_data,omitempty"` // raw QR data string
Message string `json:"message,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
QRCodeSession represents an active QR code login session
func (*QRCodeSession) ToAPIResponse ¶ added in v0.3.1
func (s *QRCodeSession) ToAPIResponse() *QRCodeAPIResponse
ToAPIResponse converts a QRCodeSession to API response format
func (*QRCodeSession) ToJSON ¶ added in v0.4.0
func (s *QRCodeSession) ToJSON() string
ToJSON converts session to JSON
type QRPollContext ¶ added in v0.4.0
type QRPollContext struct {
Cancel context.CancelFunc
Timeout time.Duration
}
QRPollContext holds the context for QR status polling
type RateLimitMiddleware ¶
type RateLimitMiddleware struct {
// contains filtered or unexported fields
}
RateLimitMiddleware limits message rate per user
func NewRateLimitMiddleware ¶
func NewRateLimitMiddleware(maxCount int, window time.Duration) *RateLimitMiddleware
NewRateLimitMiddleware creates a new rate limit middleware
func (*RateLimitMiddleware) Name ¶
func (m *RateLimitMiddleware) Name() string
type Response ¶
type Response struct {
MessageID string `json:"message_id"`
Content string `json:"content"`
ChannelID string `json:"channel_id"`
Error error `json:"error,omitempty"`
}
Response represents a response to a message
type RichMenu ¶
type RichMenu struct {
Size richMenuSize `json:"size"`
Selected bool `json:"selected"`
Name string `json:"name"`
ChatBarText string `json:"chatBarText"`
Areas []struct {
Bounds richMenuBounds `json:"bounds"`
Action interface{} `json:"action"`
} `json:"areas"`
}
RichMenu represents LINE rich menu
type SensitiveWordMiddleware ¶
type SensitiveWordMiddleware struct {
// contains filtered or unexported fields
}
SensitiveWordMiddleware filters sensitive words
func NewSensitiveWordMiddleware ¶
func NewSensitiveWordMiddleware(words []string) *SensitiveWordMiddleware
NewSensitiveWordMiddleware creates a new sensitive word middleware
func (*SensitiveWordMiddleware) Name ¶
func (m *SensitiveWordMiddleware) Name() string
type Session ¶
type Session struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Platform string `json:"platform"`
CreatedAt time.Time `json:"created_at"`
LastActive time.Time `json:"last_active"`
History []Message `json:"history,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheReadTokens int `json:"cache_read_tokens"`
// contains filtered or unexported fields
}
Session represents a user session
type SlackGateway ¶
type SlackGateway struct {
// contains filtered or unexported fields
}
SlackGateway implements the Slack platform handler
func NewSlackGateway ¶
func NewSlackGateway(botToken, signingSecret string) *SlackGateway
NewSlackGateway creates a new Slack gateway
func (*SlackGateway) CheckHealth ¶
func (g *SlackGateway) CheckHealth() *HealthStatus
CheckHealth returns health status
func (*SlackGateway) Connect ¶
func (g *SlackGateway) Connect(ctx context.Context) error
Connect establishes connection to Slack
func (*SlackGateway) Disconnect ¶
func (g *SlackGateway) Disconnect() error
Disconnect closes the connection
func (*SlackGateway) HandleSlashCommand ¶
func (g *SlackGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles slash commands
func (*SlackGateway) IsConnected ¶ added in v0.3.1
func (g *SlackGateway) IsConnected() bool
IsConnected returns whether the gateway is connected
func (*SlackGateway) Receive ¶
func (g *SlackGateway) Receive() <-chan Message
Receive returns the message channel
func (*SlackGateway) Send ¶
func (g *SlackGateway) Send(ctx context.Context, resp Response) error
Send sends a message to Slack
func (*SlackGateway) SetChannelFilter ¶
func (g *SlackGateway) SetChannelFilter(allowed, blocked []string)
SetChannelFilter sets the channel allowlist and blocklist
type TelegramConfig ¶
type TelegramConfig struct {
Token string
AdminUsers []int64 // List of admin user IDs
AllowGroups bool // Allow bot in groups
StreamingReply bool // Enable streaming reply for long messages
AllowedChannels []string `json:"allowed_channels,omitempty"` // Whitelist of channel/chat IDs
BlockedChannels []string `json:"blocked_channels,omitempty"` // Blacklist of channel/chat IDs
}
TelegramConfig holds Telegram-specific configuration
type TelegramHandler ¶
type TelegramHandler struct {
// contains filtered or unexported fields
}
TelegramHandler implements PlatformHandler for Telegram
func NewTelegramHandler ¶
func NewTelegramHandler(token string, config *TelegramConfig) (*TelegramHandler, error)
NewTelegramHandler creates a new Telegram platform handler
func (*TelegramHandler) CheckHealth ¶
func (t *TelegramHandler) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for Telegram gateway
func (*TelegramHandler) Connect ¶
func (t *TelegramHandler) Connect(ctx context.Context) error
Connect establishes connection to Telegram
func (*TelegramHandler) Disconnect ¶
func (t *TelegramHandler) Disconnect() error
Disconnect closes the connection
func (*TelegramHandler) HandleSlashCommand ¶
func (t *TelegramHandler) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles a slash command
func (*TelegramHandler) IsConnected ¶
func (t *TelegramHandler) IsConnected() bool
IsConnected checks if connected to Telegram
func (*TelegramHandler) Name ¶
func (t *TelegramHandler) Name() string
Name returns the platform name
func (*TelegramHandler) Receive ¶
func (t *TelegramHandler) Receive() <-chan Message
Receive returns a channel of incoming messages
type WeChatCallbackGateway ¶
type WeChatCallbackGateway struct {
// contains filtered or unexported fields
}
WeChatCallbackGateway implements the WeChat Official Account callback mode This mode requires: - A verified service account (已认证服务号) - A public IP address for the callback server - Properly configured callback URL in WeChat admin console
func NewWeChatCallbackGateway ¶
func NewWeChatCallbackGateway(appID, appSecret, token, aesKey string) *WeChatCallbackGateway
NewWeChatCallbackGateway creates a new WeChat callback mode gateway
func (*WeChatCallbackGateway) CheckHealth ¶
func (g *WeChatCallbackGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for WeChat callback gateway
func (*WeChatCallbackGateway) Connect ¶
func (g *WeChatCallbackGateway) Connect(ctx context.Context) error
Connect establishes connection to WeChat callback server
func (*WeChatCallbackGateway) Disconnect ¶
func (g *WeChatCallbackGateway) Disconnect() error
Disconnect closes the connection
func (*WeChatCallbackGateway) GetAccessToken ¶
func (g *WeChatCallbackGateway) GetAccessToken() string
GetAccessToken returns the current access token
func (*WeChatCallbackGateway) HandleSlashCommand ¶
func (g *WeChatCallbackGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles a slash command
func (*WeChatCallbackGateway) IsConnected ¶
func (g *WeChatCallbackGateway) IsConnected() bool
IsConnected checks if connected to WeChat
func (*WeChatCallbackGateway) Name ¶
func (g *WeChatCallbackGateway) Name() string
Name returns the platform name
func (*WeChatCallbackGateway) Receive ¶
func (g *WeChatCallbackGateway) Receive() <-chan Message
Receive returns a channel of incoming messages
func (*WeChatCallbackGateway) RefreshToken ¶
func (g *WeChatCallbackGateway) RefreshToken() error
RefreshToken forces a token refresh
func (*WeChatCallbackGateway) Send ¶
func (g *WeChatCallbackGateway) Send(ctx context.Context, resp Response) error
Send sends a message via WeChat API
func (*WeChatCallbackGateway) SendText ¶
func (g *WeChatCallbackGateway) SendText(openID, text string) error
SendText sends a text message via WeChat API
func (*WeChatCallbackGateway) SetCallbackPort ¶
func (g *WeChatCallbackGateway) SetCallbackPort(port int)
SetCallbackPort sets the callback server port
type WeChatILinkConfig ¶
type WeChatILinkConfig struct {
// Bot token obtained from QR code login
Token string `json:"token"`
// Base URL for iLink API (default: https://ilinkai.weixin.qq.com/)
BaseURL string `json:"base_url"`
// CDN base URL for media upload/download (default: https://novac2c.cdn.weixin.qq.com/c2c)
CDNBaseURL string `json:"cdn_base_url"`
// Proxy URL for HTTP requests (optional)
Proxy string `json:"proxy"`
// Data directory for persisting sync buffers and context tokens
DataDir string `json:"data_dir"`
// Auto-login: if true, start QR login flow when no token is available
AutoLogin bool `json:"auto_login"`
// Bot type (default: "3")
BotType string `json:"bot_type"`
// Max reconnection attempts (0 = unlimited)
MaxReconnectAttempts int `json:"max_reconnect_attempts"`
// Whether to enable media download for inbound messages
EnableMediaDownload bool `json:"enable_media_download"`
}
WeChatILinkConfig holds configuration for the WeChat iLink Bot gateway.
type WeChatILinkGateway ¶
type WeChatILinkGateway struct {
// contains filtered or unexported fields
}
WeChatILinkGateway implements the WeChat iLink Bot API for go-magic.
Architecture:
- Connect() starts the long-poll loop that receives messages via GetUpdates
- Messages are parsed and forwarded to the msgCh channel
- Send() sends messages via the SendMessage API
- Supports typing indicators via StartTyping/StopTyping
- Supports media upload/download via CDN
- Supports QR code login flow
func NewWeChatILinkGateway ¶
func NewWeChatILinkGateway(cfg WeChatILinkConfig) *WeChatILinkGateway
NewWeChatILinkGateway creates a new WeChat iLink Bot gateway.
func (*WeChatILinkGateway) CheckHealth ¶
func (g *WeChatILinkGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status.
func (*WeChatILinkGateway) Connect ¶
func (g *WeChatILinkGateway) Connect(ctx context.Context) error
Connect establishes connection to the WeChat iLink Bot API.
func (*WeChatILinkGateway) Disconnect ¶
func (g *WeChatILinkGateway) Disconnect() error
Disconnect closes the connection and stops all goroutines.
func (*WeChatILinkGateway) HandleSlashCommand ¶
func (g *WeChatILinkGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles slash commands.
func (*WeChatILinkGateway) IsConnected ¶
func (g *WeChatILinkGateway) IsConnected() bool
IsConnected checks whether the gateway is running and has a valid token.
func (*WeChatILinkGateway) Name ¶
func (g *WeChatILinkGateway) Name() string
Name returns the platform name.
func (*WeChatILinkGateway) Receive ¶
func (g *WeChatILinkGateway) Receive() <-chan Message
Receive returns a channel of incoming messages.
func (*WeChatILinkGateway) Send ¶
func (g *WeChatILinkGateway) Send(ctx context.Context, resp Response) error
Send sends a text message to a WeChat user.
func (*WeChatILinkGateway) SendText ¶
func (g *WeChatILinkGateway) SendText(ctx context.Context, toUserID, text string) error
SendText sends a text message directly to a user.
func (*WeChatILinkGateway) StartTyping ¶
func (g *WeChatILinkGateway) StartTyping(ctx context.Context, chatID string) (func(), error)
StartTyping starts a typing indicator for the given user. Returns a stop function that cancels the typing indicator.
func (*WeChatILinkGateway) StopTyping ¶
func (g *WeChatILinkGateway) StopTyping(chatID string)
StopTyping stops the typing indicator for the given user.
type WeChatMessage ¶
type WeChatMessage struct {
ToUserName string `xml:"ToUserName"`
FromUserName string `xml:"FromUserName"`
CreateTime int64 `xml:"CreateTime"`
MsgType string `xml:"MsgType"`
Content string `xml:"Content"`
MsgID string `xml:"MsgId"`
Encrypt string `xml:"Encrypt"`
// Media fields for various message types
MediaID string `xml:"MediaId,omitempty"` // For image, voice, video, shortvideo
PicURL string `xml:"PicUrl,omitempty"` // For image
Format string `xml:"Format,omitempty"` // For voice (amr, mp3)
Recognition string `xml:"Recognition,omitempty"` // For voice (ASR result)
ThumbMediaID string `xml:"ThumbMediaId,omitempty"` // For video, music
LocationX string `xml:"Location_X,omitempty"`
LocationY string `xml:"Location_Y,omitempty"`
Scale string `xml:"Scale,omitempty"`
Label string `xml:"Label,omitempty"`
Title string `xml:"Title,omitempty"`
Description string `xml:"Description,omitempty"`
URL string `xml:"Url,omitempty"`
}
WeChatMessage represents a WeChat message
type WeChatQRGateway ¶
type WeChatQRGateway struct {
// contains filtered or unexported fields
}
WeChatQRGateway implements WeChat Official Account QR code login mode This mode uses the WeChat Open Platform OAuth2 flow for easier setup Requirements: - WeChat Official Account (订阅号/服务号都可以) - No public IP required - No verified service account required
func NewWeChatGateway ¶
func NewWeChatGateway(appID, appSecret, token, aesKey string) *WeChatQRGateway
Backward compatibility: NewWeChatGateway creates a QR gateway by default This is for API compatibility with existing code
func NewWeChatQRGateway ¶
func NewWeChatQRGateway(appID, appSecret string) *WeChatQRGateway
NewWeChatQRGateway creates a new WeChat QR code login gateway
func (*WeChatQRGateway) CheckHealth ¶
func (g *WeChatQRGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for WeChat QR gateway
func (*WeChatQRGateway) Connect ¶
func (g *WeChatQRGateway) Connect(ctx context.Context) error
Connect establishes connection with QR code login
func (*WeChatQRGateway) Disconnect ¶
func (g *WeChatQRGateway) Disconnect() error
Disconnect closes the connection
func (*WeChatQRGateway) GetOpenID ¶
func (g *WeChatQRGateway) GetOpenID() string
GetOpenID returns the authenticated user's OpenID
func (*WeChatQRGateway) HandleSlashCommand ¶
func (g *WeChatQRGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles a slash command
func (*WeChatQRGateway) IsAuthenticated ¶
func (g *WeChatQRGateway) IsAuthenticated() bool
IsAuthenticated returns whether the gateway is authenticated
func (*WeChatQRGateway) IsConnected ¶
func (g *WeChatQRGateway) IsConnected() bool
IsConnected checks if connected to WeChat
func (*WeChatQRGateway) Name ¶
func (g *WeChatQRGateway) Name() string
Name returns the platform name
func (*WeChatQRGateway) Receive ¶
func (g *WeChatQRGateway) Receive() <-chan Message
Receive returns a channel of incoming messages
func (*WeChatQRGateway) Send ¶
func (g *WeChatQRGateway) Send(ctx context.Context, resp Response) error
Send sends a message via WeChat API
func (*WeChatQRGateway) SendText ¶
func (g *WeChatQRGateway) SendText(openID, text string) error
SendText sends a text message via WeChat customer service API
func (*WeChatQRGateway) SetQRCallback ¶
func (g *WeChatQRGateway) SetQRCallback(cb func(url string))
SetQRCallback sets a callback for QR code URL (for CLI display or API push)
func (*WeChatQRGateway) SetQRCallbackPort ¶
func (g *WeChatQRGateway) SetQRCallbackPort(port int)
SetQRCallbackPort sets the callback server port
func (*WeChatQRGateway) TriggerReauth ¶
func (g *WeChatQRGateway) TriggerReauth(ctx context.Context)
TriggerReauth starts a new QR authentication flow
type WeChatSession ¶
type WeChatSession struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
OpenID string `json:"openid"`
ExpiresAt time.Time `json:"expires_at"`
RefreshAt time.Time `json:"refresh_at"`
LastActiveTime time.Time `json:"last_active"`
}
WeChatSession represents the OAuth session data
type WeComAppGateway ¶
type WeComAppGateway struct {
// contains filtered or unexported fields
}
WeComAppGateway implements WeCom (Enterprise WeChat) application message mode This mode requires: - A verified enterprise account (已认证企业) - Application credentials (corpID + secret) - Properly configured callback URL in WeCom admin console
func NewWeComAppGateway ¶
func NewWeComAppGateway(corpID, agentID, secret string) *WeComAppGateway
NewWeComAppGateway creates a new WeCom application message mode gateway
func (*WeComAppGateway) CheckHealth ¶
func (g *WeComAppGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for WeCom App gateway
func (*WeComAppGateway) Connect ¶
func (g *WeComAppGateway) Connect(ctx context.Context) error
Connect establishes connection to WeCom
func (*WeComAppGateway) Disconnect ¶
func (g *WeComAppGateway) Disconnect() error
Disconnect closes the connection
func (*WeComAppGateway) GetAccessToken ¶
func (g *WeComAppGateway) GetAccessToken() string
GetAccessToken returns the current access token
func (*WeComAppGateway) HandleSlashCommand ¶
func (g *WeComAppGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles a slash command
func (*WeComAppGateway) IsConnected ¶
func (g *WeComAppGateway) IsConnected() bool
IsConnected checks if connected to WeCom
func (*WeComAppGateway) Name ¶
func (g *WeComAppGateway) Name() string
Name returns the platform name
func (*WeComAppGateway) Receive ¶
func (g *WeComAppGateway) Receive() <-chan Message
Receive returns a channel of incoming messages
func (*WeComAppGateway) Reconnect ¶
func (g *WeComAppGateway) Reconnect(ctx context.Context) error
Reconnect attempts to reconnect with exponential backoff
func (*WeComAppGateway) Send ¶
func (g *WeComAppGateway) Send(ctx context.Context, resp Response) error
Send sends a message (enhanced to support rich content)
func (*WeComAppGateway) SendText ¶
func (g *WeComAppGateway) SendText(userID, content string) error
SendText sends a text message
func (*WeComAppGateway) SendToUser ¶
func (g *WeComAppGateway) SendToUser(userID, content string) error
SendToUser sends a message to a user
func (*WeComAppGateway) SetAESKey ¶
func (g *WeComAppGateway) SetAESKey(key string)
SetAESKey sets the AES key for callback encryption
func (*WeComAppGateway) SetCallbackPort ¶
func (g *WeComAppGateway) SetCallbackPort(port int)
SetCallbackPort sets the callback server port
func (*WeComAppGateway) SetChannelFilter ¶
func (g *WeComAppGateway) SetChannelFilter(allowed, blocked []string)
SetChannelFilter sets the channel allowlist and blocklist
type WeComQRGateway ¶
type WeComQRGateway struct {
// contains filtered or unexported fields
}
WeComQRGateway implements WeCom (Enterprise WeChat) QR code login mode This mode uses the WeCom Open Platform OAuth2 flow for easier setup Requirements: - A WeCom enterprise account (任何版本都可以) - No public IP required - No verified enterprise required
func NewWeComGateway ¶
func NewWeComGateway(corpID, agentID, secret string) *WeComQRGateway
Backward compatibility: NewWeComGateway creates a QR gateway by default This is for API compatibility with existing code
func NewWeComQRGateway ¶
func NewWeComQRGateway(corpID, agentID, secret string) *WeComQRGateway
NewWeComQRGateway creates a new WeCom QR code login gateway
func (*WeComQRGateway) CheckHealth ¶
func (g *WeComQRGateway) CheckHealth() *HealthStatus
CheckHealth returns detailed health status for WeCom QR gateway
func (*WeComQRGateway) Connect ¶
func (g *WeComQRGateway) Connect(ctx context.Context) error
Connect establishes connection with QR code login
func (*WeComQRGateway) Disconnect ¶
func (g *WeComQRGateway) Disconnect() error
Disconnect closes the connection
func (*WeComQRGateway) GetUserID ¶
func (g *WeComQRGateway) GetUserID() string
GetUserID returns the authenticated user's ID
func (*WeComQRGateway) GetUserName ¶
func (g *WeComQRGateway) GetUserName() string
GetUserName returns the authenticated user's name
func (*WeComQRGateway) HandleSlashCommand ¶
func (g *WeComQRGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles a slash command
func (*WeComQRGateway) IsAuthenticated ¶
func (g *WeComQRGateway) IsAuthenticated() bool
IsAuthenticated returns whether the gateway is authenticated
func (*WeComQRGateway) IsConnected ¶
func (g *WeComQRGateway) IsConnected() bool
IsConnected checks if connected to WeCom
func (*WeComQRGateway) Receive ¶
func (g *WeComQRGateway) Receive() <-chan Message
Receive returns a channel of incoming messages
func (*WeComQRGateway) Send ¶
func (g *WeComQRGateway) Send(ctx context.Context, resp Response) error
Send sends a message via WeCom API
func (*WeComQRGateway) SendText ¶
func (g *WeComQRGateway) SendText(userID, content string) error
SendText sends a text message
func (*WeComQRGateway) SetChannelFilter ¶
func (g *WeComQRGateway) SetChannelFilter(allowed, blocked []string)
SetChannelFilter sets the channel allowlist and blocklist
func (*WeComQRGateway) SetQRCallback ¶
func (g *WeComQRGateway) SetQRCallback(cb func(url string))
SetQRCallback sets a callback for QR code URL (for CLI display or API push)
func (*WeComQRGateway) SetQRCallbackPort ¶
func (g *WeComQRGateway) SetQRCallbackPort(port int)
SetQRCallbackPort sets the callback server port
func (*WeComQRGateway) TriggerReauth ¶
func (g *WeComQRGateway) TriggerReauth(ctx context.Context)
TriggerReauth starts a new QR authentication flow
type WeComSession ¶
type WeComSession struct {
UserID string `json:"user_id"`
UserName string `json:"user_name"`
UserDeptID int `json:"user_dept_id"`
AccessToken string `json:"access_token"`
ExpiresAt time.Time `json:"expires_at"`
LastActive time.Time `json:"last_active"`
}
WeComSession represents the QR login session data
type WhatsAppBusinessGateway ¶
type WhatsAppBusinessGateway struct {
// contains filtered or unexported fields
}
WhatsAppBusinessGateway implements WhatsApp Business API (webhook-based) For personal WhatsApp with QR login, use WhatsAppGateway instead.
func NewWhatsAppBusinessGateway ¶
func NewWhatsAppBusinessGateway(phoneNumberID, accessToken, appSecret, verifyToken string) *WhatsAppBusinessGateway
NewWhatsAppBusinessGateway creates a WhatsApp Business API gateway (legacy) Deprecated: Use NewWhatsAppGateway for personal accounts with QR login
func (*WhatsAppBusinessGateway) CheckHealth ¶
func (g *WhatsAppBusinessGateway) CheckHealth() *HealthStatus
CheckHealth returns health status
func (*WhatsAppBusinessGateway) Connect ¶
func (g *WhatsAppBusinessGateway) Connect(ctx context.Context) error
Connect establishes connection to WhatsApp Business API
func (*WhatsAppBusinessGateway) Disconnect ¶
func (g *WhatsAppBusinessGateway) Disconnect() error
Disconnect closes the connection
func (*WhatsAppBusinessGateway) HandleSlashCommand ¶
func (g *WhatsAppBusinessGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles commands
func (*WhatsAppBusinessGateway) IsConnected ¶ added in v0.3.1
func (g *WhatsAppBusinessGateway) IsConnected() bool
IsConnected returns whether the gateway is connected
func (*WhatsAppBusinessGateway) Name ¶
func (g *WhatsAppBusinessGateway) Name() string
Name returns the platform name
func (*WhatsAppBusinessGateway) Receive ¶
func (g *WhatsAppBusinessGateway) Receive() <-chan Message
Receive returns the message channel
func (*WhatsAppBusinessGateway) Send ¶
func (g *WhatsAppBusinessGateway) Send(ctx context.Context, resp Response) error
Send sends a message via WhatsApp Business API
func (*WhatsAppBusinessGateway) SetChannelFilter ¶
func (g *WhatsAppBusinessGateway) SetChannelFilter(allowed, blocked []string)
SetChannelFilter sets the channel allowlist and blocklist for WhatsApp Business
type WhatsAppGateway ¶
type WhatsAppGateway struct {
// contains filtered or unexported fields
}
WhatsAppGateway implements WhatsApp via whatsmeow (personal account, QR code login)
func NewWhatsAppGateway ¶
func NewWhatsAppGateway(dataDir string) *WhatsAppGateway
NewWhatsAppGateway creates a new WhatsApp gateway with QR login support
func (*WhatsAppGateway) CheckHealth ¶
func (g *WhatsAppGateway) CheckHealth() *HealthStatus
CheckHealth returns health status
func (*WhatsAppGateway) Connect ¶
func (g *WhatsAppGateway) Connect(ctx context.Context) error
Connect establishes connection with QR code login
func (*WhatsAppGateway) Disconnect ¶
func (g *WhatsAppGateway) Disconnect() error
Disconnect closes the connection
func (*WhatsAppGateway) ExportSession ¶
func (g *WhatsAppGateway) ExportSession() ([]byte, error)
ExportSession exports the current session as JSON (for backup)
func (*WhatsAppGateway) GetContactName ¶
func (g *WhatsAppGateway) GetContactName(jid types.JID) string
GetContactName resolves a JID to a contact name
func (*WhatsAppGateway) GetLatestQR ¶ added in v0.3.0
func (g *WhatsAppGateway) GetLatestQR() string
GetLatestQR returns the most recent QR code data
func (*WhatsAppGateway) GetLoginStatus ¶ added in v0.3.1
func (g *WhatsAppGateway) GetLoginStatus() string
GetLoginStatus returns the current login status
func (*WhatsAppGateway) GetQRCode ¶
func (g *WhatsAppGateway) GetQRCode() string
GetQRCode returns the current QR code for login (if waiting) This is called after Connect() if the session is new
func (*WhatsAppGateway) GetQRCodeForAPI ¶ added in v0.3.0
func (g *WhatsAppGateway) GetQRCodeForAPI() *QRCodeResponse
GetQRCodeForAPI returns QR code data suitable for web display
func (*WhatsAppGateway) HandleSlashCommand ¶
func (g *WhatsAppGateway) HandleSlashCommand(cmd string, msg Message) (Response, error)
HandleSlashCommand handles commands
func (*WhatsAppGateway) IsConnected ¶ added in v0.3.1
func (g *WhatsAppGateway) IsConnected() bool
IsConnected returns whether the gateway is connected
func (*WhatsAppGateway) IsLoggedIn ¶
func (g *WhatsAppGateway) IsLoggedIn() bool
IsLoggedIn returns whether the client is logged in
func (*WhatsAppGateway) Name ¶
func (g *WhatsAppGateway) Name() string
Name returns the platform name
func (*WhatsAppGateway) Receive ¶
func (g *WhatsAppGateway) Receive() <-chan Message
Receive returns the message channel
func (*WhatsAppGateway) RequestAppState ¶
func (g *WhatsAppGateway) RequestAppState() error
RequestAppState requests full app state sync (contacts, etc.)
func (*WhatsAppGateway) Send ¶
func (g *WhatsAppGateway) Send(ctx context.Context, resp Response) error
Send sends a message via WhatsApp
func (*WhatsAppGateway) SendPresence ¶
func (g *WhatsAppGateway) SendPresence(presence types.Presence) error
SendPresence updates the user's presence (available/unavailable/composing)
func (*WhatsAppGateway) SendTyping ¶
func (g *WhatsAppGateway) SendTyping(chatJID types.JID) error
SendTyping sends a typing indicator to a chat
func (*WhatsAppGateway) SetChannelFilter ¶
func (g *WhatsAppGateway) SetChannelFilter(allowed, blocked []string)
SetChannelFilter sets the channel allowlist and blocklist
func (*WhatsAppGateway) SetQRCallback ¶
func (g *WhatsAppGateway) SetQRCallback(cb func(qr string))
SetQRCallback sets a callback for QR code events (for CLI display or API push)
func (*WhatsAppGateway) StartQRLogin ¶ added in v0.3.1
func (g *WhatsAppGateway) StartQRLogin(ctx context.Context) (string, error)
StartQRLogin initiates QR code login and returns the QR data string