{"id":19660633,"url":"https://github.com/renyijiu/ding_hook","last_synced_at":"2026-06-13T00:31:20.124Z","repository":{"id":62557234,"uuid":"160046245","full_name":"renyijiu/ding_hook","owner":"renyijiu","description":"a gem build for use the dingding webhook convenient and happy","archived":false,"fork":false,"pushed_at":"2018-12-02T12:59:32.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-06-01T20:06:50.025Z","etag":null,"topics":["dingding","dingding-bot","gem","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/renyijiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-02T12:44:23.000Z","updated_at":"2018-12-05T14:44:24.000Z","dependencies_parsed_at":"2022-11-03T06:30:23.267Z","dependency_job_id":null,"html_url":"https://github.com/renyijiu/ding_hook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/renyijiu/ding_hook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fding_hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fding_hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fding_hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fding_hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renyijiu","download_url":"https://codeload.github.com/renyijiu/ding_hook/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renyijiu%2Fding_hook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34268187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","dingding-bot","gem","ruby"],"created_at":"2024-11-11T16:04:43.106Z","updated_at":"2026-06-13T00:31:20.093Z","avatar_url":"https://github.com/renyijiu.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DingHook\n\n钉钉群机器人中自定义机器人的webhook封装版本，更方便在项目中的使用。[钉钉文档地址](https://open-doc.dingtalk.com/docs/doc.htm?treeId=257\u0026articleId=105735\u0026docType=1)\n![robot.png](https://i.loli.net/2018/12/02/5c03c363974b1.png)\n## 安装\n\n如果需要在项目中使用，把下面代码增加到你的Gemfile中：\n\n```ruby\ngem 'ding_hook'\n```\n\n然后执行下列命令：\n\n    $ bundle\n\n或者是直接安装对应的gem包使用：\n\n    $ gem install ding_hook\n\n## 配置\n### 文件配置\n1. 在 Rails 项目中使用时，默认会读取`config`目录下的`dinghook.yml`文件\n2. 非 Rails 项目中，默认读取当前目录中`config`目录下的`dinghook.yml`文件；若不存在，则读取当前用户主目录下的`.ding_hook.yml`文件\n\n配置格式：\n```yaml\ndefault: access_token                # 默认机器人\ndev: dev_group_access_token          # example, 不同分组机器人\nalarm: alarm_group_access_token      # example, 不同分组机器人\n```\n\n### 代码配置\n当然也可以在代码中去配置对应的`access_token`, 当前配置会覆盖文件中的相同配置项\n\n```ruby\nDingHook.configure do |config|\n  config[:default] = 'access_token'\n  config[:dev] = 'dev_group_access_token'\n  config[:alarm] = 'alarm_group_access_token'\nend\n```\n\n可以通过下列命令查看已配置的信息：\n```ruby\n  DingHook.config\n```\n\n## 项目使用\n在项目中使用时，提供了下列的方法调用：\n\n### 文本类型消息\n\n```ruby\n# 必需的参数\ntext = '消息内容' # 文本信息\n\n# 可选参数\noptions = {\n  at_mobiles: [12345678901], # 数组，被@人的手机号码\n  is_at_all: false           # Boolean, 是否 @所有人\n}\n\naccounts = [:default, :dev]  # 数组，配置的key值，支持多机器人同时发送\n\n# 方法调用\nDingHook.send_text_msg(text, options = {}, accounts = [:default])\n```\n\n或者是\n\n```ruby\nparams = {\n  text: '消息内容',\n  at_mobiles: [],\n  is_at_all: true\n}\n\nDingHook.send_msg(params, :text, accounts)\n```\n\n### link类型消息\n\n```ruby\n# 必需参数\ntext = '消息内容。如果太长只会部分展示'\ntitle = '消息标题'\nmsg_url = '点击消息跳转的URL'\n\n# 可选参数\noptions = {\n  pic_url: '图片链接'\n} \n\nDingHook.send_link_msg(title, text, msg_url, options = {}, accounts = [:default]) \n```\n\n或者是\n\n```ruby\nparams = {\n  text: '消息内容。如果太长只会部分展示',\n  title: '消息标题',\n  message_url: '点击消息跳转的URL',\n  pic_url: '图片链接'\n}\n\nDingHook.send_msg(params, :link, accounts)\n```\n\n### markdown类型消息\n```ruby\n# 必需参数\ntitle = '首屏会话透出的展示内容'\ntext = 'markdown格式的消息'\n\n# 可选参数\noptions = {\n  at_mobiles: [],\n  is_at_all: false\n}\n\n# 调用方法\nDingHook.send_markdown_msg(title, text, options = {}, accounts = [:default])\n```\n或者是\n\n```ruby\nparams = {\n  text: 'markdown格式的消息',\n  title: '首屏会话透出的展示内容',\n  at_mobiles: [],\n  is_at_all: false\n}\n\nDingHook.send_msg(params, :markdown, accounts)\n```\n\n### 发送单个按钮的action_card\n````ruby\n# 必需参数\ntitle = '首屏会话透出的展示内容'\ntext = 'markdown格式的消息'\nsingle_title = '按钮提示'\nsingle_url = '点击按钮触发的URL'\n\n# 可选参数\noptions = {\n  btn_orientation: '按钮排列方式，0：垂直排列，1：横向排列',\n  hide_avator: '0-正常发消息者头像,1-隐藏发消息者头像'\n}\n\n# 方法调用\nDingHook.send_single_action_card(title, text, single_title, single_url, options = {}, accounts = [:default])\n````\n\n或者是\n```ruby\nparams = {\n  title: '首屏会话透出的展示内容',\n  text: 'markdown格式的消息',\n  single_title: '按钮提示',\n  single_url: '点击按钮触发的URL',\n  btn_orientation: '按钮排列方式，0：垂直排列，1：横向排列',\n  hide_avator: '0-正常发消息者头像,1-隐藏发消息者头像'\n}\n\nDingHook.send_msg(params, :action_card, accounts)\n```\n\n### 发送多个按钮的action_card\n\n```ruby\n# 必需参数\ntext = 'markdown格式的消息'\ntitle = '首屏会话透出的展示内容'\nbtns = [{\n  title: '按钮方案',\n  action_url: '点击按钮触发的URL'\n}]\n\n# 可选参数\noptions = {\n  btn_orientation: '按钮排列方式，0：垂直排列，1：横向排列',\n  hide_avator: '0-正常发消息者头像,1-隐藏发消息者头像'\n}\n\n# 方法调用\nDingHook.send_btns_action_card(title, text, btns, options = {}, accounts = [:default])\n```\n或者是\n```ruby\nparams = {\n  title: '首屏会话透出的展示内容',\n  text: 'markdown格式的消息',\n  btns: [{\n    title: '按钮方案',\n    action_url: '点击按钮触发的URL',\n  }],\n  btn_orientation: '按钮排列方式，0：垂直排列，1：横向排列',\n  hide_avator: '0-正常发消息者头像,1-隐藏发消息者头像'\n}\n\nDingHook.send_msg(params, :action_card, accounts)\n```\n\n### 发送feed_card消息\n```ruby\n# 必需参数\nlinks = [\n  {\n    title: '单条信息文本',\n    message_url: '点击单条信息到跳转链接',\n    pic_url: '单条信息后面图片的URL'\n  }\n]\n\n# 方法调用\nDingHook.send_feed_card(links, accounts = [:default])\n```\n\n或者是\n\n```ruby\nparams = {\n  links: [\n    {\n      title: '单条信息文本',\n      message_url: '点击单条信息到跳转链接',\n      pic_url: '单条信息后面图片的URL'\n    }\n  ]\n}\n\nDingHook.send_msg(params, accounts)\n```\n### 返回格式\n`[true, msg]`\n - true: Boolean 消息发送成功；多账号同时发送时，只有全部成功才会返回true\n - msg: String 错误消息提示\n\n## 命令行使用\n```shell\n$ bundle exec ding_hook -h\nUsage: ding_hook [options]\n\nSpecific options:\n    -t, --type TYPE                  the type of msg to send: text, link, markdown, action_card, feed_card\n    -a \u003cAccount1,Account2...\u003e,       the accounts that want to send msg\n        --accounts\n    -c \u003cAccount,Access_token\u003e,       the config of accounts\n        --config\n        --text TEXT                  the content of msg\n        --title TITLE                the title of msg\n        --mobiles \u003cPhone_no_1,Phone_no_2...\u003e\n                                     the array of mobiles that want to @\n        --[no-]all                   the option is want to @all\n        --msg-url                    the message url of msg\n        --pic-url                    the picture url of msg\n        --[no-]btn-vertical          Buttons are arranged vertically\n        --[no-]show-avator           show the avator of sender\n        --btns \u003cTitle,ActionURL\u003e     multi btns for action card\n        --single-title Single_title  the single btn title for action card\n        --single-url Single_url      the single btn url for action card\n        --links \u003cTitle,MessageURL,PicURL\u003e\n                                     the links for feed card\n\nCommon options:\n    -h, --help                       Show the help message\n    -v, --version                    Show version\n\n```\n\n⚠️：发送对应类型消息时，请参考上面文档，提供所必须的参数，否则消息会发送失败或出现异常错误\n\n例子：\n```shell\n$ bundle exec ding_hook -c default,access_token -t action_card -a default --text 我爱你 --title ❤ --btns homepage,https://renyijiu.com --btns blog,htts://blog.renyijiu.com --no-btn-vertical --show-avator\n\n```\n\n## 如何贡献\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n欢迎贡献相关代码或是反馈使用时遇到的问题👏，另外请记得为你的代码编写测试。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenyijiu%2Fding_hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenyijiu%2Fding_hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenyijiu%2Fding_hook/lists"}