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
+6 -1
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"message-pusher/model"
"net/http"
"strings"
)
type corpMessageRequest struct {
@@ -17,6 +18,7 @@ type corpMessageRequest struct {
Markdown struct {
Content string `json:"content"`
} `json:"markdown"`
MentionedList []string `json:"mentioned_list"`
}
type corpMessageResponse struct {
@@ -25,6 +27,7 @@ type corpMessageResponse struct {
}
func SendCorpMessage(message *model.Message, user *model.User) error {
// https://developer.work.weixin.qq.com/document/path/91770
if user.CorpWebhookURL == "" {
return errors.New("未配置企业微信群机器人消息推送方式")
}
@@ -38,7 +41,9 @@ func SendCorpMessage(message *model.Message, user *model.User) error {
messageRequest.MessageType = "markdown"
messageRequest.Markdown.Content = message.Content
}
if message.To != "" {
messageRequest.MentionedList = strings.Split(message.To, "|")
}
jsonData, err := json.Marshal(messageRequest)
if err != nil {
return err