Code Monkey home page Code Monkey logo

dingtalk's Introduction

dingtalk

钉钉群机器人SDK

安装

go get github.com/shockerli/dingtalk

使用

初始化配置

var robot = dingtalk.NewRobotCustom()
robot.SetWebhook("your_robot_webhook")
robot.SetSecret("your_secret") // 可选

Text

robot.SendText("TEST: Text")

AtAll

robot.SendText("TEST: Text&AtAll", robot.AtAll())

AtMobiles

robot.SendText("TEST: Text&AtMobiles", robot.AtMobiles("19900001111"))

Link

robot.SendLink(
    "TEST: Link",
    "link content",
    "https://github.com/shockerli",
    "https://www.wangbase.com/blogimg/asset/202101/bg2021011601.jpg",
)

Markdown

robot.SendMarkdown("TEST: Markdown", markdown)

robot.SendMarkdown("TEST: Markdown&AtAll", markdown, robot.AtAll())

robot.SendMarkdown("TEST: Markdown&AtMobiles", markdown, robot.AtMobiles("19900001111"))

ActionCard

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"),
)

FeedCard

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"),
)

Outgoing

// 获取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 {
    // ...
}

获取群机器人Token

  • 选择自定义机器人

    选择自定义机器人

  • 设置机器人

    设置机器人

  • 获取Webhook&token

    获取Webhook

测试

  1. 打开 robot_test.go 文件,修改 your_robot_webhookyour_secret
  2. 运行单元测试 go test -v *_test.go

dingtalk's People

Contributors

shockerli avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.