dingding

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DingTalkButton

type DingTalkButton struct {
	Title     string `json:"title"`
	ActionURL string `json:"actionURL"`
}
type DingTalkLink struct {
	Title      string `json:"title"`      // 消息标题
	MessageURL string `json:"messageURL"` // 消息跳转链接
	PicURL     string `json:"picURL"`     // 消息图片链接
}

type DingTalkMessage

type DingTalkMessage struct {
	MsgType string `json:"msgtype"` // 消息类型
	Text    struct {
		Content string `json:"content"` // 消息内容
	} `json:"text,omitempty"`
	Markdown struct {
		Title string `json:"title"` // 消息标题
		Text  string `json:"text"`  // 消息内容
	} `json:"markdown,omitempty"`
	Link struct {
		Text       string `json:"text"`       // 消息内容
		Title      string `json:"title"`      // 消息标题
		PicUrl     string `json:"picUrl"`     //图片URL
		MessageUrl string `json:"messageUrl"` //点击消息跳转的URL,打开方式如下 移动端,在钉钉客户端内打开 PC端 默认侧边栏打开
	} `json:"link,omitempty"`
	ActionCard struct {
		Title          string `json:"title"`          // 消息标题
		Text           string `json:"text"`           // 消息内容
		SingleTitle    string `json:"singleTitle"`    // 单个按钮标题
		SingleURL      string `json:"singleURL"`      // 单个按钮跳转链接
		BtnOrientation int    `json:"btnOrientation"` // 按钮排列方式,0表示竖直排列,1表示横向排列
		Btns           []struct {
			Title     string `json:"title"`     //首屏会话透出的展示内容
			ActionURL string `json:"actionURL"` //点击按钮触发的URL
		} `json:"btns,omitempty"`
	} `json:"actionCard,omitempty"`
	FeedCard struct {
		Links []struct {
			Title      string `json:"title"`      // 消息标题
			MessageURL string `json:"messageURL"` // 消息跳转链接
			PicURL     string `json:"picURL"`     // 消息图片链接
		} `json:"links"`
	} `json:"feedCard,omitempty"`
	At struct {
		AtMobiles []string `json:"atMobiles,omitempty"` // 被@人的手机号
		IsAtAll   bool     `json:"isAtAll,omitempty"`   // 是否@所有人
	} `json:"at,omitempty"`
}

DingTalkMessage 钉钉机器人消息结构体

type RequestStatus

type RequestStatus struct {
	Errcode int    `json:"errcode"`
	Errmsg  string `json:"errmsg"`
}

RequestStatus 钉钉返回状态吗

func SendDingTalkRobotMessage

func SendDingTalkRobotMessage(webhookURL string, message DingTalkMessage) (req *RequestStatus, err error)

SendDingTalkRobotMessage 发送钉钉消息

该示例会发送一个text类型的钉钉机器人消息,内容为"Hello, World!",并且@了手机号码为12345678901和23456789012的用户。 您可以按照上述示例修改DingTalkRobotMessage结构体中的字段以发送不同类型的消息。

		webhookURL := fmt.Sprintf("https://oapi.dingtalk.com/robot/send?access_token=%s", access_token)
	message := DingTalkRobotMessage{
		MsgType: "text",
		Text: struct {
			Content string `json:"content"`
		}{
			Content: "Hello, World!",
		},
		At: struct {
			AtMobiles []string `json:"atMobiles,omitempty"`
			IsAtAll   bool     `json:"isAtAll"`
		}{
			AtMobiles: []string{"12345678901", "23456789012"},
			IsAtAll:   false,
		},
	}
	err := SendDingTalkRobotMessage(webhookURL, message)
	if err != nil {
		fmt.Println(err)
	}
   其他请求查看官方文档:https://open.dingtalk.com/document/orgapp/custom-robot-access

func SendDingTalkRobotMessageText

func SendDingTalkRobotMessageText(webhookURL, Content string, AtMobiles []string, IsAtAll bool) (req *RequestStatus, err error)

SendDingTalkRobotMessageText 文本类型

	参数:
	webhookUrl: string类型,机器人的Webhook地址
	content: string类型,要发送的文本消息内容
	atMobiles: []string类型,需要被@的手机号列表,可以为空
	isAtAll: bool类型,是否需要@所有人,默认为false,即不@所有人
	返回值:
	 RequestStatus 类型如果发送成功  {"errcode":0,"errmsg":"ok"}
     error类型,如果发送成功,返回nil;否则返回错误信息

func SendFeedCardMessage

