Documentation
¶
Index ¶
Constants ¶
const ( WsCmdSubscribe = "aibot_subscribe" WsCmdHeartbeat = "ping" WsCmdCallback = "aibot_msg_callback" WsCmdEventCallback = "aibot_event_callback" WsCmdResponse = "aibot_respond_msg" WsCmdSendMsg = "aibot_send_msg" WsCmdUploadMediaInit = "aibot_upload_media_init" WsCmdUploadMediaChunk = "aibot_upload_media_chunk" WsCmdUploadMediaFinish = "aibot_upload_media_finish" )
Protocol command constants — WeCom AI Bot WebSocket wire commands.
Variables ¶
This section is empty.
Functions ¶
func DecryptFile ¶
DecryptFile decrypts a WeCom media file using AES-256-CBC.
aesKeyBase64 is the Base64-encoded 256-bit (32-byte) key provided in the message body (image.aeskey / file.aeskey). The IV is the first 16 bytes of the decoded key. Padding is PKCS#7 with a 32-byte block size — WeCom pads to 32-byte multiples rather than the standard AES 16-byte block size, so auto-padding must be disabled and padding removed manually.
func NewPlatform ¶
NewPlatform constructs a WeComPlatform from configuration.
Types ¶
type WeComPlatform ¶
type WeComPlatform struct {
// contains filtered or unexported fields
}
WeComPlatform implements platform.Platform for WeCom AI Bot.
func (*WeComPlatform) ID ¶
func (p *WeComPlatform) ID() string
func (*WeComPlatform) Receiver ¶
func (p *WeComPlatform) Receiver() platform.PlatformReceiverAdapter
func (*WeComPlatform) Sender ¶
func (p *WeComPlatform) Sender() platform.PlatformSenderAdapter
type WeComReceiver ¶
type WeComReceiver struct {
// contains filtered or unexported fields
}
WeComReceiver connects to WeCom via WebSocket and dispatches inbound messages.
func (*WeComReceiver) Start ¶
func (r *WeComReceiver) Start(ctx context.Context, dispatch func(platform.InboundMessage)) error
Start begins receiving messages and blocks until ctx is cancelled.
type WeComSender ¶
type WeComSender struct {
// contains filtered or unexported fields
}
WeComSender sends replies via the WeCom AI Bot WebSocket.
func (*WeComSender) Send ¶
func (s *WeComSender) Send(ctx context.Context, msg platform.OutboundMessage) error
Send delivers a reply to WeCom. Text replies use aibot_respond_msg streaming; media replies use 3-step upload + aibot_send_msg.
type WsConn ¶
type WsConn struct {
// Callbacks — set before Connect().
OnAuthenticated func()
OnMessage func(WsFrame)
// contains filtered or unexported fields
}
WsConn manages a persistent WebSocket connection to the WeCom AI Bot server. It handles auth, heartbeat, reconnection, and serialised reply queues.
func NewWsConn ¶
func NewWsConn(cfg WsConnConfig) *WsConn
NewWsConn creates a WsConn with defaults applied.
func (*WsConn) Connect ¶
Connect establishes and maintains the WebSocket connection until ctx is cancelled. It blocks until ctx.Done().
func (*WsConn) IsConnected ¶
IsConnected reports whether the WebSocket connection is currently open.
func (*WsConn) SendReply ¶
SendReply enqueues a frame for the given reqID and waits for the server ack. Frames with the same reqID are serialised; different reqIDs are independent. Each distinct operation (subscribe, heartbeat, each upload step, each reply) MUST use its own freshly generated reqID — reusing a reqID across operations would serialize them through the same queue slot and deadlock.
type WsConnConfig ¶
type WsConnConfig struct {
BotID string
Secret string
URL string // default: wss://openws.work.weixin.qq.com
HeartbeatInterval time.Duration // default: 30s
MaxReconnectAttempts int // default: 100
ReconnectBaseDelay time.Duration // default: 1s
ReplyAckTimeout time.Duration // default: 5s
}
WsConnConfig configures a WsConn. Zero values use defaults.
type WsFrame ¶
type WsFrame struct {
Cmd string `json:"cmd,omitempty"`
Headers WsFrameHeaders `json:"headers"`
Body json.RawMessage `json:"body,omitempty"`
ErrCode int `json:"errcode,omitempty"`
ErrMsg string `json:"errmsg,omitempty"`
}
WsFrame is a single JSON message on the WeCom WebSocket wire.
type WsFrameHeaders ¶
type WsFrameHeaders struct {
ReqID string `json:"req_id"`
}
WsFrameHeaders carries the req_id used to correlate requests and acks.