mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 10:58:35 +08:00
规则链
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package nodes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/XM-GO/PandaKit/httpclient"
|
||||
"github.com/sirupsen/logrus"
|
||||
"pandax/pkg/rule_engine/message"
|
||||
)
|
||||
@@ -11,7 +13,7 @@ type externalWechatNode struct {
|
||||
MsgType string `json:"msgType" yaml:"msgType"`
|
||||
Content string `json:"content" yaml:"content"`
|
||||
IsAtAll bool `json:"isAtAll" yaml:"isAtAll"`
|
||||
atMobiles []string `json:"atMobiles" yaml:"atMobiles"`
|
||||
AtMobiles []string `json:"atMobiles" yaml:"atMobiles"`
|
||||
}
|
||||
|
||||
type externalWechatNodeFactory struct{}
|
||||
@@ -29,5 +31,29 @@ func (f externalWechatNodeFactory) Create(id string, meta Metadata) (Node, error
|
||||
func (n *externalWechatNode) Handle(msg message.Message) error {
|
||||
logrus.Infof("%s handle message '%s'", n.Name(), msg.GetType())
|
||||
|
||||
successLabelNode := n.GetLinkedNode("Success")
|
||||
failureLabelNode := n.GetLinkedNode("Failure")
|
||||
template, err := ParseTemplate(n.Content, msg.GetAllMap())
|
||||
sendData := map[string]interface{}{
|
||||
"msgtype": "text",
|
||||
"text": map[string]interface{}{"content": template},
|
||||
}
|
||||
if n.IsAtAll {
|
||||
sendData["text"].(map[string]interface{})["mentioned_mobile_list"] = []string{"@all"}
|
||||
} else {
|
||||
sendData["text"].(map[string]interface{})["mentioned_mobile_list"] = n.AtMobiles
|
||||
}
|
||||
marshal, _ := json.Marshal(sendData)
|
||||
postJson := httpclient.NewRequest(n.WebHook).Header("Content-Type", "application/json").PostJson(string(marshal))
|
||||
if postJson.StatusCode != 200 {
|
||||
if failureLabelNode != nil {
|
||||
return failureLabelNode.Handle(msg)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if successLabelNode != nil {
|
||||
return successLabelNode.Handle(msg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user