钉钉群机器人SDK
go get github.com/shockerli/dingtalk
var robot = dingtalk.NewRobotCustom()
robot.SetWebhook("your_robot_webhook")
robot.SetSecret("your_secret") // 可选
robot.SendText("TEST: Text")
robot.SendText("TEST: Text&AtAll", robot.AtAll())
robot.SendText("TEST: Text&AtMobiles", robot.AtMobiles("19900001111"))
robot.SendLink(
"TEST: Link",
"link content",
"https://github.com/shockerli",
"https://www.wangbase.com/blogimg/asset/202101/bg2021011601.jpg",
)
robot.SendMarkdown("TEST: Markdown", markdown)
robot.SendMarkdown("TEST: Markdown&AtAll", markdown, robot.AtAll())
robot.SendMarkdown("TEST: Markdown&AtMobiles", markdown, robot.AtMobiles("19900001111"))
robot.SendActionCard(
"TEST: ActionCard&SingleCard",
"SingleCard content",
robot.SingleCard("阅读全文", "https://github.com/shockerli"),
)
robot.SendActionCard(
"TEST: ActionCard&MultiCard",
"MultiCard content",
robot.MultiCard("内容不错", "https://github.com/shockerli"),
robot.MultiCard("不感兴趣", "https://github.com/shockerli"),
)
robot.SendActionCard(
"TEST: ActionCard&BtnOrientation",
"BtnOrientation content",
robot.MultiCard("内容不错", "https://github.com/shockerli"),
robot.MultiCard("不感兴趣", "https://github.com/shockerli"),
robot.BtnOrientation("0"),
)
robot.SendActionCard(
"TEST: ActionCard&Image",
"![xxx](https://www.wangbase.com/blogimg/asset/202101/bg2021011601.jpg)\n\nSingleCard content with image",
robot.SingleCard("阅读全文", "https://github.com/shockerli"),
)
robot.SendActionCard(
"TEST: ActionCard&HideAvatar",
"24565\n\n![xxx](https://www.wangbase.com/blogimg/asset/202101/bg2021011601.jpg)\n\nSingleCard content with image",
robot.SingleCard("阅读全文", "https://github.com/shockerli"),
robot.HideAvatar("1"),
)
robot.SendFeedCard(
robot.FeedCard("3月15日起,Chromium 不能再调用谷歌 API", "https://bodhi.fedoraproject.org/updates/FEDORA-2021-48866282e5%29", "https://www.wangbase.com/blogimg/asset/202101/bg2021012506.jpg"),
robot.FeedCard("考古学家在英国发现两枚11世纪北宋时期的中国硬币", "https://www.caitlingreen.org/2020/12/another-medieval-chinese-coin-from-england.html", "https://www.wangbase.com/blogimg/asset/202101/bg2021012208.jpg"),
)
// 获取HTTP请求Body
var contents = getRequestBody()
// 解析Outgoing内容
og, err := robot.ParseOutgoing(contents)
if err != nil {
// ...
}
// 自定义业务逻辑,生成响应的Text消息内容
var res = doSomeThing(og)
// 发送回复消息
err = robot.SendText(res, robot.WithOutgoing(og))
if err != nil {
// ...
}
- 打开
robot_test.go
文件,修改your_robot_webhook
和your_secret
; - 运行单元测试
go test -v *_test.go
;