wecom

package
v0.0.0-...-8155ea7 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: GPL-2.0, GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageDeduplicator

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

MessageDeduplicator provides thread-safe message deduplication using a circular queue (ring buffer) combined with a hash map. This ensures fast O(1) lookups while naturally evicting the oldest messages without causing "amnesia cliffs" when the limit is reached.

func NewMessageDeduplicator

func NewMessageDeduplicator(maxEntries int) *MessageDeduplicator

NewMessageDeduplicator creates a new deduplicator with the specified capacity.

func (*MessageDeduplicator) MarkMessageProcessed

func (d *MessageDeduplicator) MarkMessageProcessed(msgID string) bool

MarkMessageProcessed marks msgID as processed and returns false for duplicates.

type PKCS7Padding

type PKCS7Padding struct{}

PKCS7Padding adds PKCS7 padding

type WeComAIBotChannel

type WeComAIBotChannel struct {
	*channels.BaseChannel
	// contains filtered or unexported fields
}

WeComAIBotChannel implements the Channel interface for WeCom AI Bot (企业微信智能机器人)

func NewWeComAIBotChannel

func NewWeComAIBotChannel(
	cfg config.WeComAIBotConfig,
	messageBus *bus.MessageBus,
) (*WeComAIBotChannel, error)

NewWeComAIBotChannel creates a new WeCom AI Bot channel instance

func (*WeComAIBotChannel) HealthHandler

func (c *WeComAIBotChannel) HealthHandler(w http.ResponseWriter, r *http.Request)

HealthHandler handles health check requests

func (*WeComAIBotChannel) HealthPath

func (c *WeComAIBotChannel) HealthPath() string

HealthPath returns the health check endpoint path

func (*WeComAIBotChannel) Name

func (c *WeComAIBotChannel) Name() string

Name returns the channel name

func (*WeComAIBotChannel) Send

Send delivers the agent reply into the active streamTask for msg.ChatID. It writes into the earliest unfinished task in the queue (FIFO per chatID). If the stream has already closed (deadline passed), it posts directly to response_url.

func (*WeComAIBotChannel) ServeHTTP

func (c *WeComAIBotChannel) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler for the shared HTTP server

func (*WeComAIBotChannel) Start

func (c *WeComAIBotChannel) Start(ctx context.Context) error

Start initializes the WeCom AI Bot channel

func (*WeComAIBotChannel) Stop

func (c *WeComAIBotChannel) Stop(ctx context.Context) error

Stop gracefully stops the WeCom AI Bot channel

func (*WeComAIBotChannel) WebhookPath

func (c *WeComAIBotChannel) WebhookPath() string

WebhookPath returns the path for registering on the shared HTTP server

type WeComAIBotEncryptedResponse

type WeComAIBotEncryptedResponse struct {
	Encrypt      string `json:"encrypt"`
	MsgSignature string `json:"msgsignature"`
	Timestamp    string `json:"timestamp"`
	Nonce        string `json:"nonce"`
}

WeComAIBotEncryptedResponse represents the encrypted response wrapper Fields match WXBizJsonMsgCrypt.generate() in Python SDK

type WeComAIBotMessage

type WeComAIBotMessage struct {
	MsgID    string `json:"msgid"`
	AIBotID  string `json:"aibotid"`
	ChatID   string `json:"chatid"`   // only for group chat
	ChatType string `json:"chattype"` // "single" or "group"
	From     struct {
		UserID string `json:"userid"`
	} `json:"from"`
	ResponseURL string `json:"response_url"` // temporary URL for proactive reply
	MsgType     string `json:"msgtype"`
	// text message
	Text *struct {
		Content string `json:"content"`
	} `json:"text,omitempty"`
	// stream polling refresh
	Stream *struct {
		ID string `json:"id"`
	} `json:"stream,omitempty"`
	// image message
	Image *struct {
		URL string `json:"url"`
	} `json:"image,omitempty"`
	// mixed message (text + image)
	Mixed *struct {
		MsgItem []struct {
			MsgType string `json:"msgtype"`
			Text    *struct {
				Content string `json:"content"`
			} `json:"text,omitempty"`
			Image *struct {
				URL string `json:"url"`
			} `json:"image,omitempty"`
		} `json:"msg_item"`
	} `json:"mixed,omitempty"`
	// event field
	Event *struct {
		EventType string `json:"eventtype"`
	} `json:"event,omitempty"`
}

WeComAIBotMessage represents the decrypted JSON message from WeCom AI Bot Ref: https://developer.work.weixin.qq.com/document/path/100719

