diff --git a/src/server/common/sender/mm.go b/src/server/common/sender/mm.go index 1435a1fb..cd3ff4d5 100644 --- a/src/server/common/sender/mm.go +++ b/src/server/common/sender/mm.go @@ -2,6 +2,7 @@ package sender import ( "net/url" + "strings" "time" "github.com/didi/nightingale/v5/src/pkg/poster" @@ -19,6 +20,14 @@ type mm struct { Text string `json:"text"` } +func MapStrToStr(arr []string, fn func(s string) string) []string { + var newArray = []string{} + for _, it := range arr { + newArray = append(newArray, fn(it)) + } + return newArray +} + func SendMM(message MatterMostMessage) { for i := 0; i < len(message.Tokens); i++ { @@ -33,6 +42,13 @@ func SendMM(message MatterMostMessage) { } channels := v["channel"] // do not get + txt := "" + atuser := v["atuser"] + if len(atuser) != 0 { + txt = strings.Join(MapStrToStr(atuser, func(u string) string { + return "@" + u + }), ",") + "\n" + } username := v.Get("username") if err != nil { logger.Errorf("mm_sender: failed to parse error=%v", err) @@ -43,7 +59,7 @@ func SendMM(message MatterMostMessage) { body := mm{ Channel: channel, Username: username, - Text: message.Text, + Text: txt + message.Text, } res, code, err := poster.PostJSON(ur, time.Second*5, body, 3)