1 Star 0 Fork 1

邹富星 / dingrobot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Dingrobot

GoDoc Go Report Card

钉钉自定义机器人 Golang API.

支持的消息类型:

  • 文本类型
  • link 类型
  • markdown 类型
  • 整体跳转 ActionCard 类型

Installation

Install:

go get -u github.com/royeo/dingrobot

Import:

import "github.com/royeo/dingrobot"

Quick start

发送文本类型的消息:

func main() {
	// You should replace the webhook here with your own.
	webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx"
	robot := dingrobot.NewRobot(webhook)

	content := "我就是我,  @1825718XXXX 是不一样的烟火"
	atMobiles := []string{"1825718XXXX"}
	isAtAll := false

	err := robot.SendText(content, atMobiles, isAtAll)
	if err != nil {
		log.Fatal(err)
	}
}

发送 link 类型的消息:

func main() {
	// You should replace the webhook here with your own.
	webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx"
	robot := dingrobot.NewRobot(webhook)

	title := "自定义机器人协议"
	text := "群机器人是钉钉群的高级扩展功能。群机器人可以将第三方服务的信息聚合到群聊中,实现自动化的信息同步。例如:通过聚合GitHub,GitLab等源码管理服务,实现源码更新同步;通过聚合Trello,JIRA等项目协调服务,实现项目信息同步。不仅如此,群机器人支持Webhook协议的自定义接入,支持更多可能性,例如:你可将运维报警提醒通过自定义机器人聚合到钉钉群。"
	messageUrl := "https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.Rqyvqo&treeId=257&articleId=105735&docType=1"
	picUrl := ""

	err := robot.SendLink(title, text, messageUrl, picUrl)
	if err != nil {
		log.Fatal(err)
	}
}

发送 markdown 类型的消息:

func main() {
	// You should replace the webhook here with your own.
	webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx"
	robot := dingrobot.NewRobot(webhook)

	title := "杭州天气"
	text := "#### 杭州天气  \n > 9度,@1825718XXXX 西北风1级,空气良89,相对温度73%\n\n > ![screenshot](http://i01.lw.aliimg.com/media/lALPBbCc1ZhJGIvNAkzNBLA_1200_588.png)\n  > ###### 10点20分发布 [天气](http://www.thinkpage.cn/) "
	atMobiles := []string{"1825718XXXX"}
	isAtAll := false

	err := robot.SendMarkdown(title, text, atMobiles, isAtAll)
	if err != nil {
		log.Fatal(err)
	}
}

发送整体跳转 ActionCard 类型的消息:

func main() {
	// You should replace the webhook here with your own.
	webhook := "https://oapi.dingtalk.com/robot/send?access_token=xxx"
	robot := dingrobot.NewRobot(webhook)

	title := "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身"
	text := "![screenshot](@lADOpwk3K80C0M0FoA) \n #### 乔布斯 20 年前想打造的苹果咖啡厅 \n\n Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划"
	singleTitle := "阅读全文"
	singleURL := "https://www.dingtalk.com/"
	btnOrientation := "0"
	hideAvatar := "0"

	err := robot.SendActionCard(title, text, singleTitle, singleURL, btnOrientation, hideAvatar)
	if err != nil {
		log.Fatal(err)
	}
}

License

MIT Copyright (c) 2018 Royeo

MIT License Copyright (c) 2018 Royeo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

DingTalk robot golang API 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/zoufuxing/dingrobot.git
git@gitee.com:zoufuxing/dingrobot.git
zoufuxing
dingrobot
dingrobot
master

搜索帮助