wechat

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 9 Imported by: 0

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

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

func (b *Bot) DownloadMedia(ctx context.Context, media *types.CDNMedia) ([]byte, error)

DownloadMedia downloads and decrypts media from a CDNMedia reference. Returns (nil, nil) if media is nil.

func (*Bot) DownloadVoice

func (b *Bot) DownloadVoice(ctx context.Context, item *types.VoiceItem) ([]byte, error)

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) Run

func (b *Bot) Run(ctx context.Context, handler monitor.Handler) error

Run starts the long-poll monitor loop. Blocks until ctx is canceled.

func (*Bot) SendErrorNotice

func (b *Bot) SendErrorNotice(ctx context.Context, toUserID, text, contextToken string)

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

func (b *Bot) SendImageFile(ctx context.Context, toUserID, filePath, contextToken string) error

SendImageFile uploads and sends an image from a file path.

func (*Bot) SendText

func (b *Bot) SendText(ctx context.Context, toUserID, text, contextToken string) error

SendText sends a text message.

func (*Bot) SendVideoFile

func (b *Bot) SendVideoFile(ctx context.Context, toUserID, filePath, contextToken string) error

SendVideoFile uploads and sends a video from a file path.

func (*Bot) StartTyping

func (b *Bot) StartTyping(ctx context.Context, userID, contextToken string) (stop func())

StartTyping begins sending typing indicators every 5 seconds. Returns a stop function.

type BotOption

type BotOption func(*Bot)

BotOption configures the Bot.

func WithHTTPDoer

func WithHTTPDoer(doer client.HTTPDoer) BotOption

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

func WithSyncState(s monitor.SyncState) BotOption

WithSyncState sets a custom sync state for message polling persistence.

func WithVoiceDecoder

func WithVoiceDecoder(d voice.Decoder) BotOption

WithVoiceDecoder sets a custom voice decoder.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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