send message use dingtalk group robot through js.
group robot hath 3 verifications type, key and token type is the most common one. the document is here: https://open.dingtalk.com/document/orgapp/customize-robot-security-settings
we can use it like this:
const DingtalkSecret = "secret";
const DingtalkToken = "token";
const dingtalkNotice = (receivers, noticeMessage) => {
const currentTimestamp = Date.now();
const msg = `${currentTimestamp}\n${DingtalkSecret}`;
const hmacCode = crypto
.createHmac("sha256", DingtalkSecret)
.update(msg)
.digest("base64");
const sign = hmacCode;
const url = `https://oapi.dingtalk.com/robot/send?access_token=${DingtalkToken}×tamp=${currentTimestamp}&sign=${sign}`;
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
at: {
atMobiles: receivers,
isAtAll: false,
},
msgtype: "text",
text: {
content: noticeMessage,
},
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
};