blinkbean / dingtalk

golang钉钉机器人客户端。支持文本、链接、Markdown、ActionCard、FeedCard类型消息的发送,Outgoing机器人消息的接收。通过钉钉机器人接口和不同消息的封装,达到简单快速发送不同类型消息的目的。
MIT License
247 stars 59 forks source link
dingding golang

Dingtalk

[![Go Report Card](https://goreportcard.com/badge/github.com/blinkbean/dingtalk)](https://goreportcard.com/report/github.com/blinkbean/dingtalk) [![Production Ready](https://img.shields.io/badge/production-ready-blue.svg?style=flat)](https://github.com/blinkbean/dingtalk) [![License](https://img.shields.io/github/license/blinkbean/dingtalk.svg?style=flat)](https://github.com/blinkbean/dingtalk) [![Release](https://img.shields.io/github/v/release/blinkbean/dingtalk?style=flat)](https://github.com/blinkbean/dingtalk/releases) [![GitHub pull requests](https://img.shields.io/github/issues-pr/blinkbean/dingtalk?style=flat)](https://github.com/blinkbean/dingtalk/pulls) [![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/blinkbean/dingtalk?style=flat)](https://github.com/blinkbean/dingtalk/pulls?q=is%3Apr+is%3Aclosed) [![GitHub issues](https://img.shields.io/github/issues/blinkbean/dingtalk?style=flat)](https://github.com/blinkbean/dingtalk/issues) [![GitHub closed issues](https://img.shields.io/github/issues-closed/blinkbean/dingtalk?style=flat)](https://github.com/blinkbean/dingtalk/issues?q=is%3Aissue+is%3Aclosed) ![Stars](https://img.shields.io/github/stars/blinkbean/dingtalk?style=flat) ![Forks](https://img.shields.io/github/forks/blinkbean/dingtalk?style=flat)

钉钉机器人消息封装——Golang

目前自定义机器人支持

使用

创建钉钉群机器人

  1. 选择添加自定义机器人。
  2. 安全设置 共有关键词、加签、IP白名单三种设置,需要根据情况进行选择。 Xnip2020-07-05_15-55-24.jpg
  3. 选择自定义关键词,这里设置的关键词在初始化机器人的时候会用到。

    获取

    • go get github.com/blinkbean/dingtalk

      初始化

    • 
      // key 创建钉钉机器人需要设置的关键词,默认为`.`
      func InitDingTalk(tokens []string, key string) *dingTalk

    // 加签方式创建钉钉机器人 // 加签机器人 access_token和secret一一对应,在创建机器人是获取 func InitDingTalkWithSecret(tokens string, secret string) *DingTalk

    -   ```go
    import "github.com/blinkbean/dingtalk"
    
    func main() {
        // 单个机器人有单位时间内消息条数的限制,如果有需要可以初始化多个token,发消息时随机发给其中一个机器人。
        var dingToken = []string{"7bd675b66646ba890046c2198257576470099e1bda0770bad7dd6684fb1e0415"}
        cli := dingtalk.InitDingTalk(dingToken, ".")
        cli.SendTextMessage("content")
    }

OutGoing

Text类型

Link类型

Markdown类型

整体跳转ActionCard类型

独立跳转ActionCard类型

FeedCard类型