func SendFeedCardMessage(webhookUrl string, links []DingTalkLink, atMobiles []string, isAtAll bool) (req *RequestStatus, err error)

SendFeedCardMessage FeedCard类型

参数:
webhookUrl: string类型,机器人的Webhook地址
links: []DingTalkLink类型,链接列表,每个链接包含标题、描述和点击后跳转的URL
atMobiles: []string类型,需要被@的手机号列表,可以为空
isAtAll: bool类型,是否需要@所有人,默认为false,即不@所有人
返回值:
error类型,如果发送成功,返回nil;否则返回错误信息

func SendIndependentActionCardMessage

func SendIndependentActionCardMessage(webhookUrl, title, content string, btnOrientation int, btns []DingTalkButton, atMobiles []string, isAtAll bool) (req *RequestStatus, err error)

SendIndependentActionCardMessage 用于发送独立跳转ActionCard类型的消息

	参数:
	webhookUrl: string类型,机器人的Webhook地址
	title: string类型,ActionCard消息的标题
	content: string类型,ActionCard消息的正文内容
	btns: []DingTalkButton类型,按钮列表,每个按钮包含标题和点击后跳转的URL
    btnOrientation: string类型 0:按钮竖直排列 1:按钮横向排列
	atMobiles: []string类型,需要被@的手机号列表,可以为空
	isAtAll: bool类型,是否需要@所有人,默认为false,即不@所有人
	返回值:
    RequestStatus 类型如果发送成功  {"errcode":0,"errmsg":"ok"}
	error类型,如果发送成功,返回nil;否则返回错误信息

func SendLinkMessage

func SendLinkMessage(webhookUrl, title, text, messageUrl, picUrl string, atMobiles []string, isAtAll bool) (req *RequestStatus, err error)

SendLinkMessage 发送Link类型的消息

	参数:
	webhookUrl: string类型,机器人的Webhook地址
	title: string类型,Markdown消息的标题
	content: string类型,Markdown消息的正文内容
	atMobiles: []string类型,需要被@的手机号列表,可以为空
	isAtAll: bool类型,是否需要@所有人,默认为false,即不@所有人
	返回值:
	 RequestStatus 类型如果发送成功  {"errcode":0,"errmsg":"ok"}
     error类型,如果发送成功,返回nil;否则返回错误信息

func SendMarkdownMessage

func SendMarkdownMessage(webhookUrl, title, text string, atMobiles []string, isAtAll bool) (req *RequestStatus, err error)

SendMarkdownMessage 发送Markdown类型的消息

	参数:
	webhookUrl: string类型,机器人的Webhook地址
	title: string类型,Markdown消息的标题
	text: string类型,Markdown消息的正文内容
	atMobiles: []string类型,需要被@的手机号列表,可以为空
	isAtAll: bool类型,是否需要@所有人,默认为false,即不@所有人
	返回值:
	 RequestStatus 类型如果发送成功  {"errcode":0,"errmsg":"ok"}
     error类型,如果发送成功,返回nil;否则返回错误信息
		标题
		# 一级标题
		## 二级标题
		### 三级标题
		#### 四级标题
		##### 五级标题
		###### 六级标题
		引用
		> A man who stands for nothing will fall for anything.
		文字加粗、斜体
		**bold**
		*italic*
		链接
		[this is a link](http://name.com)
		图片(建议不要超过20张)
		![](http://name.com/pic.jpg)
		无序列表
		- item1
		- item2
		有序列表
		1. item1
		2. item2

func SendWholeActionCardMessage

func SendWholeActionCardMessage(webhookUrl, title, content, singleTitle, singleUrl string, btnOrientation int, atMobiles []string, isAtAll bool) (req *RequestStatus, err error)

SendWholeActionCardMessage 发送整体跳转ActionCard类型的消息

    参数:
	webhookUrl: string类型,机器人的Webhook地址
	title: string类型,Link消息的标题
	text: string类型,Link消息的描述文本
	messageUrl: string类型,点击消息后跳转的URL
	picUrl: string类型,图片URL,可以为空
	atMobiles: []string类型,需要被@的手机号列表,可以为空
    btnOrientation: string类型 0:按钮竖直排列 1:按钮横向排列
	isAtAll: bool类型,是否需要@所有人,默认为false,即不@所有人
	返回值:
	 RequestStatus 类型如果发送成功  {"errcode":0,"errmsg":"ok"}
     error类型,如果发送成功,返回nil;否则返回错误信息

Jump to

Keyboard shortcuts

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