types

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: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Message types identify the sender role.
	MessageTypeNone = 0
	MessageTypeUser = 1
	MessageTypeBot  = 2

	// Message states track the lifecycle of a message.
	MessageStateNew        = 0
	MessageStateGenerating = 1
	MessageStateFinish     = 2

	// Item types identify the content type of a message item.
	ItemTypeNone  = 0
	ItemTypeText  = 1
	ItemTypeImage = 2
	ItemTypeVoice = 3
	ItemTypeFile  = 4
	ItemTypeVideo = 5

	// Typing status values for sendtyping API.
	TypingStatusTyping = 1
	TypingStatusCancel = 2

	// Upload media types for getuploadurl API.
	UploadMediaTypeImage = 1
	UploadMediaTypeVideo = 2
	UploadMediaTypeFile  = 3
	UploadMediaTypeVoice = 4

	// Encrypt types for CDN media.
	EncryptTypeAES128ECB = 1

	// Voice encode types.
	VoiceEncodeTypePCM      = 1
	VoiceEncodeTypeADPCM    = 2
	VoiceEncodeTypeFeature  = 3
	VoiceEncodeTypeSpeex    = 4
	VoiceEncodeTypeAMR      = 5
	VoiceEncodeTypeSILK     = 6
	VoiceEncodeTypeMP3      = 7
	VoiceEncodeTypeOggSpeex = 8

	// QR code login status values.
	QRStatusWait      = "wait"
	QRStatusScanned   = "scaned"
	QRStatusConfirmed = "confirmed"
	QRStatusExpired   = "expired"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseInfo

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

BaseInfo is included in all API request bodies.

type CDNMedia

type CDNMedia struct {
	EncryptQueryParam string `json:"encrypt_query_param,omitempty"`
	AESKey            string `json:"aes_key,omitempty"`      // base64-encoded (dual format)
	EncryptType       int    `json:"encrypt_type,omitempty"` // 1 for AES-128-ECB
}

CDNMedia is a CDN media reference for encrypted uploads/downloads.

type Credentials

type Credentials struct {
	BotToken    string `json:"bot_token"`
	ILinkBotID  string `json:"ilink_bot_id"`
	BaseURL     string `json:"baseurl"`
	ILinkUserID string `json:"ilink_user_id"`
}

Credentials stores login session data obtained from QR code login.

type FileItem

type FileItem struct {
	Media    *CDNMedia `json:"media,omitempty"`
	FileName string    `json:"file_name,omitempty"`
	Len      string    `json:"len,omitempty"` // Plaintext size as string
}

FileItem holds file attachment content.

type GetConfigRequest

type GetConfigRequest struct {
	ILinkUserID  string   `json:"ilink_user_id"`
	ContextToken string   `json:"context_token,omitempty"`
	BaseInfo     BaseInfo `json:"base_info"`
}

GetConfigRequest is the body for getconfig API.

type GetConfigResponse

type GetConfigResponse struct {
	Ret          int    `json:"ret"`
	ErrMsg       string `json:"errmsg,omitempty"`
	TypingTicket string `json:"typing_ticket,omitempty"`
}

GetConfigResponse is the response from getconfig API.

type GetUpdatesRequest

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

GetUpdatesRequest is the body for getupdates API.

type GetUpdatesResponse

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

GetUpdatesResponse is the response from getupdates API.

type GetUploadURLRequest

type GetUploadURLRequest struct {
	FileKey     string   `json:"filekey"`    // 32 hex chars (random 16 bytes)
	MediaType   int      `json:"media_type"` // UploadMediaType*
	ToUserID    string   `json:"to_user_id"`
	RawSize     int      `json:"rawsize"`    // Plaintext file size
	RawFileMD5  string   `json:"rawfilemd5"` // Hex-encoded MD5 of plaintext
	FileSize    int      `json:"filesize"`   // Ciphertext size (after AES+PKCS7)
	NoNeedThumb bool     `json:"no_need_thumb"`
	AESKey      string   `json:"aeskey"` // Hex-encoded AES key
	BaseInfo    BaseInfo `json:"base_info"`
}

GetUploadURLRequest is the body for getuploadurl API.

type GetUploadURLResponse

type GetUploadURLResponse struct {
	Ret         int    `json:"ret"`
	ErrMsg      string `json:"errmsg,omitempty"`
	UploadParam string `json:"upload_param,omitempty"` // Signed query string for CDN upload
}

GetUploadURLResponse is the response from getuploadurl API.

type ImageItem

type ImageItem struct {
	URL     string    `json:"url,omitempty"`      // Direct URL (unencrypted)
	Media   *CDNMedia `json:"media,omitempty"`    // Encrypted CDN reference
	MidSize int       `json:"mid_size,omitempty"` // Ciphertext size
}

ImageItem holds image content.

type MessageItem