type WeComAIBotMsgItem

type WeComAIBotMsgItem struct {
	MsgType string                  `json:"msgtype"`
	Image   *WeComAIBotMsgItemImage `json:"image,omitempty"`
}

WeComAIBotMsgItem is a single item inside a stream's msg_item list.

type WeComAIBotMsgItemImage

type WeComAIBotMsgItemImage struct {
	Base64 string `json:"base64"`
	MD5    string `json:"md5"`
}

WeComAIBotMsgItemImage holds the image payload inside a stream message item.

type WeComAIBotStreamInfo

type WeComAIBotStreamInfo struct {
	ID      string              `json:"id"`
	Finish  bool                `json:"finish"`
	Content string              `json:"content,omitempty"`
	MsgItem []WeComAIBotMsgItem `json:"msg_item,omitempty"`
}

WeComAIBotStreamInfo represents the detailed stream content in streaming responses.

type WeComAIBotStreamResponse

type WeComAIBotStreamResponse struct {
	MsgType string               `json:"msgtype"`
	Stream  WeComAIBotStreamInfo `json:"stream"`
}

WeComAIBotStreamResponse represents the streaming response format

type WeComAccessTokenResponse

type WeComAccessTokenResponse struct {
	ErrCode     int    `json:"errcode"`
	ErrMsg      string `json:"errmsg"`
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

WeComAccessTokenResponse represents the access token API response

type WeComAppChannel

type WeComAppChannel struct {
	*channels.BaseChannel
	// contains filtered or unexported fields
}

WeComAppChannel implements the Channel interface for WeCom App (企业微信自建应用)

func NewWeComAppChannel

func NewWeComAppChannel(cfg config.WeComAppConfig, messageBus *bus.MessageBus) (*WeComAppChannel, error)

NewWeComAppChannel creates a new WeCom App channel instance

func (*WeComAppChannel) HealthHandler

func (c *WeComAppChannel) HealthHandler(w http.ResponseWriter, r *http.Request)

HealthHandler handles health check requests.

func (*WeComAppChannel) HealthPath

func (c *WeComAppChannel) HealthPath() string

HealthPath returns the health check endpoint path.

func (*WeComAppChannel) Name

func (c *WeComAppChannel) Name() string

Name returns the channel name

func (*WeComAppChannel) Send

Send sends a message to WeCom user proactively using access token

func (*WeComAppChannel) SendMedia

SendMedia implements the channels.MediaSender interface.

func (*WeComAppChannel) ServeHTTP

func (c *WeComAppChannel) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler for the shared HTTP server.

func (*WeComAppChannel) Start

func (c *WeComAppChannel) Start(ctx context.Context) error

Start initializes the WeCom App channel

func (*WeComAppChannel) Stop

func (c *WeComAppChannel) Stop(ctx context.Context) error

Stop gracefully stops the WeCom App channel

func (*WeComAppChannel) WebhookPath

func (c *WeComAppChannel) WebhookPath() string

WebhookPath returns the path for registering on the shared HTTP server.

type WeComBotChannel

type WeComBotChannel struct {
	*channels.BaseChannel
	// contains filtered or unexported fields
}

WeComBotChannel implements the Channel interface for WeCom Bot (企业微信智能机器人) Uses webhook callback mode - simpler than WeCom App but only supports passive replies

func NewWeComBotChannel

func NewWeComBotChannel(cfg config.WeComConfig, messageBus *bus.MessageBus) (*WeComBotChannel, error)

NewWeComBotChannel creates a new WeCom Bot channel instance

func (*WeComBotChannel) HealthHandler

func (c *WeComBotChannel) HealthHandler(w http.ResponseWriter, r *http.Request)

HealthHandler handles health check requests.

func (*WeComBotChannel) HealthPath

func (c *WeComBotChannel) HealthPath() string

HealthPath returns the health check endpoint path.

func (*WeComBotChannel) Name

func (c *WeComBotChannel) Name() string

Name returns the channel name

func (*WeComBotChannel) Send

Send sends a message to WeCom user via webhook API Note: WeCom Bot can only reply within the configured timeout (default 5 seconds) of receiving a message For delayed responses, we use the webhook URL

func (*WeComBotChannel) ServeHTTP

func (c *WeComBotChannel) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler for the shared HTTP server.

func (*WeComBotChannel) Start

func (c *WeComBotChannel) Start(ctx context.Context) error

Start initializes the WeCom Bot channel

func (*WeComBotChannel) Stop

func (c *WeComBotChannel) Stop(ctx context.Context) error

Stop gracefully stops the WeCom Bot channel

func (*WeComBotChannel) WebhookPath

func (c *WeComBotChannel) WebhookPath() string

WebhookPath returns the path for registering on the shared HTTP server.

type WeComBotMessage

type WeComBotMessage struct {
	MsgID    string `json:"msgid"`
	AIBotID  string `json:"aibotid"`
	ChatID   string `json:"chatid"`   // Session ID, only present for group chats
	ChatType string `json:"chattype"` // "single" for DM, "group" for group chat
	From     struct {
		UserID string `json:"userid"`
	} `json:"from"`
	ResponseURL string `json:"response_url"`
	MsgType     string `json:"msgtype"` // text, image, voice, file, mixed
	Text        struct {
		Content string `json:"content"`
	} `json:"text"`
	Image struct {
		URL string `json:"url"`
	} `json:"image"`
	Voice struct {
		Content string `json:"content"` // Voice to text content
	} `json:"voice"`
	File struct {
		URL string `json:"url"`
	} `json:"file"`
	Mixed struct {
		MsgItem []struct {
			MsgType string `json:"msgtype"`
			Text    struct {
				Content string `json:"content"`
			} `json:"text"`
			Image struct {
				URL string `json:"url"`
			} `json:"image"`
		} `json:"msg_item"`
	} `json:"mixed"`
	Quote struct {
		MsgType string `json:"msgtype"`
		Text    struct {
			Content string `json:"content"`
		} `json:"text"`
	} `json:"quote"`
}

WeComBotMessage represents the JSON message structure from WeCom Bot (AIBOT)

type WeComBotReplyMessage

type WeComBotReplyMessage struct {
	MsgType string `json:"msgtype"`
	Text    struct {
		Content string `json:"content"`
	} `json:"text,omitempty"`
}

WeComBotReplyMessage represents the reply message structure

type WeComImageMessage

type WeComImageMessage struct {
	ToUser  string `json:"touser"`
	MsgType string `json:"msgtype"`
	AgentID int64  `json:"agentid"`
	Image   struct {
		MediaID string `json:"media_id"`
	} `json:"image"`
}

WeComImageMessage represents image message for sending

type WeComMarkdownMessage

type WeComMarkdownMessage struct {
	ToUser   string `json:"touser"`
	MsgType  string `json:"msgtype"`
	AgentID  int64  `json:"agentid"`
	Markdown struct {
		Content string `json:"content"`
	} `json:"markdown"`
}

WeComMarkdownMessage represents markdown message for sending

type WeComSendMessageResponse

type WeComSendMessageResponse struct {
	ErrCode      int    `json:"errcode"`
	ErrMsg       string `json:"errmsg"`
	InvalidUser  string `json:"invaliduser"`
	InvalidParty string `json:"invalidparty"`
	InvalidTag   string `json:"invalidtag"`
}

WeComSendMessageResponse represents the send message API response

type WeComTextMessage

type WeComTextMessage struct {
	ToUser  string `json:"touser"`
	MsgType string `json:"msgtype"`
	AgentID int64  `json:"agentid"`
	Text    struct {
		Content string `json:"content"`
	} `json:"text"`
	Safe int `json:"safe,omitempty"`
}

WeComTextMessage represents text message for sending

type WeComXMLMessage

type WeComXMLMessage struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   `xml:"ToUserName"`
	FromUserName string   `xml:"FromUserName"`
	CreateTime   int64    `xml:"CreateTime"`
	MsgType      string   `xml:"MsgType"`
	Content      string   `xml:"Content"`
	MsgId        int64    `xml:"MsgId"`
	AgentID      int64    `xml:"AgentID"`
	PicUrl       string   `xml:"PicUrl"`
	MediaId      string   `xml:"MediaId"`
	Format       string   `xml:"Format"`
	ThumbMediaId string   `xml:"ThumbMediaId"`
	LocationX    float64  `xml:"Location_X"`
	LocationY    float64  `xml:"Location_Y"`
	Scale        int      `xml:"Scale"`
	Label        string   `xml:"Label"`
	Title        string   `xml:"Title"`
	Description  string   `xml:"Description"`
	Url          string   `xml:"Url"`
	Event        string   `xml:"Event"`
	EventKey     string   `xml:"EventKey"`
}

WeComXMLMessage represents the XML message structure from WeCom

Jump to

Keyboard shortcuts

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