{"id":23578318,"url":"https://github.com/leitingting08/ding-bot-sdk","last_synced_at":"2025-05-05T23:49:16.911Z","repository":{"id":41174213,"uuid":"330292563","full_name":"leitingting08/ding-bot-sdk","owner":"leitingting08","description":"Dingbot customize  node sdk ","archived":false,"fork":false,"pushed_at":"2021-12-22T02:07:43.000Z","size":196,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-29T18:12:53.756Z","etag":null,"topics":["dingding-bot","node"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leitingting08.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-17T01:33:38.000Z","updated_at":"2024-06-22T09:48:42.000Z","dependencies_parsed_at":"2022-08-30T22:13:11.728Z","dependency_job_id":null,"html_url":"https://github.com/leitingting08/ding-bot-sdk","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leitingting08%2Fding-bot-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leitingting08%2Fding-bot-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leitingting08%2Fding-bot-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leitingting08%2Fding-bot-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leitingting08","download_url":"https://codeload.github.com/leitingting08/ding-bot-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252596365,"owners_count":21773843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dingding-bot","node"],"created_at":"2024-12-26T22:38:53.045Z","updated_at":"2025-05-05T23:49:16.892Z","avatar_url":"https://github.com/leitingting08.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 钉钉自定义机器人的封装\n\n[官方文档](https://ding-doc.dingtalk.com/document/app/custom-robot-access)\n\n## 安装\n\n```\nnpm install ding-bot-sdk\n# or\nyarn add ding-bot-sdk\n```\n\n## 初始化\n\n```\nimport Bot from 'ding-bot-sdk'\n# or\nconst Bot = require('ding-bot-sdk')\n\n// Webhook地址: https://oapi.dingtalk.com/robot/send?access_token=xxx\nconst bot = new Bot({\n  base_url: 'https://oapi.dingtalk.com/robot/send', // 可选 不填默认 https://oapi.dingtalk.com/robot/send\n  access_token: 'xxx', // Webhook地址后的access_token // 必填\n  secret: 'xxx' // 安全设置：加签的secret 必填\n}) \n```\n\n## 发送消息\n\n[格式和钉钉机器人开发文档保持一致](https://ding-doc.dingtalk.com/document/app/custom-robot-access)\n\ntext类型，返回回调内容\n\n```js\nbot.send({\n  \"msgtype\": \"text\",\n  \"text\": {\n      \"content\": \"我就是我, @150XXXXXXXX 是不一样的烟火\"\n  },\n  \"at\": {\n      \"atMobiles\": [\n          \"150XXXXXXXX\"\n      ], \n      \"isAtAll\": false\n  }\n}).then(res=\u003e{\n  console.log('res',res)\n}).catch(error=\u003e{\n  console.log('error',error)\n})\n```\n\nlink类型\n\n```js\nbot.send({\n    \"msgtype\": \"link\", \n    \"link\": {\n        \"text\": \"这个即将发布的新版本，创始人xx称它为红树林。而在此之前，每当面临重大升级，产品经理们都会取一个应景的代号，这一次，为什么是红树林\", \n        \"title\": \"时代的火车向前开\", \n        \"picUrl\": \"\", \n        \"messageUrl\": \"https://www.dingtalk.com/s?__biz=MzA4NjMwMTA2Ng==\u0026mid=2650316842\u0026idx=1\u0026sn=60da3ea2b29f1dcc43a7c8e4a7c97a16\u0026scene=2\u0026srcid=09189AnRJEdIiWVaKltFzNTw\u0026from=timeline\u0026isappinstalled=0\u0026key=\u0026ascene=2\u0026uin=\u0026devicetype=android-23\u0026version=26031933\u0026nettype=WIFI\"\n    }\n})\n```\n\nmarkdown类型\n\n```js\nbot.send({\n    \"msgtype\": \"markdown\",\n    \"markdown\": {\n        \"title\":\"杭州天气\",\n        \"text\": \"#### 杭州天气 @150XXXXXXXX \\n\u003e 9度，西北风1级，空气良89，相对温度73%\\n\u003e ![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png)\\n\u003e ###### 10点20分发布 [天气](https://www.dingtalk.com) \\n\"\n    },\n    \"at\": {\n        \"atMobiles\": [\n            \"150XXXXXXXX\"\n        ],\n        \"isAtAll\": false\n    }\n})\n```\n\n整体跳转ActionCard类型\n\n```js\nbot.send({\n    \"actionCard\": {\n        \"title\": \"乔布斯 20 年前想打造一间苹果咖啡厅，而它正是 Apple Store 的前身\", \n        \"text\": \"![screenshot](https://gw.alicdn.com/tfs/TB1ut3xxbsrBKNjSZFpXXcXhFXa-846-786.png) \n ### 乔布斯 20 年前想打造的苹果咖啡厅 \n Apple Store 的设计正从原来满满的科技感走向生活化，而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划\", \n        \"btnOrientation\": \"0\", \n        \"singleTitle\" : \"阅读全文\",\n        \"singleURL\" : \"https://www.dingtalk.com/\"\n    }, \n    \"msgtype\": \"actionCard\"\n})\n```\n\n独立跳转ActionCard类型\n\n```js\nbot.send({\n    \"msgtype\": \"actionCard\",\n    \"actionCard\": {\n        \"title\": \"我 20 年前想打造一间苹果咖啡厅，而它正是 Apple Store 的前身\", \n        \"text\": \"![screenshot](https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png) \\n\\n #### 乔布斯 20 年前想打造的苹果咖啡厅 \\n\\n Apple Store 的设计正从原来满满的科技感走向生活化，而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划\", \n        \"hideAvatar\": \"0\", \n        \"btnOrientation\": \"0\", \n        \"btns\": [\n            {\n                \"title\": \"内容不错\", \n                \"actionURL\": \"https://www.dingtalk.com/\"\n            }, \n            {\n                \"title\": \"不感兴趣\", \n                \"actionURL\": \"https://www.dingtalk.com/\"\n            }\n        ]\n    }\n})\n```\n\nFeedCard类型\n\n```js\nbot.send({\n    \"msgtype\": \"feedCard\",\n    \"feedCard\": {\n        \"links\": [\n            {\n                \"title\": \"时代的火车向前开1\", \n                \"messageURL\": \"https://www.dingtalk.com/\", \n                \"picURL\": \"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png\"\n            },\n            {\n                \"title\": \"时代的火车向前开2\", \n                \"messageURL\": \"https://www.dingtalk.com/\", \n                \"picURL\": \"https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png\"\n            }\n        ]\n    }\n})\n```\n\n## 常见问题\n\n当出现以下错误时，表示消息校验未通过，请查看机器人的安全设置。\n\n```json\n// 消息内容中不包含任何关键词\n{\n  \"errcode\":310000,\n  \"errmsg\":\"keywords not in content\"\n}\n\n// timestamp 无效\n{\n  \"errcode\":310000,\n  \"errmsg\":\"invalid timestamp\"\n}\n\n// 签名不匹配\n{\n  \"errcode\":310000,\n  \"errmsg\":\"sign not match\"\n}\n\n// IP地址不在白名单\n{\n  \"errcode\":310000,\n  \"errmsg\":\"ip X.X.X.X not in whitelist\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleitingting08%2Fding-bot-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleitingting08%2Fding-bot-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleitingting08%2Fding-bot-sdk/lists"}