add mm notification with notify plugin

This commit is contained in:
kongfei 2022-08-31 15:31:27 +08:00
parent 5e931ebe8e
commit 26a3d2dafa
2 changed files with 23 additions and 1 deletions

View File

@ -17,7 +17,6 @@ type mm struct {
Channel string `json:"channel"`
Username string `json:"username"`
Text string `json:"text"`
Props string `json:"props"`
}
func SendMM(message MatterMostMessage) {

View File

@ -125,6 +125,7 @@ func handleNotice(notice Notice, bs []byte) {
wecomset := make(map[string]struct{})
dingtalkset := make(map[string]struct{})
feishuset := make(map[string]struct{})
mmset := make(map[string]struct{})
for _, user := range notice.Event.NotifyUsersObj {
if user.Email != "" {
@ -155,6 +156,11 @@ func handleNotice(notice Notice, bs []byte) {
if ret.Exists() {
feishuset[ret.String()] = struct{}{}
}
ret = gjson.GetBytes(bs, "mm_webhook_url")
if ret.Exists() {
mmset[ret.String()] = struct{}{}
}
}
phones := StringSetKeys(phoneset)
@ -236,6 +242,23 @@ func handleNotice(notice Notice, bs []byte) {
AtMobiles: phones,
Tokens: StringSetKeys(feishuset),
})
case "mm":
if len(mmset) == 0 {
continue
}
if !slice.ContainsString(config.C.Alerting.NotifyBuiltinChannels, "mm") {
continue
}
content, has := notice.Tpls["mm.tpl"]
if !has {
content = "mm.tpl not found"
}
sender.SendMM(sender.MatterMostMessage{
Text: content,
Tokens: StringSetKeys(mmset),
})
}
}
}