weixin

package
v0.26.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultAPIBaseURL = "https://ilinkai.weixin.qq.com"
)

Variables

This section is empty.

Functions

func ClearSession

func ClearSession(sandboxID string)

func SendTextMessage added in v0.26.0

func SendTextMessage(ctx context.Context, apiBaseURL, botToken, toUserID, text, contextToken string) error

SendTextMessage sends a text message to a WeChat user via iLink.

func SetSession

func SetSession(sandboxID string, s *Session)

Types

type BaseInfo added in v0.26.0

type BaseInfo struct {
	ChannelVersion string `json:"channel_version,omitempty"`
}

BaseInfo is common metadata attached to every iLink API request.

type Bridge added in v0.26.0

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge manages per-sandbox long-poll goroutines for nanoclaw WeChat bindings.

func NewBridge added in v0.26.0

func NewBridge(db BridgeDB, resolver SandboxResolver) *Bridge

NewBridge creates a new Bridge instance.

func (*Bridge) StartPoller added in v0.26.0

func (b *Bridge) StartPoller(binding BridgeBinding)

StartPoller starts a long-poll goroutine for a single binding. If a poller already exists for this binding, it is stopped first.

func (*Bridge) StopPoller added in v0.26.0

func (b *Bridge) StopPoller(sandboxID, botID string)

StopPoller stops the polling goroutine for a specific binding.

func (*Bridge) StopPollersForSandbox added in v0.26.0

func (b *Bridge) StopPollersForSandbox(sandboxID string)

StopPollersForSandbox stops all polling goroutines for a sandbox.

type BridgeBinding added in v0.26.0

type BridgeBinding struct {
	SandboxID     string
	BotID         string
	BotToken      string
	ILinkBaseURL  string
	GetUpdatesBuf string
	PodIP         string
	BridgeSecret  string
}

BridgeBinding holds the info needed to run a poller for one WeChat binding.

type BridgeDB added in v0.26.0

type BridgeDB interface {
	UpdateGetUpdatesBuf(sandboxID, botID, buf string) error
	UpsertContextToken(sandboxID, botID, userID, contextToken string) error
	GetContextToken(sandboxID, botID, userID string) (string, error)
}

BridgeDB is the DB interface needed by the bridge.

type GetUpdatesRequest added in v0.26.0

type GetUpdatesRequest struct {
	GetUpdatesBuf string   `json:"get_updates_buf"`
	BaseInfo      BaseInfo `json:"base_info"`
}

GetUpdatesRequest is the body for POST /ilink/bot/getupdates.

type GetUpdatesResponse added in v0.26.0

type GetUpdatesResponse struct {
	Ret                  int             `json:"ret"`
	ErrCode              int             `json:"errcode,omitempty"`
	ErrMsg               string          `json:"errmsg,omitempty"`
	Msgs                 []WeixinMessage `json:"msgs,omitempty"`
	GetUpdatesBuf        string          `json:"get_updates_buf,omitempty"`
	LongPollingTimeoutMs int             `json:"longpolling_timeout_ms,omitempty"`
}

GetUpdatesResponse is the response from getupdates.

func GetUpdates added in v0.26.0

func GetUpdates(ctx context.Context, apiBaseURL, botToken, getUpdatesBuf string) (*GetUpdatesResponse, error)

GetUpdates long-polls iLink for new messages. Blocks for up to ~35s. Returns an empty response (Ret=0, no msgs) on client-side timeout.

type MessageItem added in v0.26.0

type MessageItem struct {
	Type     int       `json:"type,omitempty"` // 1=TEXT, 2=IMAGE, 3=VOICE, 4=FILE, 5=VIDEO
	TextItem *TextItem `json:"text_item,omitempty"`
}

MessageItem represents a single content item in a WeixinMessage.

type SandboxResolver added in v0.26.0

type SandboxResolver interface {
	GetPodIP(sandboxID string) string
}

SandboxResolver looks up the current state of a sandbox. Used by the poller to get the latest PodIP (which changes on Pod restart).

type SendMessageRequest added in v0.26.0

type SendMessageRequest struct {
	Msg      WeixinMessage `json:"msg"`
	BaseInfo BaseInfo      `json:"base_info"`
}

SendMessageRequest is the body for POST /ilink/bot/sendmessage.

type Session

type Session struct {
	QRCode    string // opaque qrcode string for status polling
	QRCodeURL string // image URL for frontend rendering
	StartedAt time.Time
}

Session holds the state of an in-progress QR login for a single sandbox.

func GetSession

func GetSession(sandboxID string) *Session

func StartLogin

func StartLogin(ctx context.Context, apiBaseURL string) (*Session, error)

StartLogin calls the ilink API to generate a new QR code for WeChat login.

func TakeSession

func TakeSession(sandboxID string) *Session

TakeSession atomically returns and removes the session (used on confirmed).

type StatusResult

type StatusResult struct {
	Status  string `json:"status"` // "wait", "scaned", "confirmed", "expired"
	Token   string `json:"bot_token,omitempty"`
	BotID   string `json:"ilink_bot_id,omitempty"`
	BaseURL string `json:"baseurl,omitempty"`
	UserID  string `json:"ilink_user_id,omitempty"`
}

StatusResult is the parsed response from get_qrcode_status.

func PollLoginStatus

func PollLoginStatus(ctx context.Context, apiBaseURL, qrcode string) (*StatusResult, error)

PollLoginStatus long-polls the ilink API for QR code scan status. Blocks for up to ~35 seconds (server-side long-poll).

type TextItem added in v0.26.0

type TextItem struct {
	Text string `json:"text,omitempty"`
}

TextItem holds the text content of a TEXT message item.

type WeixinMessage added in v0.26.0

type WeixinMessage struct {
	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"`
	MessageType  int           `json:"message_type,omitempty"`  // 1=USER, 2=BOT
	MessageState int           `json:"message_state,omitempty"` // 0=NEW, 1=GENERATING, 2=FINISH
	ItemList     []MessageItem `json:"item_list,omitempty"`
	ContextToken string        `json:"context_token,omitempty"`
}

WeixinMessage is a message from/to iLink.

Jump to

Keyboard shortcuts

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