Setup and access
1. Create a DingTalk Group
2. Open group settings, intelligent group assistant, add robots, and customize webhook access
3. Set the robot name, enable message push, and copy the Webhook address
4. Security settings, select custom keywords, and you can add up to ten
Send a message
Use post method to send a request to the address copied above
Message Agreement:/document/robots/message-types-and-data-format
/* -- @Time : 2022/6/8 11:24 -- @Author : raoxiaoya -- @Desc : */ package dingtalk import ( "encoding/json" "errors" "voteapi/pkg/curl" ) type Response struct { Errcode int Errmsg string } const KeywordMonitor = "Monitor" const MessageRobot = "/robot/send?access_token=xxxxxxxxxxxxxxxxxxxx" // Send simple text messagefunc SendDingTalkMessage(messageContent, messagePrefix string) (err error) { defer func() { if er := recover(); er != nil { err = ("SendDingTalkMessage panic") } }() headers := map[string]string{ "Content-Type": "application/json", } text := map[string]string{ "content": messagePrefix + ": " + messageContent, } postData := map[string]interface{}{ "msgtype": "text", "text": text, } body, _ := (postData) resp, err := (MessageRobot, "POST", headers, string(body)) if err != nil { return err } var re Response _ = ([]byte(resp), &re) if > 0 { return (resp) } return nil }
Call
(("service [%s] reboot success", ), )
This is the article about the sample code of Golang access DingTalk notification. For more information about Golang access DingTalk notifications, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!