ding

package
v0.0.0-...-4ea7438 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Btn

type Btn struct {
	Title     string `json:"title" comment:"按钮名称,必须"`
	ActionURL string `json:"actionURL" comment:"按钮点击后打开的网址,必须"`
}

Btn actionCard类型消息多个按钮定义结构

type Ding

type Ding struct {
	// contains filtered or unexported fields
}

Ding 钉钉机器人消息发送客户端

  • ① 每个钉钉机器人每分钟最多发送20条。如果超过20条,会限流10分钟
  • ② 支持 文本 (text)、链接 (link)、markdown(markdown)、ActionCard、FeedCard消息类型

func New

func New(token, secret string, enable bool, client *http.Client) *Ding

New 创建钉钉客户端

  • token 钉钉access_token,钉钉机器人设置时 Webhook 的URL里的access_token值
  • secret 钉钉secret,钉钉机器人设置时 启用加签获得以 SEC 开头的秘钥令牌
  • client 自定义 *http.Client 可自主控制http请求客户端,给 nil 不则使用默认

func (*Ding) ActionCard

func (d *Ding) ActionCard(title, msg, btnText, btnURL string) error

ActionCard 发送只有一个按钮的整体跳转类型单个卡片消息

  • title 卡片消息的标题
  • msg 卡片消息的正文<支持MarkDown格式>
  • btnText 卡片消息按钮上的文字
  • btnURL 卡片消息按钮(其实是整个卡片)被点击后打开的URL

func (*Ding) ActionCardWithMultiBtn

func (d *Ding) ActionCardWithMultiBtn(title, msg string, btn []Btn, isBtnVertical bool) error

ActionCardWithMultiBtn 发送有多个按钮的单个卡片消息

  • title 卡片消息的标题
  • msg 卡片消息的正文<支持MarkDown格式>
  • btn Btn 切片 卡片消息多个按钮定义
  • isBtnVertical 多个按钮连接是否垂直排列<即多个按钮是否从上至下依次排列> true垂直 false水平

func (*Ding) FeedCard

func (d *Ding) FeedCard(feed []Feed) error

FeedCard 信息流消息<类似微信公众号多多图消息>

func (d *Ding) Link(title, msg, msgURL, picURL string) error

Link 发送卡片链接信息

  • title 卡片消息的标题
  • msg 卡片消息的正文
  • msgURL 卡片消息被点击后打开的URL
  • picURL 卡片消息的封面图<没有图片可传空字符串>

func (*Ding) Markdown

func (d *Ding) Markdown(title, msg string, atMobiles []string, isAtAll bool) error

Markdown 发送markdown信息

  • title MD格式消息的标题,会以 ## 即h2形式显示在首行
  • msg MD的内容<注意使用MarkDown格式,支持链接、图片>
  • atMobiles 需要 at 的人的手机号
  • isAtAll 是否要 at 全员 支持的MD语法见:https://developers.dingtalk.com/document/app/custom-robot-access#section-e4x-4y8-9k0 例子1: var account = "acc" var msg = "login use mobile" var time = "2021-07-23 14:48:44" msg = fmt.Sprintf("> Account: %s \n> Msg: %s \n> Time: %s \n", account, msg, time) c.Markdown("login info", msg, nil, false)

--------------------------------------------------------------------------------------------

		例子2:
     msg := []string{
         "## panic",
         "> Env: " + conf.Config.Server.Env,
         "> Code: " + strconv.Itoa(code),
         "> Msg: " + message,
         "> ReqID: " + utils.IFaceToString(reqID),
         "> Url: " + ctx.Request.URL.String(),
         "> Method: " + ctx.Request.Method,
         "> Stack:" + stack,
     }
     msg := strings.Join(msg, "  \n")
     c.Markdown("", msg, nil, false)

func (*Ding) Text

func (d *Ding) Text(msg string, atMobiles []string, isAtAll bool) error

Text 发送文本信息

  • msg 文本消息内容,不宜过长
  • atMobiles 需要 at 的人的手机号
  • isAtAll 是否要 at 全员

type Feed

type Feed struct {
	Title      string `json:"title" comment:"标题,必须"`
	MessageURL string `json:"messageURL" comment:"点击后打开的网址,必须"`
	PicURL     string `json:"picURL" comment:"图片地址,必须"`
}

Feed feed流消息子结构<多图文>

Jump to

Keyboard shortcuts

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