{"id":19703710,"url":"https://github.com/cocowwy/dingtalk-robot","last_synced_at":"2025-04-29T14:30:57.508Z","repository":{"id":44762303,"uuid":"438829667","full_name":"Cocowwy/dingtalk-robot","owner":"Cocowwy","description":":robot:拆箱即用的钉钉机器人，已解决20次/秒的消息上限问题，支持复杂业务场景下，根据业务标识使用指定的机器人进行消息通知","archived":false,"fork":false,"pushed_at":"2023-01-05T03:50:33.000Z","size":146,"stargazers_count":27,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T17:51:09.914Z","etag":null,"topics":["java","springboot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cocowwy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-16T01:59:34.000Z","updated_at":"2024-06-06T05:10:47.000Z","dependencies_parsed_at":"2023-02-03T09:31:59.138Z","dependency_job_id":null,"html_url":"https://github.com/Cocowwy/dingtalk-robot","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cocowwy%2Fdingtalk-robot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cocowwy%2Fdingtalk-robot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cocowwy%2Fdingtalk-robot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cocowwy%2Fdingtalk-robot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cocowwy","download_url":"https://codeload.github.com/Cocowwy/dingtalk-robot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251518900,"owners_count":21602232,"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":["java","springboot"],"created_at":"2024-11-11T21:18:46.805Z","updated_at":"2025-04-29T14:30:56.624Z","avatar_url":"https://github.com/Cocowwy.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :robot:cocowwy-dingtalk-robot\n\u003ca href=\"https://github.com/Cocowwy/dingtalk-robot\"\u003e\u003cimg src=\"https://badgen.net/badge/⭐/GitHub/blue\" alt=\"github\"\u003e\u003c/a\u003e\n![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)   \n![image](https://user-images.githubusercontent.com/63331147/153790868-79936b70-7008-484b-a749-dac3f304d257.png)\n## 说明  \n拆箱即用，以便更灵活的将钉钉机器人快速的嵌入到业务里，用来应付在复杂场景里对不同业务类型的机器人来按需调用，同时会提供一些应付更复杂的业务场景的功能  \n- **群机器人**\n  - 对钉钉群引入的机器人进行管理，可根据业务统一调度不同群的机器人发送消息\n  - 在上述功能的基础上，实现根据手机号@指定人员\n  - 在上述功能的情况下，实现消息延时发送，消息定时发送（coding...）\n  - **由于群机器人有1分钟20条消息的上限，实现机器人对短时间内（10s）的并发消息按顺序拼接成长消息体，解决上限问题**\n- **单聊机器人**\n  - 对多个单聊机器人进行统一的管理，可细粒度的控制不同机器人根据手机号发送消息\n  - 对token进行自定义缓存时间，调用方可以无需考虑钉钉开放平台对token获取接口的限流，api会自动对token进行自定义时长的缓存\n  - 实现一个消息能被同一个分组内的机器人随机消费，按权重消费（coding...）\n  - 发送带有link链接的单聊机器人\n  - 白名单控制发送，以及禁用发送功能\n\n## pom.xml：\n```\n \u003cdependency\u003e\n     \u003cgroupId\u003ecn.cocowwy\u003c/groupId\u003e\n     \u003cartifactId\u003ecocowwy-dingtalk-robot\u003c/artifactId\u003e\n     \u003cversion\u003e1.0.7\u003c/version\u003e\n \u003c/dependency\u003e\n```\n\n## yml：\n```yml\ndingding:\n  robots:\n    hooks:\n      - label: robotA\n        signature: robotA的signature\n        webhook: robotA的webhook\n      - label: robotB\n        signature: robotB的signature\n        webhook: robotB的webhook\n    robot:\n      - label: robot1\n        agentId: robot1的agentId\n        appKey: robot1的appKey\n        appSecret: robot1的appSecret\n        whitelist: 1234,3456\n        ban: true\n        tokenRefresh: robot1 的 Token的缓存时长，默认110min\n      - label: robot2\n        agentId: robot2的agentId\n        appKey: robot2的appKey\n        appSecret: robot2的appSecret\n        whitelist: 1234,3456\n        ban: false\n```\n\n### 🍓参数说明：\nhooks： 是webhook机器人数组，你可以塞一堆机器人来控制对每个机器人在不同群发的消息\nrobot 是钉钉机器人数组,你也可以设置一堆机器人来私聊（骚扰）不同的人\nlabel： 在使用api进行发送时，指定使用的哪一个机器人或者webhook的配置   \nwhitelist： 白名单，当白名单指定之后（用户的钉钉userid），发送对象会和白名单取并集进行发送，如果不指定白名单，则无视白名单功能       \nban：是否使用禁止发送功能，默认是false，开启后，将不会进行消息的发送   \n\n### 如何使用？\n注入即可使用相应的API，您只需在调用处传入你所需要使用的机器人的**label**即可实现调用\n- **hooks** 群机器人需要注入**DingTalkGroupApi**来进行使用\n- **robot** 单聊机器人需要注入**DingTalkRobotApi**来进行使用\n\n### 使用Demo\n```java\n/**\n * @author cocowwy.cn\n * @create 2021-12-12-10:41\n */\n@Component\npublic class Runner implements ApplicationRunner {\n    @Autowired\n    private DingTalkRobotApi dingTalkRobotApi;\n    @Autowired\n    private DingTalkGroupApi dingTalkGroupApi;\n    \n    @Override\n    public void run(ApplicationArguments args) throws Exception {\n            // 发送群消息\n            dingTalkGroupApi.sendText(\"robot1\",\"xxxxx\" );\n            \n            // 发送群消息，并且@某人\n            dingTalkGroupApi.sendTextAndAt(\"robot1\", \"xxxxx\",\"Arrays.asList(\"需要@的手机号，不需要则传空数组\")\");\n            \n                       \n            // 多消息自动拼接（群消息） \n            dingTalkGroupApi.sendFrequentlyMessage(\"robot1\", \"xxxxx\", Arrays.asList(\"需要@的手机号，不需要则传空数组\"));\n    \n            // 发送机器人私聊消息\n            dingTalkRobotApi.sendMessageByPhonesAt(\"robotA\", Arrays.asList(\"需要@的手机号，不需要则传空数组\"), \"xxxxx\", \"标题\");\n        }\n    }\n}\n```\n- DingTalkGroupApi\n   - getHooks 获取所有在线的群机器人label\n   - sendText 向指定label的群机器人发送消息\n   - sendTextByPhones 向指定label的群机器人发送消息，并且根据手机号@\n   - sendTextAndAtAll 向指定群机器人发送消息，并且@所有人\n   - sendFrequentlyMessage 解决群机器人1分钟的20条消息限制，该接口会在短时间内的消息自动拼接成长消息，默认缓存拼接时间为10s\n- DingTalkRobotApi\n   - getRobots 获取单聊机器人列表\n   - sendMessageByPhonesAt 根据手机号向指定人发送消息\n   - sendMessageByUserIdsAt 根据用户id给指定人发送消息\n   - getToken 查询指定机器人的token\n   - sendLinkMessageByPhones 发送link消息\n\n### hooks配置方式\n**点击群机器人** ---\u003e **机器人设置** ---\u003e **往下翻** ---\u003e **复制webhook** ---\u003e **安全设置点击加签,将密钥复制即可**\n\n![image](https://user-images.githubusercontent.com/63331147/146709451-9e76d821-5012-4853-b433-760a9a26cc58.png)\n\n### robot配置方式\n**钉钉开放平台** ---\u003e **点击开发者后台** ---\u003e **应用开发** ---\u003e **企业内部开发** ---\u003e **点击机器人,复制需要的参数即可** \n\n![image](https://user-images.githubusercontent.com/63331147/146709663-a2db71f5-226d-4332-90b0-ffb67f14f53e.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocowwy%2Fdingtalk-robot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcocowwy%2Fdingtalk-robot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocowwy%2Fdingtalk-robot/lists"}