Documentation
¶
Index ¶
- func AtAll(s *Send) error
- func GenerateSign(secret string) (int64, string, error)
- type ActionCard
- type ActionCardBtn
- type ActionsCard
- type At
- type Bot
- func (b *Bot) ContainsAnyKeyword(text string) bool
- func (b *Bot) Send(msg Msg, handlers ...SendHandler) error
- func (b *Bot) SendActionCard(title, text, singleTitle, singleURL string, handlers ...SendHandler) error
- func (b *Bot) SendActionCardWithContext(ctx context.Context, title, text, singleTitle, singleURL string, ...) error
- func (b *Bot) SendActionsCard(title, text string, btns []ActionCardBtn, handlers ...SendHandler) error
- func (b *Bot) SendActionsCardWithContext(ctx context.Context, title, text string, btns []ActionCardBtn, ...) error
- func (b *Bot) SendFeedCard(links []FeedCardLink, handlers ...SendHandler) error
- func (b *Bot) SendFeedCardWithContext(ctx context.Context, links []FeedCardLink, handlers ...SendHandler) error
- func (b *Bot) SendLink(title, text, msgURL, picURL string, handlers ...SendHandler) error
- func (b *Bot) SendLinkWithContext(ctx context.Context, title, text, msgURL, picURL string, ...) error
- func (b *Bot) SendMarkdown(title, text string, handlers ...SendHandler) error
- func (b *Bot) SendMarkdownWithContext(ctx context.Context, title, text string, handlers ...SendHandler) error
- func (b *Bot) SendText(content string, handlers ...SendHandler) error
- func (b *Bot) SendTextWithContext(ctx context.Context, content string, handlers ...SendHandler) error
- func (b *Bot) SendWithContext(ctx context.Context, msg Msg, handlers ...SendHandler) error
- type FeedCard
- type FeedCardLink
- type Link
- type Markdown
- type Msg
- type MsgType
- type Send
- type SendError
- type SendHandler
- type SendResponse
- type Text
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActionCard ¶
type ActionCard struct {
// 消息会话列表中展示的标题,非消息体的标题
Title string `json:"title" yaml:"title" toml:"title" long:"title"`
// actionCard 类型消息的正文内容,支持 markdown 语法
Text string `json:"text" yaml:"text" toml:"text" long:"text"`
// 按钮上显示的文本
SingleTitle string `json:"singleTitle,omitempty" yaml:"singleTitle" toml:"singleTitle" long:"singleTitle"`
// 点击 singleTitle 按钮触发的 URL
SingleURL string `json:"singleURL,omitempty" yaml:"singleURL" toml:"singleURL" long:"singleURL"`
}
ActionCard 整体跳转 actionCard 类型消息
func (ActionCard) Type ¶
func (ActionCard) Type() MsgType
type ActionCardBtn ¶
type ActionCardBtn struct {
// 按钮上显示的文本
Title string `json:"title" yaml:"title" toml:"title" long:"title"`
// 按钮跳转的 URL
ActionURL string `json:"actionURL" yaml:"actionURL" toml:"actionURL" long:"actionURL"`
}
ActionCardBtn actionCard 类型消息的按钮
type ActionsCard ¶
type ActionsCard struct {
// 消息会话列表中展示的标题,非消息体的标题
Title string `json:"title" yaml:"title" toml:"title" long:"title"`
// actionCard 类型消息的正文内容,支持 markdown 语法
Text string `json:"text" yaml:"text" toml:"text" long:"text"`
// 按钮的信息列表
Btns []ActionCardBtn `json:"btns,omitempty" yaml:"btns" toml:"btns" long:"btns"`
// 消息内按钮排列方式,0:按钮竖直排列,1:按钮横向排列
BtnOrientation string `json:"btnOrientation,omitempty" yaml:"btnOrientation" toml:"btnOrientation" long:"btnOrientation"`
}
ActionsCard 独立跳转 actionCard 类型消息
func (ActionsCard) Type ¶
func (ActionsCard) Type() MsgType
type At ¶
type At struct {
IsAtAll bool `json:"isAtAll,omitempty"` // 是否@所有人
AtMobiles []string `json:"atMobiles,omitempty"` // 被@的群成员手机号
AtUserIDs []string `json:"atUserIds,omitempty"` // 被@的群成员 userId
}
At 被@的群成员信息
type Bot ¶
type Bot struct {
// 名称,可自定义
Name string `json:"name" yaml:"name" toml:"name" long:"name"`
// 调用接口的凭证,钉钉提供的 Webhook 链接中 access_token 的值
Token string `json:"token" yaml:"token" toml:"token" long:"token"`
// 安全密钥,创建机器人时在安全设置项选择了加签后,钉钉提供的 SEC 开头的字符串
Secret string `json:"secret" yaml:"secret" toml:"secret" long:"secret"`
// 自定义关键词,创建机器人时在安全设置项填入的所有关键词。当消息文本中不包含任何一个关键词时,会自动在文本末尾添加第一个关键词
Keywords []string `json:"keywords" yaml:"keywords" toml:"keywords" long:"keywords"`
// 全局请求超时时间,值为正时生效
Timeout time.Duration `json:"timeout" yaml:"timeout" toml:"timeout" long:"timeout"`
// 每分钟发送消息限制量,平台规定每分钟最多发送 20 条消息。如果超过限制,会限流至下一分钟零秒时刻,值为零则不限流
Limit int `json:"limit" yaml:"limit" toml:"limit" long:"limit"`
// contains filtered or unexported fields
}
Bot 钉钉机器人
func (*Bot) ContainsAnyKeyword ¶
ContainsAnyKeyword 检测字符串是否包含任意一个关键词,关键词切片为空也返回真
func (*Bot) SendActionCard ¶
func (b *Bot) SendActionCard(title, text, singleTitle, singleURL string, handlers ...SendHandler) error
SendActionCard 发送整体跳转 actionCard 类型消息
func (*Bot) SendActionCardWithContext ¶
func (b *Bot) SendActionCardWithContext(ctx context.Context, title, text, singleTitle, singleURL string, handlers ...SendHandler) error
SendActionCardWithContext 携带上下文发送整体跳转 actionCard 类型消息
func (*Bot) SendActionsCard ¶
func (b *Bot) SendActionsCard(title, text string, btns []ActionCardBtn, handlers ...SendHandler) error
SendActionsCard 发送独立跳转 actionCard 类型消息
func (*Bot) SendActionsCardWithContext ¶
func (b *Bot) SendActionsCardWithContext(ctx context.Context, title, text string, btns []ActionCardBtn, handlers ...SendHandler) error
SendActionsCardWithContext 携带上下文发送独立跳转 actionCard 类型消息
func (*Bot) SendFeedCard ¶
func (b *Bot) SendFeedCard(links []FeedCardLink, handlers ...SendHandler) error
SendFeedCard 发送 feedCard 类型消息
func (*Bot) SendFeedCardWithContext ¶
func (b *Bot) SendFeedCardWithContext(ctx context.Context, links []FeedCardLink, handlers ...SendHandler) error
SendFeedCardWithContext 携带上下文发送 feedCard 类型消息
func (*Bot) SendLink ¶
func (b *Bot) SendLink(title, text, msgURL, picURL string, handlers ...SendHandler) error
SendLink 发送链接类型消息
func (*Bot) SendLinkWithContext ¶
func (b *Bot) SendLinkWithContext(ctx context.Context, title, text, msgURL, picURL string, handlers ...SendHandler) error
SendLinkWithContext 携带上下文发送链接类型消息
func (*Bot) SendMarkdown ¶
func (b *Bot) SendMarkdown(title, text string, handlers ...SendHandler) error
SendMarkdown 发送 markdown 类型消息
func (*Bot) SendMarkdownWithContext ¶
func (b *Bot) SendMarkdownWithContext(ctx context.Context, title, text string, handlers ...SendHandler) error
SendMarkdownWithContext 携带上下文发送 markdown 类型消息
func (*Bot) SendText ¶
func (b *Bot) SendText(content string, handlers ...SendHandler) error
SendText 发送文本类型消息
func (*Bot) SendTextWithContext ¶
func (b *Bot) SendTextWithContext(ctx context.Context, content string, handlers ...SendHandler) error
SendTextWithContext 携带上下文发送文本类型消息
func (*Bot) SendWithContext ¶
SendWithContext 携带上下文发送消息
type FeedCard ¶
type FeedCard struct {
// feedCard 类型消息的内容列表
Links []FeedCardLink `json:"links" yaml:"links" toml:"links" long:"links"`
}
FeedCard feedCard 类型消息
type FeedCardLink ¶
type FeedCardLink struct {
// 每条内容的标题
Title string `json:"title" yaml:"title" toml:"title" long:"title"`
// 每条内容的跳转链接
MessageURL string `json:"messageURL" yaml:"messageURL" toml:"messageURL" long:"messageURL"`
// 每条内容的图片 URL ,建议使用上传媒体文件接口获取
PicURL string `json:"picURL" yaml:"picURL" toml:"picURL" long:"picURL"`
}
FeedCardLink feedCard 类型消息的内容
type Link ¶
type Link struct {
// 链接消息标题
Title string `json:"title" yaml:"title" toml:"title" long:"title"`
// 链接消息的内容
Text string `json:"text" yaml:"text" toml:"text" long:"text"`
// 点击消息跳转的 URL
MessageURL string `json:"messageUrl" yaml:"messageUrl" toml:"messageUrl" long:"messageUrl"`
// 链接消息内的图片地址,建议使用上传媒体文件接口获取
PicURL string `json:"picUrl,omitempty" yaml:"picUrl" toml:"picUrl" long:"picUrl"`
}
Link 链接类型消息
type Markdown ¶
type Markdown struct {
// 消息会话列表中展示的标题,非消息体的标题
Title string `json:"title" yaml:"title" toml:"title" long:"title"`
// markdown 类型消息的文本内容
Text string `json:"text" yaml:"text" toml:"text" long:"text"`
}
Markdown markdown 类型消息
type MsgType ¶
type MsgType string
MsgType 表示消息类型的字符串,已内置五种类型
MsgText // 文本类型 MsgLink // 链接类型,不支持@人 MsgMarkdown // Markdown 类型 MsgActionCard // 整体跳转、独立跳转类型 MsgFeedCard // FeedCard 类型,不支持@人
type Send ¶
type Send struct {
// 要发送的消息
Msg Msg
// 自定义机器人调用接口的凭证
AccessToken string `req:"query"`
// 使用时间戳和密钥生成的加密签名
Sign string `req:"query,omitempty"`
// 开发者服务内当前系统时间戳,单位是毫秒,与请求调用时间误差不能超过 1 小时
Timestamp int64 `req:"query,omitempty"`
// 消息幂等,发消息时接口调用超时或未知错误等报错,开发者可使用同一个消息幂等重试,避免重复发出消息
MsgUUID string `req:"body:msgUuid,omitempty"`
// 被@的群成员信息
At At `req:"body,omitempty"`
// 请求头
ContentType string `req:"header" default:"application/json"`
}
Send 自定义机器人发送群消息
type SendHandler ¶
发送消息接口的前处理器,可以用来更新消息、生成加密签名、设置消息幂等、设置@等
func Secret ¶
func Secret(secret string) SendHandler
Secret 会自动设置生成的加密签名,密钥参数为机器人安全设置页面,加签一栏下面显示的 SEC 开头的字符串
type SendResponse ¶
SendResponse 发送消息响应体
func PostSend ¶
func PostSend(token string, msg Msg, handlers ...SendHandler) (SendResponse, error)
PostSendWithContext 发送消息
func PostSendWithContext ¶
func PostSendWithContext(ctx context.Context, token string, msg Msg, handlers ...SendHandler) (r SendResponse, err error)
PostSendWithContext 携带上下文发送消息
