wecom

package
v0.0.46 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

View Source
const PlatformID = "wecom"

Variables

This section is empty.

Functions

func DecryptFile

func DecryptFile(encrypted []byte, aesKeyBase64 string) ([]byte, error)

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 ExtractContext added in v0.0.31

func ExtractContext(raw string) string

func NewPlatform

func NewPlatform(cfg config.WeComConfig, mediaSvc *media.Service) platform.Platform

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 (*WeComPlatform) Sender

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

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

func (c *WsConn) Connect(ctx context.Context) error

Connect establishes and maintains the WebSocket connection until ctx is cancelled. It blocks until ctx.Done().

func (*WsConn) IsConnected

func (c *WsConn) IsConnected() bool

IsConnected reports whether the WebSocket connection is currently open.

func (*WsConn) SendReply

func (c *WsConn) SendReply(reqID, cmd string, body any) (WsFrame, error)

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.

Jump to

Keyboard shortcuts

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