Documentation ¶
Overview ¶
Copyright (c) 2021 Jayson Wang.
Package workrobot implements work-wx robot.
Index ¶
Constants ¶
const ( // default robot webhook gateway DefaultSendGateway = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send" // default upload gateway DefaultUploadGateway = "https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media" )
const ( TextMessageMaxLength = 2048 MarkdownMessageMaxLength = 4096 MaxImageFileSize = 2 * 1024 * 1024 // 2M MaxArticleCount = 8 )
Variables ¶
var ( // ErrMessageTooLong represents the message length exceeds the limit ErrMessageTooLong = errors.New("message too long") // ErrImageTooLarge represents the image size exceeds the limit(2m) ErrImageTooLarge = errors.New("image too large") // ErrTooManyArticle represents articles count more than 8 ErrTooManyArticle = errors.New("too many articles") )
Functions ¶
Types ¶
type Article ¶
type Article struct { Title string `json:"title"` Description string `json:"description"` Link string `json:"url"` ImageUrl string `json:"picurl"` }
Article represents an article message data see https://work.weixin.qq.com/api/doc/90000/90136/91770#图文类型
type Card ¶
type Card struct {
// contains filtered or unexported fields
}
Card represents a card message
func (*Card) AddArticle ¶
AddArticle add article into card
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a robot client
func NewClient ¶
func NewClient(key string, options ...ClientOption) (*Client, error)
NewClient create a instance of robot
func (*Client) Send ¶
Send send messages to the group in order, when error occurs will be returns immediately and skip the rest of the messages
func (*Client) SendConcurrency ¶
SendConcurrency send message to the group concurrency, and error will returns according to fastFail, returns immediately when fastFail is true, aggregation errors otherwise
concurrency limit: 20/min, 2/sec see https://work.weixin.qq.com/api/doc/90000/90136/91770#消息发送频率限制
type ClientOption ¶
ClientOption represents additional robot configuration
func WithHttpClient ¶
func WithHttpClient(hc *http.Client) ClientOption
WithHttpClient override http client for robot request
func WithWebhook ¶
func WithWebhook(webhook string) ClientOption
WithWebhook override robot webhook address
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image represents an image
type Markdown ¶
type Markdown struct {
// contains filtered or unexported fields
}
Markdown represents a pure markdown message
func NewMarkdown ¶
NewMarkdown create a markdown message from lines
func (*Markdown) AddSegmentLine ¶
AddSegmentLine add a segment as line
func (*Markdown) RawContent ¶
RawContent sets the raw markdown text
type Media ¶
type Media struct {
// contains filtered or unexported fields
}
Media represents a file message
type Mention ¶
type Mention struct {
// contains filtered or unexported fields
}
Mention represents a mention message
func NewMention ¶
NewMention create a mention message without error
func (*Mention) MentionAll ¶
MentionAll make mentioned all group members
func (*Mention) MentionMember ¶
MentionMember make mentioned someone in group
func (*Mention) MentionMobile ¶
MentionMobile make mentioned someone by mobile in group
type Messager ¶
type Messager interface {
Message() []byte
}
Messager represents a message will sent