wecom

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
const (
	BaseURL = "https://qyapi.weixin.qq.com"

	EndpointWebhookSend = "/cgi-bin/webhook/send"
	EndpointMediaUpload = "/cgi-bin/media/upload"
)

API endpoints for WeCom API.

Variables

View Source
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

func NewChannel(name string, config Config) (*Channel, error)

NewChannel creates a new WeCom channel.

func (*Channel) GetCapabilities

func (c *Channel) GetCapabilities() channel.ChannelCapabilities

GetCapabilities returns the channel capabilities.

func (*Channel) HandleWebhook

func (c *Channel) HandleWebhook(path string, data []byte) (*message.Message, error)

HandleWebhook handles incoming webhook requests from WeCom. Note: WeCom webhook robots are outbound only, so this method returns an error.

func (*Channel) SendMessage

func (c *Channel) SendMessage(ctx context.Context, msg *message.Message) error

SendMessage sends a message via WeCom webhook.

func (*Channel) Start

func (c *Channel) Start(ctx context.Context, handler channel.MessageHandler) error

Start starts the WeCom channel.

func (*Channel) Stop

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

Stop stops the WeCom channel.

func (*Channel) UploadMedia

func (c *Channel) UploadMedia(ctx context.Context, mediaType string, fileData []byte, filename string) (string, error)

UploadMedia uploads a media file to WeCom and returns the media_id.

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.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

Jump to

Keyboard shortcuts

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