Skip to main content

Ruby sends group message to DingTalk

Ruby sends group message to DingTalk

The purpose of sending a work message to DingTalk is as follows:

  • Ipa, apk, packaging is completed and can be used as a test group
  • The table export was successful, general group messages
  • For example, background log alarm
  • etc.

Proceed as follows

Group Settings-Smart Group Assistant-Add Robot-Select-Customize

Ruby sends group message to DingTalk

Ruby sends group message to DingTalk

You need to set a custom keyword in the robot settings. For example, I will name it summerxx.

Ruby sends group message to DingTalk

As mentioned in the previous article, I used a [ruby](/search?q=ruby) ​​program to automatically export a table. Then I sent a message to the DingTalk group to tell everyone that the table has been exported successfully. Please check the desktop.

First we define a DingDing class

    # 钉钉机器人
class DingDing
# 发送 markdown 消息
def DingDing.send_markdown(title, markdown)
# 这个就是申请机器人后给的 token
token = ''
params = %Q+{
'msgtype': 'markdown',
'markdown': {
'title': '#{title}',
'text': '#{markdown}'
}
}+

`curl --silent \
-H \"Content-Type: application/json\" \
-d \"#{params}\" \
https://oapi.dingtalk.com/robot/send?access_token=#{token}`
end
end


![Ruby sends group message to DingTalk](6b44e99974d17195ee2722671aabdc1f.png)

Curl is a commonly used command line data transmission tool that can easily create network requests from the command line. It supports many protocols, such as HTTP, HTTPS, FTP, FTPS, SFTP, IMAP, SMTP, POP3 and so on. Curl provides many powerful functions. We can use it to make HTTP requests, upload/download files, etc., and supports cookies, user password verification, proxy tunnels, speed limits, etc.
Here I use it to send an HTTPS request

If you call it where needed, a message will be sent.

    DingDing.send_markdown("excel导出完成", "请查看桌面summerxx")

Ruby sends group message to DingTalk

Some usages of Curl can be found here

[https://blog.csdn.net/zfw_666666/article/details/126161447](