未验证 提交 fc4c4b96 编写于 作者: K kongfei605 提交者: GitHub

Merge pull request #1138 from ccfos/mm_notification

mm notification support at someone
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册