Documentation
¶
Overview ¶
Package wecom provides a Channel adapter for WeCom (企业微信) webhook robots.
Official API Documentation: - URL: https://developer.work.weixin.qq.com/document/path/91770 - API Version: WeCom API v3 - Last Updated: 2024 - Authentication: Webhook URL with key parameter
Supported Features: - Text messages (文本消息) - Markdown messages (Markdown消息) - Markdown v2 messages (Markdown_v2消息) - Image messages (图片消息) - News messages (图文消息) - File messages (文件消息) - Voice messages (语音消息) - Template card messages (模板卡片消息)
Rate Limits: - 20 messages per minute per robot - Message length limits vary by type
Security: - Webhook URL contains secret key parameter - IP whitelist can be configured in WeCom admin console - HTTPS required for all API calls
Index ¶
- Constants
- Variables
- type Channel
- func (c *Channel) GetCapabilities() channel.ChannelCapabilities
- func (c *Channel) HandleWebhook(path string, data []byte) (*message.Message, error)
- func (c *Channel) SendMessage(ctx context.Context, msg *message.Message) error
- func (c *Channel) Start(ctx context.Context, handler channel.MessageHandler) error
- func (c *Channel) Stop(ctx context.Context) error
- func (c *Channel) UploadMedia(ctx context.Context, mediaType string, fileData []byte, filename string) (string, error)
- type Config
Constants ¶
const ( BaseURL = "https://qyapi.weixin.qq.com" EndpointWebhookSend = "/cgi-bin/webhook/send" EndpointMediaUpload = "/cgi-bin/media/upload" )
API endpoints for WeCom API.
Variables ¶
var ( ErrWebhookURLRequired = errors.New("webhook_url is required") ErrInvalidWebhookURL = errors.New("invalid webhook URL") ErrKeyRequired = errors.New("webhook key is required") ErrMessageTooLong = errors.New("message content exceeds maximum length") ErrInvalidMessageType = errors.New("invalid message type") )
Error definitions for WeCom channel.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
*channel.BaseChannel
// contains filtered or unexported fields
}
Channel implements the channel.Channel interface for WeCom.
func NewChannel ¶
NewChannel creates a new WeCom channel.
func (*Channel) GetCapabilities ¶
func (c *Channel) GetCapabilities() channel.ChannelCapabilities
GetCapabilities returns the channel capabilities.
func (*Channel) HandleWebhook ¶
HandleWebhook handles incoming webhook requests from WeCom. Note: WeCom webhook robots are outbound only, so this method returns an error.
func (*Channel) SendMessage ¶
SendMessage sends a message via WeCom webhook.
type Config ¶
type Config struct {
// WebhookURL is the full webhook URL including the key parameter
// Example: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa
WebhookURL string
// Key is the webhook key (extracted from WebhookURL if not provided)
Key string
// HTTPTimeout is the HTTP client timeout (default: 30s)
HTTPTimeout time.Duration
}
Config contains the configuration for WeCom channel.