Documentation
¶
Index ¶
- func ExtractKey(webhookURL string) (key string)
- func NewResError(code int, msg string) error
- func WithHttpClient(c *http.Client) func(*Bot)
- func WithMentionedList(userid ...string) func(*TextMessage)
- func WithMentionedMobileList(mobile ...string) func(*TextMessage)
- func WithThreadSafe() func(*Bot)
- type Article
- type Bot
- func (bot *Bot) SendFile(f []byte, filename string) (err error)
- func (bot *Bot) SendFileMessage(msg *FileMessage) (err error)
- func (bot *Bot) SendImage(img []byte) (err error)
- func (bot *Bot) SendImageMessage(msg *ImageMessage) (err error)
- func (bot *Bot) SendMarkdown(content string) (err error)
- func (bot *Bot) SendMarkdownMessage(msg *MarkdownMessage) (err error)
- func (bot *Bot) SendNews(articles ...*Article) (err error)
- func (bot *Bot) SendNewsMessage(msg *NewsMessage) (err error)
- func (bot *Bot) SendNewsNoticeTemplateCardMessage(msg *NewsNoticeTemplateCardMessage) error
- func (bot *Bot) SendText(content string, opts ...func(*TextMessage)) (err error)
- func (bot *Bot) SendTextMessage(msg *TextMessage) error
- func (bot *Bot) SendTextNoticeTemplateCardMessage(msg *TextNoticeTemplateCardMessage) error
- func (bot *Bot) SendVoice(f []byte, filename string) (err error)
- func (bot *Bot) SendVoiceMessage(msg *VoiceMessage) (err error)
- func (bot *Bot) UploadMedia(tpe FileType, f []byte, filename string) (*UploadedMedia, error)
- type CardAction
- type CardImage
- type CardType
- type EmphasisContent
- type FileMessage
- type FileType
- type HorizontalContent
- type ImageMessage
- type ImageTextArea
- type Jump
- type MainTitle
- type MarkdownMessage
- type MsgType
- type NewsMessage
- type NewsNoticeTemplateCardMessage
- type QuoteArea
- type ResError
- type Source
- type TextMessage
- type TextNoticeTemplateCardMessage
- type UploadedMedia
- type VerticalContent
- type VoiceMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractKey ¶ added in v0.3.0
ExtractKey 返回 webhook 中包含的 key 信息。若 URL 地址无效,或 URL 中不包含 key 参数,则返回空字符串。
func WithMentionedList ¶
func WithMentionedList(userid ...string) func(*TextMessage)
WithMentionedList 设置被提醒的 userid 列表
func WithMentionedMobileList ¶
func WithMentionedMobileList(mobile ...string) func(*TextMessage)
WithMentionedMobileList 设置被提醒的手机号列表
Types ¶
type Article ¶ added in v0.2.0
type Article struct {
// Title 标题,不超过128个字节,超过会自动截断。
Title string `json:"title"`
// Description 描述,不超过512个字节,超过会自动截断。
Description *string `json:"description"`
// URL 点击后跳转的链接。
URL string `json:"url"`
// PicURL 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图 1068*455,小图150*150。
PicURL *string `json:"picurl"`
}
Article 图文
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot 企业微信群机器人
func (*Bot) SendFileMessage ¶
func (bot *Bot) SendFileMessage(msg *FileMessage) (err error)
SendFileMessage 发送文件消息
func (*Bot) SendImageMessage ¶ added in v0.2.0
func (bot *Bot) SendImageMessage(msg *ImageMessage) (err error)
SendImageMessage 发送图片消息
func (*Bot) SendMarkdown ¶
SendMarkdown 发送 Markdown 消息
func (*Bot) SendMarkdownMessage ¶
func (bot *Bot) SendMarkdownMessage(msg *MarkdownMessage) (err error)
SendMarkdownMessage 发送 Markdown 消息
func (*Bot) SendNewsMessage ¶ added in v0.2.0
func (bot *Bot) SendNewsMessage(msg *NewsMessage) (err error)
SendNewsMessage 发送图文消息
func (*Bot) SendNewsNoticeTemplateCardMessage ¶ added in v0.2.0
func (bot *Bot) SendNewsNoticeTemplateCardMessage(msg *NewsNoticeTemplateCardMessage) error
SendNewsNoticeTemplateCardMessage 发送图文展示模板卡片类型消息
func (*Bot) SendText ¶
func (bot *Bot) SendText(content string, opts ...func(*TextMessage)) (err error)
SendText 发送文本消息
func (*Bot) SendTextMessage ¶
func (bot *Bot) SendTextMessage(msg *TextMessage) error
SendTextMessage 发送文本消息
func (*Bot) SendTextNoticeTemplateCardMessage ¶ added in v0.2.0
func (bot *Bot) SendTextNoticeTemplateCardMessage(msg *TextNoticeTemplateCardMessage) error
SendTextNoticeTemplateCardMessage 发送文本通知模板卡片类型消息
func (*Bot) SendVoiceMessage ¶
func (bot *Bot) SendVoiceMessage(msg *VoiceMessage) (err error)
SendVoiceMessage 发送语音消息
func (*Bot) UploadMedia ¶
UploadMedia 文件上传。详见 https://developer.work.weixin.qq.com/document/path/91770#%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E6%8E%A5%E5%8F%A3
type CardAction ¶ added in v0.2.0
type CardAction struct {
// Type 卡片跳转类型,1 代表跳转url,2 代表打开小程序。
Type uint8 `json:"type"`
// URL 跳转事件的url,type是1时必填。
URL *string `json:"url"`
// AppID 跳转事件的小程序的appid,type是2时必填。
AppID *string `json:"appid"`
// PagePath 跳转事件的小程序的pagepath,type是2时选填。
PagePath *string `json:"pagepath"`
}
整体卡片的点击跳转事件
type CardImage ¶ added in v0.2.0
type CardImage struct {
// URL 图片的url
URL string `json:"url"`
// AspectRatio 图片的宽高比,宽高比要小于2.25,大于1.3,不填该参数默认1.3
AspectRatio *float32 `json:"aspect_ratio"`
}
图片样式
type EmphasisContent ¶ added in v0.2.0
type EmphasisContent struct {
// Title 关键数据样式的数据内容,建议不超过10个字
Title *string `json:"title"`
// Desc 关键数据样式的数据描述内容,建议不超过15个字
Desc *string `json:"desc"`
}
EmphasisContent 关键数据样式
type FileMessage ¶
type FileMessage struct {
// MsgType 必填。消息类型,此时固定为 file 。
MsgType MsgType `json:"msgtype"`
// 消息内容
File struct {
// MediaID 必填。文件id,通过文件上传接口获取。
MediaID string `json:"media_id"`
} `json:"file"`
}
FileMessage 文件类型消息。详见 https://developer.work.weixin.qq.com/document/path/91770#%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B
type HorizontalContent ¶ added in v0.2.0
type HorizontalContent struct {
// Type 模版卡片的二级标题信息内容支持的类型,1是url,2是文件附件,3代表点击跳转成员详情。
Type *uint8 `json:"type"`
// Keyname 二级标题,建议不超过5个字。
KeyName string `json:"keyname"`
// Value 二级文本,如果type是2,该字段代表文件名称(要包含文件类型),建议不超过26个字。
Value *string `json:"value"`
// URL 链接跳转的url,type是1时必填。
URL *string `json:"url"`
// MediaID 附件的media_id,type是2时必填。
MediaID *string `json:"media_id"`
// UserID 成员详情的userid,type是3时必填。
UserID *string `json:"userid"`
}
HorizontalContent 二级标题+文本列表
type ImageMessage ¶ added in v0.2.0
type ImageMessage struct {
// MsgType 必填。消息类型,此时固定为 image 。
MsgType MsgType `json:"msgtype"`
// 消息内容
Image struct {
// Base64 必填。图片内容的base64编码
Base64 string `json:"base64"`
// Md5 必填。图片内容(base64编码前)的md5值
Md5 string `json:"md5"`
} `json:"image"`
}
ImageMessage 图片类型消息。详见 https://developer.work.weixin.qq.com/document/path/91770#%E5%9B%BE%E7%89%87%E7%B1%BB%E5%9E%8B
type ImageTextArea ¶ added in v0.2.0
type ImageTextArea struct {
// Type 左图右文样式区域点击事件,0或不填代表没有点击事件,1 代表跳转url,2 代表跳转小程序。
Type *uint8 `json:"type"`
// URL 点击跳转的url,type是1时必填。
URL *string `json:"url"`
// AppID 点击跳转的小程序的appid,必须是与当前应用关联的小程序,type是2时必填。
AppID *string `json:"appid"`
// PagePath 点击跳转的小程序的pagepath,type是2时选填。
PagePath *string `json:"pagepath"`
// Title 左图右文样式的标题
Title *string `json:"title"`
// Desc 左图右文样式的描述
Desc *string `json:"desc"`
// ImageURL 左图右文样式的图片url
ImageURL string `json:"image_url"`
}
ImageTextArea 左图右文样式
type Jump ¶ added in v0.2.0
type Jump struct {
// Type 跳转链接类型,0或不填代表不是链接,1 代表跳转url,2 代表跳转小程序。
Type *uint8 `json:"type"`
// Title 跳转链接样式的文案内容,建议不超过13个字。
Title string `json:"title"`
// URL 跳转链接的url,type是1时必填。
URL *string `json:"url"`
// AppID 跳转链接的小程序的appid,type是2时必填。
AppID *string `json:"appid"`
// PagePath 跳转链接的小程序的pagepath,type是2时选填。
PagePath *string `json:"pagepath"`
}
Jump 跳转指引样式
type MainTitle ¶ added in v0.2.0
type MainTitle struct {
// Title 一级标题,建议不超过26个字。模版卡片主要内容的一级标题main_title.title和二级普通文本sub_title_text必须有一项填写
Title *string `json:"title"`
// Desc 标题辅助信息,建议不超过30个字
Desc *string `json:"desc"`
}
MainTitle 模版卡片的主要内容,包括一级标题和标题辅助信息。
type MarkdownMessage ¶
type MarkdownMessage struct {
// MsgType 必填。消息类型,此时固定为 markdown 。
MsgType MsgType `json:"msgtype"`
// 消息内容
Markdown struct {
// Content 必填。markdown内容,最长不超过4096个字节,必须是utf8编码。
Content string `json:"content"`
} `json:"markdown"`
}
MarkdownMessage Markdown 类型消息。详见 https://developer.work.weixin.qq.com/document/path/91770#markdown%E7%B1%BB%E5%9E%8B
type MsgType ¶ added in v0.2.0
type MsgType string
MsgType 消息类型
const ( // TextMsgType 文本类型 TextMsgType MsgType = "text" // MarkdownMsgType Markdown 类型 MarkdownMsgType MsgType = "markdown" // ImageMsgType 图片类型 ImageMsgType MsgType = "image" // NewsMsgType 图文类型 NewsMsgType MsgType = "news" // FileMsgType 文件类型 FileMsgType MsgType = "file" // VoiceMsgType 语音类型 VoiceMsgType MsgType = "voice" // TemplateCardMsgType 模板卡片类型 TemplateCardMsgType MsgType = "template_card" )
type NewsMessage ¶ added in v0.2.0
type NewsMessage struct {
// MsgType 必填。消息类型,此时固定为 news 。
MsgType MsgType `json:"msgtype"`
// 消息内容
News struct {
Articles []*Article `json:"articles"`
} `json:"news"`
}
NewsMessage 图文类型消息。详见 https://developer.work.weixin.qq.com/document/path/91770#%E5%9B%BE%E6%96%87%E7%B1%BB%E5%9E%8B
type NewsNoticeTemplateCardMessage ¶ added in v0.2.0
type NewsNoticeTemplateCardMessage struct {
// MsgType 必填。消息类型,此时的消息类型固定为 template_card 。
MsgType MsgType `json:"msgtype"`
// TemplateCard 模板卡片
TemplateCard struct {
// CardType 模版卡片的模版类型,图文展示模版卡片的类型为 news_notice 。
CardType CardType `json:"card_type"`
// Source 可选。卡片来源样式信息。
Source *Source `json:"source"`
// MainTitle 模版卡片的主要内容,包括一级标题和标题辅助信息。
MainTitle MainTitle `json:"main_title"`
// CardImage 图片样式
CardImage CardImage `json:"card_image"`
// ImageTextArea 左图右文样式
ImageTextArea *ImageTextArea `json:"image_text_area"`
// QuoteArea 引用文献样式,建议不与关键数据共用。
QuoteArea *QuoteArea `json:"quote_area"`
// VerticalContentList 卡片二级垂直内容,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过4。
VerticalContentList []*VerticalContent `json:"vertical_content_list"`
// HorizontalContentList 二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6。
HorizontalContentList []*HorizontalContent `json:"horizontal_content_list"`
// JumpList 跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3。
JumpList []*Jump `json:"jump_list"`
// CardAction 整体卡片的点击跳转事件,text_notice模版卡片中该字段为必填项。
CardAction CardAction `json:"card_action"`
} `json:"template_card"`
}
NewsNoticeTemplateCardMessage 图文展示模版卡片类型消息
type QuoteArea ¶ added in v0.2.0
type QuoteArea struct {
// Type 引用文献样式区域点击事件,0或不填代表没有点击事件,1 代表跳转url,2 代表跳转小程序。
Type *uint8 `json:"type"`
// URL 点击跳转的url,type是1时必填。
URL *string `json:"url"`
// AppID 点击跳转的小程序的appid,type是2时必填。
AppID *string `json:"appid"`
// PagePath 点击跳转的小程序的pagepath,type是2时选填。
PagePath *string `json:"pagepath"`
// Title 引用文献样式的标题
Title *string `json:"title"`
// QuoteText 引用文献样式的引用文案
QuoteText *string `json:"quote_text"`
}
QuoteArea 引用文献样式,建议不与关键数据共用。
type Source ¶ added in v0.2.0
type Source struct {
// IconURL 来源图片的url
IconURL *string `json:"icon_url"`
// Desc 来源图片的描述,建议不超过13个字。
Desc *string `json:"desc"`
// DescColor 来源文字的颜色,目前支持:0(默认) 灰色,1 黑色,2 红色,3 绿色。
DescColor *uint8 `json:"desc_color"`
}
Source 卡片来源样式信息
type TextMessage ¶
type TextMessage struct {
// MsgType 必填。消息类型,此时固定为:text。
MsgType MsgType `json:"msgtype"`
Text struct {
// Content 必填。文本内容,最长不超过2048个字节,必须是utf8编码。
Content string `json:"content"`
// MentionedList 可选。userid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userid,可以使用mentioned_mobile_list。
MentionedList []string `json:"mentioned_list"`
// MentionedMobileList 可选。手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人。
MentionedMobileList []string `json:"mentioned_mobile_list"`
} `json:"text"`
}
TextMessage 文本类型消息。详见 https://developer.work.weixin.qq.com/document/path/91770#%E6%96%87%E6%9C%AC%E7%B1%BB%E5%9E%8B
type TextNoticeTemplateCardMessage ¶ added in v0.2.0
type TextNoticeTemplateCardMessage struct {
// MsgType 必填。消息类型,此时的消息类型固定为 template_card 。
MsgType MsgType `json:"msgtype"`
// TemplateCard 模板卡片
TemplateCard struct {
// CardType 模版卡片的模版类型,文本通知模版卡片的类型为 text_notice 。
CardType CardType `json:"card_type"`
// Source 可选。卡片来源样式信息。
Source *Source `json:"source"`
// MainTitle 模版卡片的主要内容,包括一级标题和标题辅助信息。
MainTitle MainTitle `json:"main_title"`
// EmphasisContent 关键数据样式
EmphasisContent *EmphasisContent `json:"emphasis_content"`
// QuoteArea 引用文献样式,建议不与关键数据共用。
QuoteArea *QuoteArea `json:"quote_area"`
// SubTitleText 二级普通文本,建议不超过112个字。模版卡片主要内容的一级标题main_title.title和二级普通文本sub_title_text必须有一项填写。
SubTitleText *string `json:"sub_title_text"`
// HorizontalContentList 二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6。
HorizontalContentList []*HorizontalContent `json:"horizontal_content_list"`
// JumpList 跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3。
JumpList []*Jump `json:"jump_list"`
// CardAction 整体卡片的点击跳转事件,text_notice模版卡片中该字段为必填项。
CardAction CardAction `json:"card_action"`
} `json:"template_card"`
}
TextNoticeTemplateCardMessage 文本通知模版卡片类型消息
type UploadedMedia ¶
type UploadedMedia struct {
MediaID string `json:"media_id"`
CreatedAt string `json:"created_at"`
// contains filtered or unexported fields
}
UploadedMedia 上传媒体文件结果
func (*UploadedMedia) ToError ¶
func (um *UploadedMedia) ToError() error
type VerticalContent ¶ added in v0.2.0
type VerticalContent struct {
// Title 卡片二级标题,建议不超过26个字。
Title string `json:"title"`
// Desc 二级普通文本,建议不超过112个字。
Desc *string `json:"desc"`
}
VerticalContent 卡片二级垂直内容
type VoiceMessage ¶
type VoiceMessage struct {
// MsgType 必填。语音类型,此时固定为 voice 。
MsgType MsgType `json:"msgtype"`
// 消息内容
Voice struct {
// MediaID 必填。语音文件id,通过文件上传接口获取。
MediaID string `json:"media_id"`
} `json:"voice"`
}
VoiceMessage 语音类型消息。详见 https://developer.work.weixin.qq.com/document/path/91770#%E8%AF%AD%E9%9F%B3%E7%B1%BB%E5%9E%8B