Merge pull request #1138 from ccfos/mm_notification
mm notification support at someone
This commit is contained in:
commit
fc4c4b96bf
|
@ -2,6 +2,7 @@ package sender
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/didi/nightingale/v5/src/pkg/poster"
|
"github.com/didi/nightingale/v5/src/pkg/poster"
|
||||||
|
@ -19,6 +20,14 @@ type mm struct {
|
||||||
Text string `json:"text"`
|
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) {
|
func SendMM(message MatterMostMessage) {
|
||||||
|
|
||||||
for i := 0; i < len(message.Tokens); i++ {
|
for i := 0; i < len(message.Tokens); i++ {
|
||||||
|
@ -33,6 +42,13 @@ func SendMM(message MatterMostMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
channels := v["channel"] // do not get
|
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")
|
username := v.Get("username")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("mm_sender: failed to parse error=%v", err)
|
logger.Errorf("mm_sender: failed to parse error=%v", err)
|
||||||
|
@ -43,7 +59,7 @@ func SendMM(message MatterMostMessage) {
|
||||||
body := mm{
|
body := mm{
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
Username: username,
|
Username: username,
|
||||||
Text: message.Text,
|
Text: txt + message.Text,
|
||||||
}
|
}
|
||||||
|
|
||||||
res, code, err := poster.PostJSON(ur, time.Second*5, body, 3)
|
res, code, err := poster.PostJSON(ur, time.Second*5, body, 3)
|
||||||
|
|
Loading…
Reference in New Issue