Documentation
¶
Index ¶
- func GenerateSignedURL(webhook string, secret string) (string, error)
- type Client
- func (c *Client) SendWebhookActionCardMessage(ctx context.Context, webhook, title, text, singleTitle, singleURL string, ...) error
- func (c *Client) SendWebhookActionCardMessageV2(ctx context.Context, webhook, title, text string, ...) error
- func (c *Client) SendWebhookActionCardMessageV3(ctx context.Context, req *SendActionCardRequest) error
- func (c *Client) SendWebhookFeedCardMessage(ctx context.Context, webhook string, links []*WebhookFeedCardLink) error
- func (c *Client) SendWebhookFeedCardMessageV2(ctx context.Context, req *SendFeedCardRequest) error
- func (c *Client) SendWebhookLinkMessage(ctx context.Context, webhookUrl string, title string, text string, ...) error
- func (c *Client) SendWebhookLinkMessageV2(ctx context.Context, req *SendLinkRequest) error
- func (c *Client) SendWebhookMarkdownMessage(ctx context.Context, webhookUrl string, title string, text string) error
- func (c *Client) SendWebhookMarkdownMessageV2(ctx context.Context, req *SendMarkdownRequest) error
- func (c *Client) SendWebhookTextMessage(ctx context.Context, webhookUrl string, content string) error
- func (c *Client) SendWebhookTextMessageV2(ctx context.Context, req *SendTextRequest) error
- type LogLevel
- type SendActionCardRequest
- type SendFeedCardRequest
- type SendLinkRequest
- type SendMarkdownRequest
- type SendTextRequest
- type WebhookActionCardButton
- type WebhookActionCardContent
- type WebhookActionCardMessage
- type WebhookAt
- type WebhookFeedCardContent
- type WebhookFeedCardLink
- type WebhookFeedCardMessage
- type WebhookLinkContent
- type WebhookLinkMessage
- type WebhookMarkdownContent
- type WebhookMarkdownMessage
- type WebhookResponse
- type WebhookTextContent
- type WebhookTextMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateSignedURL ¶
GenerateSignedURL 生成带签名的钉钉 Webhook URL 钉钉机器人安全设置中的"加签"方式需要使用此方法 参数:
- webhook: 原始的 Webhook 地址
- secret: 机器人的加签密钥
返回:
- string: 带签名参数的完整 URL
- error: 生成失败时返回错误信息
示例:
webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx" secret := "SECxxxxxxxxxxxx" signedURL, err := GenerateSignedURL(webhook, secret)
Types ¶
type Client ¶
Client 钉钉群机器人客户端 主要用于通过 Webhook 发送消息到群聊
func NewClientWithLogLevel ¶
NewClientWithLogLevel 创建指定日志级别的钉钉客户端
func (*Client) SendWebhookActionCardMessage ¶
func (c *Client) SendWebhookActionCardMessage(ctx context.Context, webhook, title, text, singleTitle, singleURL string, btnOrientation ...string) error
SendWebhookActionCardMessage 发送 ActionCard 消息(单按钮模式) 参数:
- ctx: 上下文
- webhook: Webhook 地址
- title: 首屏会话透出的展示内容
- text: Markdown 格式的消息内容
- singleTitle: 按钮标题
- singleURL: 按钮跳转链接
- btnOrientation: 按钮排列方式,"0"-竖直排列,"1"-横向排列(可选,默认"0")
- at: @人信息(可选,注意:钉钉官方actionCard类型不支持@人,此参数为扩展预留)
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookActionCardMessageV2 ¶
func (c *Client) SendWebhookActionCardMessageV2(ctx context.Context, webhook, title, text string, btns []*WebhookActionCardButton, btnOrientation ...string) error
SendWebhookActionCardMessageV2 发送 ActionCard 消息(多按钮模式) 参数:
- ctx: 上下文
- webhook: Webhook 地址
- title: 首屏会话透出的展示内容
- text: Markdown 格式的消息内容
- btns: 按钮列表
- btnOrientation: 按钮排列方式,"0"-竖直排列,"1"-横向排列(可选,默认"0")
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookActionCardMessageV3 ¶
func (c *Client) SendWebhookActionCardMessageV3(ctx context.Context, req *SendActionCardRequest) error
SendWebhookActionCardMessageV3 发送 ActionCard 消息(使用请求对象) 参数:
- ctx: 上下文
- req: ActionCard 消息请求参数
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookFeedCardMessage ¶
func (c *Client) SendWebhookFeedCardMessage(ctx context.Context, webhook string, links []*WebhookFeedCardLink) error
SendWebhookFeedCardMessage 发送 FeedCard 消息 参数:
- ctx: 上下文
- webhook: Webhook 地址
- links: 链接列表
- at: @人信息(可选,注意:钉钉官方feedCard类型不支持@人,此参数为扩展预留)
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookFeedCardMessageV2 ¶
func (c *Client) SendWebhookFeedCardMessageV2(ctx context.Context, req *SendFeedCardRequest) error
SendWebhookFeedCardMessageV2 发送 FeedCard 消息(使用请求对象) 参数:
- ctx: 上下文
- req: FeedCard 消息请求参数
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookLinkMessage ¶
func (c *Client) SendWebhookLinkMessage(ctx context.Context, webhookUrl string, title string, text string, messageUrl string, picUrl string) error
SendWebhookLinkMessage 通过 Webhook 发送链接消息到钉钉群 参数:
- ctx: 上下文,用于控制请求超时和取消
- webhookUrl: 群机器人的 Webhook 地址
- title: 消息标题
- text: 消息内容
- messageUrl: 点击消息跳转的URL
- picUrl: 图片URL(可选)
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookLinkMessageV2 ¶
func (c *Client) SendWebhookLinkMessageV2(ctx context.Context, req *SendLinkRequest) error
SendWebhookLinkMessageV2 通过 Webhook 发送链接消息到钉钉群(使用请求对象) 参数:
- ctx: 上下文,用于控制请求超时和取消
- req: 发送链接消息请求,包含完整的配置参数
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookMarkdownMessage ¶
func (c *Client) SendWebhookMarkdownMessage(ctx context.Context, webhookUrl string, title string, text string) error
SendWebhookMarkdownMessage 通过 Webhook 发送 Markdown 消息到钉钉群 参数:
- ctx: 上下文,用于控制请求超时和取消
- webhookUrl: 群机器人的 Webhook 地址
- title: 首屏会话透出的展示内容
- text: Markdown 格式的消息内容
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookMarkdownMessageV2 ¶
func (c *Client) SendWebhookMarkdownMessageV2(ctx context.Context, req *SendMarkdownRequest) error
SendWebhookMarkdownMessageV2 通过 Webhook 发送 Markdown 消息到钉钉群(支持@功能) 参数:
- ctx: 上下文,用于控制请求超时和取消
- req: 发送Markdown消息请求,包含完整的配置参数
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookTextMessage ¶
func (c *Client) SendWebhookTextMessage(ctx context.Context, webhookUrl string, content string) error
SendWebhookTextMessage 通过 Webhook 发送文本消息到钉钉群 参数:
- ctx: 上下文,用于控制请求超时和取消
- webhookUrl: 群机器人的 Webhook 地址
- content: 要发送的文本内容
返回:
- error: 发送失败时返回错误信息
func (*Client) SendWebhookTextMessageV2 ¶
func (c *Client) SendWebhookTextMessageV2(ctx context.Context, req *SendTextRequest) error
SendWebhookTextMessageV2 通过 Webhook 发送文本消息到钉钉群(支持@功能) 参数:
- ctx: 上下文,用于控制请求超时和取消
- req: 发送文本消息请求,包含完整的配置参数
返回:
- error: 发送失败时返回错误信息
type SendActionCardRequest ¶
type SendActionCardRequest struct {
Webhook string // Webhook地址
Title string // 首屏会话透出的展示内容
Text string // Markdown格式的消息
SingleTitle string // 单个按钮的标题(单按钮模式)
SingleURL string // 单个按钮的跳转链接(单按钮模式)
BtnOrientation string // 按钮排列方式:0-按钮竖直排列,1-按钮横向排列
Btns []*WebhookActionCardButton // 按钮列表(多按钮模式)
AtMobiles []string // 被@人的手机号(注意:钉钉官方actionCard类型不支持@人,此字段为扩展预留)
AtUserIds []string // 被@人的用户userid(注意:钉钉官方actionCard类型不支持@人,此字段为扩展预留)
IsAtAll bool // 是否@所有人(注意:钉钉官方actionCard类型不支持@人,此字段为扩展预留)
}
SendActionCardRequest 发送ActionCard消息请求参数
type SendFeedCardRequest ¶
type SendFeedCardRequest struct {
Webhook string // Webhook地址
Links []*WebhookFeedCardLink // 链接列表
AtMobiles []string // 被@人的手机号(注意:钉钉官方feedCard类型不支持@人,此字段为扩展预留)
AtUserIds []string // 被@人的用户userid(注意:钉钉官方feedCard类型不支持@人,此字段为扩展预留)
IsAtAll bool // 是否@所有人(注意:钉钉官方feedCard类型不支持@人,此字段为扩展预留)
}
SendFeedCardRequest 发送FeedCard消息请求参数
type SendLinkRequest ¶
type SendLinkRequest struct {
Webhook string // Webhook地址
Title string // 消息标题
Text string // 消息内容
MessageUrl string // 点击消息跳转的URL
PicUrl string // 图片URL(可选)
AtMobiles []string // 被@人的手机号(注意:钉钉官方link类型不支持@人,此字段为扩展预留)
AtUserIds []string // 被@人的用户userid(注意:钉钉官方link类型不支持@人,此字段为扩展预留)
IsAtAll bool // 是否@所有人(注意:钉钉官方link类型不支持@人,此字段为扩展预留)
}
SendLinkRequest 发送链接消息请求参数
type SendMarkdownRequest ¶
type SendMarkdownRequest struct {
Webhook string // Webhook地址
Title string // 首屏会话透出的展示内容
Text string // Markdown格式的消息内容
AtMobiles []string // 被@人的手机号
AtUserIds []string // 被@人的用户userid
IsAtAll bool // 是否@所有人
}
SendMarkdownRequest 发送Markdown消息请求参数
type SendTextRequest ¶
type SendTextRequest struct {
Webhook string // Webhook地址
Content string // 文本内容
AtMobiles []string // 被@人的手机号
AtUserIds []string // 被@人的用户userid
IsAtAll bool // 是否@所有人
}
SendTextRequest 发送文本消息请求参数
type WebhookActionCardButton ¶
type WebhookActionCardButton struct {
Title string `json:"title"` // 按钮标题
ActionURL string `json:"actionURL"` // 点击按钮触发的URL
}
WebhookActionCardButton ActionCard按钮
type WebhookActionCardContent ¶
type WebhookActionCardContent struct {
Title string `json:"title"` // 首屏会话透出的展示内容
Text string `json:"text"` // Markdown格式的消息
SingleTitle string `json:"singleTitle,omitempty"` // 单个按钮的标题
SingleURL string `json:"singleURL,omitempty"` // 单个按钮的跳转链接
BtnOrientation string `json:"btnOrientation,omitempty"` // 按钮排列方式:0-按钮竖直排列,1-按钮横向排列
Btns []*WebhookActionCardButton `json:"btns,omitempty"` // 按钮列表
}
WebhookActionCardContent Webhook ActionCard消息内容
type WebhookActionCardMessage ¶
type WebhookActionCardMessage struct {
MsgType string `json:"msgtype"` // 消息类型,固定为 "actionCard"
ActionCard *WebhookActionCardContent `json:"actionCard"` // ActionCard内容
At *WebhookAt `json:"at,omitempty"` // @人信息(注意:钉钉官方actionCard类型不支持@人,此字段为扩展预留)
}
WebhookActionCardMessage Webhook ActionCard消息请求体
type WebhookAt ¶
type WebhookAt struct {
AtMobiles []string `json:"atMobiles,omitempty"` // 被@人的手机号
AtUserIds []string `json:"atUserIds,omitempty"` // 被@人的用户userid
IsAtAll bool `json:"isAtAll,omitempty"` // 是否@所有人
}
WebhookAt @人信息
type WebhookFeedCardContent ¶
type WebhookFeedCardContent struct {
Links []*WebhookFeedCardLink `json:"links"` // 链接列表
}
WebhookFeedCardContent Webhook FeedCard消息内容
type WebhookFeedCardLink ¶
type WebhookFeedCardLink struct {
Title string `json:"title"` // 单条信息文本
MessageURL string `json:"messageURL"` // 点击单条信息到跳转链接
PicURL string `json:"picURL"` // 单条信息后面图片的URL
}
WebhookFeedCardLink FeedCard链接项
type WebhookFeedCardMessage ¶
type WebhookFeedCardMessage struct {
MsgType string `json:"msgtype"` // 消息类型,固定为 "feedCard"
FeedCard *WebhookFeedCardContent `json:"feedCard"` // FeedCard内容
At *WebhookAt `json:"at,omitempty"` // @人信息(注意:钉钉官方feedCard类型不支持@人,此字段为扩展预留)
}
WebhookFeedCardMessage Webhook FeedCard消息请求体
type WebhookLinkContent ¶
type WebhookLinkContent struct {
Title string `json:"title"` // 消息标题
Text string `json:"text"` // 消息内容,如果太长只会部分展示
MessageUrl string `json:"messageUrl"` // 点击消息跳转的URL
PicUrl string `json:"picUrl,omitempty"` // 图片URL
}
WebhookLinkContent Webhook 链接消息内容
type WebhookLinkMessage ¶
type WebhookLinkMessage struct {
MsgType string `json:"msgtype"` // 消息类型,固定为 "link"
Link *WebhookLinkContent `json:"link"` // 链接内容
At *WebhookAt `json:"at,omitempty"` // @人信息(注意:钉钉官方link类型不支持@人,此字段为扩展预留)
}
WebhookLinkMessage Webhook 链接消息请求体
type WebhookMarkdownContent ¶
type WebhookMarkdownContent struct {
Title string `json:"title"` // 首屏会话透出的展示内容
Text string `json:"text"` // Markdown格式的消息内容
}
WebhookMarkdownContent Webhook Markdown消息内容
type WebhookMarkdownMessage ¶
type WebhookMarkdownMessage struct {
MsgType string `json:"msgtype"` // 消息类型,固定为 "markdown"
Markdown *WebhookMarkdownContent `json:"markdown"` // Markdown内容
At *WebhookAt `json:"at"` // @人信息
}
WebhookMarkdownMessage Webhook Markdown消息请求体
type WebhookResponse ¶
type WebhookResponse struct {
ErrCode int `json:"errcode"` // 错误码,0表示成功
ErrMsg string `json:"errmsg"` // 错误信息
}
WebhookResponse Webhook响应结构
type WebhookTextContent ¶
type WebhookTextContent struct {
Content string `json:"content"` // 文本内容
}
WebhookTextContent Webhook文本消息内容
type WebhookTextMessage ¶
type WebhookTextMessage struct {
MsgType string `json:"msgtype"` // 消息类型,固定为 "text"
Text *WebhookTextContent `json:"text"` // 文本内容
At *WebhookAt `json:"at"` // @人信息
}
WebhookTextMessage Webhook文本消息请求体