mm notification support at someone

This commit is contained in:
kongfei 2022-08-31 23:03:29 +08:00
parent 1e9bd900e9
commit 5c60c2c85e
1 changed files with 17 additions and 1 deletions

View File

@ -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)