type MessageItem struct {
	Type      int        `json:"type"`
	TextItem  *TextItem  `json:"text_item,omitempty"`
	ImageItem *ImageItem `json:"image_item,omitempty"`
	VideoItem *VideoItem `json:"video_item,omitempty"`
	FileItem  *FileItem  `json:"file_item,omitempty"`
	VoiceItem *VoiceItem `json:"voice_item,omitempty"`
	RefMsg    *RefMsg    `json:"ref_msg,omitempty"` // Quoted/referenced message
}

MessageItem is a single item in a message. A message can contain multiple items of different types (text + image, etc.).

type QRCodeResponse

type QRCodeResponse struct {
	QRCode           string `json:"qrcode"`
	QRCodeImgContent string `json:"qrcode_img_content"`
}

QRCodeResponse is the response from get_bot_qrcode.

type QRStatusResponse

type QRStatusResponse struct {
	Status      string `json:"status"`
	BotToken    string `json:"bot_token"`
	ILinkBotID  string `json:"ilink_bot_id"`
	BaseURL     string `json:"baseurl"`
	ILinkUserID string `json:"ilink_user_id"`
}

QRStatusResponse is the response from get_qrcode_status.

type RefMsg

type RefMsg struct {
	MessageItem *MessageItem `json:"message_item,omitempty"` // The quoted message content
	Title       string       `json:"title,omitempty"`        // Summary/preview text
}

RefMsg represents a quoted/referenced message attached to a text item.

type SendMessageRequest

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

SendMessageRequest is the body for sendmessage API.

type SendMessageResponse

type SendMessageResponse struct {
	Ret    int    `json:"ret"`
	ErrMsg string `json:"errmsg,omitempty"`
}

SendMessageResponse is the response from sendmessage API.

type SendMsg

type SendMsg struct {
	FromUserID   string        `json:"from_user_id"` // Always "" (empty) per official implementation
	ToUserID     string        `json:"to_user_id"`
	ClientID     string        `json:"client_id"`     // UUID for message correlation
	MessageType  int           `json:"message_type"`  // Always MessageTypeBot (2)
	MessageState int           `json:"message_state"` // Always MessageStateFinish (2)
	ItemList     []MessageItem `json:"item_list"`
	ContextToken string        `json:"context_token"` // From incoming message, required
}

SendMsg is the message payload for sending.

type SendTypingRequest

type SendTypingRequest struct {
	ILinkUserID  string   `json:"ilink_user_id"`
	TypingTicket string   `json:"typing_ticket"`
	Status       int      `json:"status"` // TypingStatusTyping or TypingStatusCancel
	BaseInfo     BaseInfo `json:"base_info"`
}

SendTypingRequest is the body for sendtyping API.

type SendTypingResponse

type SendTypingResponse struct {
	Ret    int    `json:"ret"`
	ErrMsg string `json:"errmsg,omitempty"`
}

SendTypingResponse is the response from sendtyping API.

type TextItem

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

TextItem holds text content.

type UploadedFileInfo

type UploadedFileInfo struct {
	FileKey                     string // 32 hex chars
	DownloadEncryptedQueryParam string // From CDN x-encrypted-param header
	AESKey                      []byte // Raw 16 bytes
	FileSize                    int    // Plaintext size
	FileSizeCiphertext          int    // Ciphertext size after AES-ECB + PKCS7
}

UploadedFileInfo contains the result of a successful CDN upload.

func (*UploadedFileInfo) AESKeyBase64

func (u *UploadedFileInfo) AESKeyBase64() string

AESKeyBase64 returns the AES key encoded as base64(hex_string_bytes). This matches the WeChat protocol: Buffer.from(hexStr).toString("base64").

func (*UploadedFileInfo) AESKeyHex

func (u *UploadedFileInfo) AESKeyHex() string

AESKeyHex returns the AES key as a hex-encoded string (for getuploadurl request).

type VideoItem

type VideoItem struct {
	Media     *CDNMedia `json:"media,omitempty"`
	VideoSize int       `json:"video_size,omitempty"` // Ciphertext size
}

VideoItem holds video content.

type VoiceItem

type VoiceItem struct {
	Media         *CDNMedia `json:"media,omitempty"`
	EncodeType    int       `json:"encode_type,omitempty"` // 1=pcm,2=adpcm,3=feature,4=speex,5=amr,6=silk,7=mp3,8=ogg-speex
	BitsPerSample int       `json:"bits_per_sample,omitempty"`
	SampleRate    int       `json:"sample_rate,omitempty"` // Hz
	Playtime      int       `json:"playtime,omitempty"`    // Duration in milliseconds
	Text          string    `json:"text,omitempty"`        // WeChat built-in voice-to-text transcription
}

VoiceItem holds voice content with full metadata.

type WeixinMessage

type WeixinMessage struct {
	FromUserID   string        `json:"from_user_id"`
	ToUserID     string        `json:"to_user_id"`
	MessageType  int           `json:"message_type"`  // MessageTypeUser or MessageTypeBot
	MessageState int           `json:"message_state"` // MessageStateNew/Generating/Finish
	ItemList     []MessageItem `json:"item_list"`
	ContextToken string        `json:"context_token"` // Required for reply association
}

WeixinMessage represents a message from WeChat.

Jump to

Keyboard shortcuts

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