Documentation
¶
Overview ¶
Package wechat provides a Go library for the WeChat iLink Bot API.
It implements the full iLink protocol used by WeChat AI bot integrations, including QR code login, message sending/receiving, CDN media handling, voice message processing, and quoted message parsing.
Quick start:
creds, _ := auth.PollQRStatus(ctx, qr.QRCode, nil)
bot := wechat.NewBot(creds)
bot.Run(ctx, func(ctx context.Context, msg types.WeixinMessage) {
text := parse.ExtractText(&msg)
bot.SendText(ctx, msg.FromUserID, "Echo: "+text, msg.ContextToken)
})
Index ¶
- type Bot
- func (b *Bot) DownloadMedia(ctx context.Context, media *types.CDNMedia) ([]byte, error)
- func (b *Bot) DownloadVoice(ctx context.Context, item *types.VoiceItem) ([]byte, error)
- func (b *Bot) ParseMedia(msg *types.WeixinMessage) *types.MessageItem
- func (b *Bot) ParseText(msg *types.WeixinMessage) string
- func (b *Bot) Run(ctx context.Context, handler monitor.Handler) error
- func (b *Bot) SendErrorNotice(ctx context.Context, toUserID, text, contextToken string)
- func (b *Bot) SendFile(ctx context.Context, toUserID, filePath, fileName, contextToken string) error
- func (b *Bot) SendImageFile(ctx context.Context, toUserID, filePath, contextToken string) error
- func (b *Bot) SendText(ctx context.Context, toUserID, text, contextToken string) error
- func (b *Bot) SendVideoFile(ctx context.Context, toUserID, filePath, contextToken string) error
- func (b *Bot) StartTyping(ctx context.Context, userID, contextToken string) (stop func())
- type BotOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct {
Client *client.Client
Downloader *cdn.Downloader
Uploader *cdn.Uploader
Typing *typing.ConfigCache
KeepAlive *typing.KeepAlive
Guard *monitor.SessionGuard
VoiceDec voice.Decoder
// contains filtered or unexported fields
}
Bot is a high-level convenience wrapper that composes all subsystems.
func NewBot ¶
func NewBot(creds *types.Credentials, opts ...BotOption) *Bot
NewBot creates a Bot with all subsystems initialized from credentials.
func (*Bot) DownloadMedia ¶
DownloadMedia downloads and decrypts media from a CDNMedia reference. Returns (nil, nil) if media is nil.
func (*Bot) DownloadVoice ¶
DownloadVoice downloads, decrypts, and optionally decodes a voice message to WAV. Returns (nil, nil) if item is nil or has no media. Use voice.Transcription() to get WeChat's built-in transcription text.
func (*Bot) ParseMedia ¶
func (b *Bot) ParseMedia(msg *types.WeixinMessage) *types.MessageItem
ParseMedia extracts the best media item from a message with ref_msg fallback.
func (*Bot) ParseText ¶
func (b *Bot) ParseText(msg *types.WeixinMessage) string
ParseText extracts text from a message, including quoted message formatting.
func (*Bot) SendErrorNotice ¶
SendErrorNotice sends an error message to a user. Fire-and-forget, never returns error.
func (*Bot) SendFile ¶
func (b *Bot) SendFile(ctx context.Context, toUserID, filePath, fileName, contextToken string) error
SendFile uploads and sends a file attachment.
func (*Bot) SendImageFile ¶
SendImageFile uploads and sends an image from a file path.
func (*Bot) SendVideoFile ¶
SendVideoFile uploads and sends a video from a file path.
type BotOption ¶
type BotOption func(*Bot)
BotOption configures the Bot.
func WithHTTPDoer ¶
WithHTTPDoer sets a custom HTTP doer for the client.
func WithSessionGuard ¶
func WithSessionGuard(g *monitor.SessionGuard) BotOption
WithSessionGuard sets a custom session guard.
func WithSyncState ¶
WithSyncState sets a custom sync state for message polling persistence.
func WithVoiceDecoder ¶
WithVoiceDecoder sets a custom voice decoder.