feat: add to field to specify the receiver (close #48)

This commit is contained in:
JustSong
2023-04-16 09:55:23 +08:00
parent 69f503124a
commit 3d38260e5b
10 changed files with 55 additions and 3 deletions
+13
View File
@@ -11,6 +11,7 @@ import (
"message-pusher/model"
"net/http"
"net/url"
"strings"
"time"
)
@@ -23,6 +24,10 @@ type dingMessageRequest struct {
Title string `json:"title"`
Text string `json:"text"`
} `json:"markdown"`
At struct {
AtUserIds []string `json:"atUserIds"`
IsAtAll bool `json:"isAtAll"`
}
}
type dingMessageResponse struct {
@@ -31,6 +36,7 @@ type dingMessageResponse struct {
}
func SendDingMessage(message *model.Message, user *model.User) error {
// https://open.dingtalk.com/document/robots/custom-robot-access#title-72m-8ag-pqw
if user.DingWebhookURL == "" {
return errors.New("未配置钉钉群机器人消息推送方式")
}
@@ -45,6 +51,13 @@ func SendDingMessage(message *model.Message, user *model.User) error {
messageRequest.Markdown.Title = message.Title
messageRequest.Markdown.Text = message.Content
}
if message.To != "" {
if message.To == "@all" {
messageRequest.At.IsAtAll = true
} else {
messageRequest.At.AtUserIds = strings.Split(message.To, "|")
}
}
timestamp := time.Now().UnixMilli()
sign, err := dingSign(user.DingWebhookSecret, timestamp)