Skip to content
DingTalk(dingding) 是钉钉机器人的 go 实现。支持 Docker、Jenkinsfile、命令行模式,module 模式,加签安全设置,支持链式语法创建消息,支持文本、链接、Markdown、ActionCard、FeedCard消息类型; DingTalk (dingding) is the go implementation of the DingTalk robot. Support Docker, Jenkinsfile, command line mode, module mode, signature security settings, chain syntax to create messages, support text, link, markd…
Go Makefile Dockerfile
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
client
cmd feat: add card message Feb 25, 2020
message feat: add card message Feb 25, 2020
security feat: version 1.0.0 Feb 21, 2020
version feat: add card message Feb 25, 2020
.gitignore
CHANGELOG.md
Dockerfile feat: add docker Feb 24, 2020
Makefile
README.md doc: format Feb 25, 2020
READMEEN.md doc: format Feb 25, 2020
go.mod
go.sum
main.go feat: version 1.0.0 Feb 21, 2020

README.md

dingtalk

English

DingTalk(dingding) 是钉钉机器人的 go 实现。支持 DockerJenkinsfile命令行模式,module 模式,支持加签安全设置,支持链式语法创建消息,支持文本、链接、Markdown、ActionCard、FeedCard 消息类型

文档

钉钉文档

特性

安装

Docker 安装

docker pull catchzeng/dingtalk

二进制安装

releases 下载相应平台的二进制可执行文件,然后加入到 PATH 环境变量即可。

go get 安装

go get github.com/CatchZeng/dingtalk

使用方法

Docker

docker run catchzeng/dingtalk dingtalk text -t 1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f -s SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68 -c "docker test"

Jenkinsfile

pipeline {
    agent {
        docker {
            image 'catchzeng/dingtalk:latest'
        }
    }
    environment {
        DING_TOKEN = '1c53e149ba5de6597cxxxxxx0e901fdxxxxxx80b8ac141e4a75afdc44c85ca4f'
        DING_SECRET = 'SECb90923e19e58b466481e9e7b7a5bxxxxxx4531axxxxxxad3967fb29f0eae5c68'
    }
    stages {
        stage('notify') {
            steps {
                sh 'dingtalk link -t ${DING_TOKEN} -s ${DING_SECRET} -i "标题" -e "信息" -u "https://catchzeng.com/" -p "https://catchzeng.com/img/avatar-hux.jpg" -a'
            }
        }
    }
}

作为 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","177010xxx61"

Help

  • dingtalk

    $ dingtalk -h
    dingtalk is a command line tool for DingTalk
    
    Usage:
      dingtalk [command]
    
    Available Commands:
      actionCard  send actionCard message with DingTalk robot
      feedCard    send feedCard message with DingTalk robot
      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
      version     dingtalk version
    
    Flags:
      -m, --atMobiles strings   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 strings       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 strings       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 strings       atMobiles
      -a, --isAtAll                 isAtAll
      -s, --secret string           secret
      -t, --token string            access_token
  • actionCard

    $ dingtalk actionCard -h
    send actionCard message with DingTalk robot
    
    Usage:
      dingtalk actionCard [flags]
    
    Flags:
      -c, --btnActionURLs strings   btnActionURLs
      -o, --btnOrientation string   btnOrientation
      -b, --btnTitles strings       btnTitles
      -h, --help                    help for actionCard
      -d, --hideAvatar string       hideAvatar
      -n, --singleTitle string      singleTitle
      -u, --singleURL string        singleURL
      -e, --text string             text
      -i, --title string            title
    
    Global Flags:
      -m, --atMobiles strings   atMobiles
      -a, --isAtAll             isAtAll
      -s, --secret string       secret
      -t, --token string        access_token
  • feedCard

    dingtalk feedCard -h
    send feedCard message with DingTalk robot
    
    Usage:
      dingtalk feedCard [flags]
    
    Flags:
      -h, --help                  help for feedCard
      -u, --messageURLs strings   messageURLs
      -p, --picURLs strings       picURLs
      -i, --titles strings        titles
    
    Global Flags:
      -m, --atMobiles strings   atMobiles
      -a, --isAtAll             isAtAll
      -s, --secret string       secret
      -t, --token string        access_token
You can’t perform that action at this time.