35
golang 钉钉机器人命令行工具&module
source link: https://catchzeng.com/2020/02/22/dingtalk/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
前言
最近在优化持续集成,之前使用 Python 写过钉钉机器人,不过随着项目往 golang 发展,于是想去掉 Python 的依赖。另外,想着如果后台服务有些重要的事项,可以通知到钉钉,也想着做个 go module 供项目使用。本来想直接 github 上找一个,结果搜索了老半天没看到一个符合的,于是,手撸了一个。
DingTalk
DingTalk(dingding) 是钉钉机器人的 go 实现。支持 加签
安全设置,支持 链式语法
创建消息,支持文本、链接、Markdown 消息类型
特性
安装
二进制安装
到 releases 下载相应平台的二进制可执行文件,然后加入到 PATH 环境变量即可。
go get 安装
go get github.com/CatchZeng/dingtalk
使用方法
作为 module
package main import ( "log" "github.com/CatchZeng/dingtalk/client" "github.com/CatchZeng/dingtalk/message" ) func main() { dingTalk := client.DingTalk{ AccessToken: "1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f", Secret: "SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68", } msg := message.NewTextMessage().SetContent("测试文本&at 某个人").SetAt([]string{"177010xxx60"}, false) dingTalk.Send(msg) }
命令行工具
Demo
dingtalk text -t 1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f -s SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68 -c "测试命令行 & at 某个人" -m ["177010xxx60"]
Help
-
dingtalk
$ dingtalk -h dingtalk is a command line tool for DingTalk Usage: dingtalk [command] Available Commands: help Help about any command link send link message with DingTalk robot markdown send markdown message with DingTalk robot text send text message with DingTalk robot Flags: -m, --atMobiles stringArray atMobiles -h, --help help for dingtalk -a, --isAtAll isAtAll -s, --secret string secret -t, --token string access_token Use "dingtalk [command] --help" for more information about a command.
-
text
$ dingtalk text -h send text message with DingTalk robot Usage: dingtalk text [flags] Flags: -c, --content string content -h, --help help for text Global Flags: -m, --atMobiles stringArray atMobiles -a, --isAtAll isAtAll -s, --secret string secret -t, --token string access_token
-
link
$ dingtalk link -h send link message with DingTalk robot Usage: dingtalk link [flags] Flags: -h, --help help for link -u, --messageURL string messageURL -p, --picURL string picURL -e, --text string text -i, --title string title Global Flags: -m, --atMobiles stringArray atMobiles -a, --isAtAll isAtAll -s, --secret string secret -t, --token string access_token
-
markdown
$ dingtalk markdown -h send markdown message with DingTalk robot Usage: dingtalk markdown [flags] Flags: -h, --help help for markdown -e, --text string text -i, --title string title Global Flags: -m, --atMobiles stringArray atMobiles -a, --isAtAll isAtAll -s, --secret string secret -t, --token string access_token
本文总阅读量次
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK