Dingrobot
钉钉自定义机器人 Golang API.
支�?的消�?�类型:
- 文本类型
- link 类型
- markdown 类型
- 整体跳转 ActionCard 类型
Installation
Install:
go get -u github.com/royeo/dingrobotImport:
import "github.com/royeo/dingrobot"Quick start
�?��?文本类型的消�?�:
func main() {
// You should replace the webhook here with your own.
webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx"
robot := dingrobot.NewRobot(webhook)
content := "我就是我, @1825718XXXX 是�?ä¸€æ ·çš„çƒŸï¿½?�"
atMobiles := []string{"1825718XXXX"}
isAtAll := false
err := robot.SendText(content, atMobiles, isAtAll)
if err != nil {
log.Fatal(err)
}
}�?��? link 类型的消�?�:
func main() {
// You should replace the webhook here with your own.
webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx"
robot := dingrobot.NewRobot(webhook)
title := "自定义机器人�??议"
text := "群机器人是钉钉群的高级扩展功能。群机器人�?�以将第三方�?务的信�?��?��?�到群�?�ä¸ï¼Œå®žçŽ°è‡ªåŠ¨åŒ–çš„ä¿¡ï¿½?��?�æ¥ã€‚例如:通过�?��?�GitHub,GitLabç‰ï¿½?�?管�?��?务,实现�?�?更新�?�æ¥ï¼›é€šè¿‡ï¿½?��?�Trello,JIRAç‰é¡¹ç›®ï¿½??调�?务,实现项目信�?��?�æ¥ã€‚�?仅如æ¤ï¼Œç¾¤æœºå™¨äººæ”¯ï¿½?Webhook�??议的自定义接入,支�?更多�?ï¿½èƒ½æ€§ï¼Œä¾‹å¦‚ï¼šä½ ï¿½?�将�?维报è¦ï¿½??醒通过自定义机器人�?��?�到钉钉群。"
messageUrl := "https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.Rqyvqo&treeId=257&articleId=105735&docType=1"
picUrl := ""
err := robot.SendLink(title, text, messageUrl, picUrl)
if err != nil {
log.Fatal(err)
}
}�?��? markdown 类型的消�?�:
func main() {
// You should replace the webhook here with your own.
webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx"
robot := dingrobot.NewRobot(webhook)
title := "�?�州天气"
text := "#### �?�州天气 \n > 9度,@1825718XXXX 西北风1级,空气良89,相对温度73%\n\n > \n > ###### 10点20分�?�布 [天气](http://www.thinkpage.cn/) "
atMobiles := []string{"1825718XXXX"}
isAtAll := false
err := robot.SendMarkdown(title, text, atMobiles, isAtAll)
if err != nil {
log.Fatal(err)
}
}�?��?整体跳转 ActionCard 类型的消�?�:
func main() {
// You should replace the webhook here with your own.
webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx"
robot := dingrobot.NewRobot(webhook)
title := "乔布斯 20 年�?æƒ³æ‰“é€ ä¸€é—´è‹¹æžœå’–å•¡åŽ…ï¼Œè€Œå®ƒæ£æ˜¯ Apple Store 的�?身"
text := " \n #### 乔布斯 20 年�?æƒ³æ‰“é€ çš„è‹¹æžœå’–å•¡åŽ… \n\n Apple Store 的设计æ£ä»ŽåŽŸï¿½?�满满的科技感走�?�生活化,而其生活化的走�?�其实�?�以追溯到 20 年�?苹果一个建立咖啡馆的计划"
singleTitle := "阅读全文"
singleURL := "https://www.dingtalk.com/"
btnOrientation := "0"
hideAvatar := "0"
err := robot.SendActionCard(title, text, singleTitle, singleURL, btnOrientation, hideAvatar)
if err != nil {
log.Fatal(err)
}
}License
MIT Copyright (c) 2018 Royeo