From c743bc6abb129dd66010409cdae2f83f90470f49 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Fri, 13 Dec 2019 16:23:04 +0800 Subject: [PATCH] support for send message to multiple dingtalk robot --- main.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 0ea8cf2..58e7d20 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,7 @@ package main import ( "context" "fmt" - dt "github.com/JetBlink/dingtalk-notify-go-sdk" + dtn "github.com/JetBlink/dingtalk-notify-go-sdk" "github.com/ehlxr/ddgo/pkg" "io" "net/http" @@ -15,7 +15,7 @@ import ( ) var ( - dingTalk *dt.Robot + dingTalk *dtn.Robot limiter *pkg.LimiterServer ) @@ -26,7 +26,7 @@ func init() { func main() { pkg.ParseArg() - dingTalk = dt.NewRobot(pkg.Opts.Robot.Token, pkg.Opts.Robot.Secret) + dingTalk = dtn.NewRobot(pkg.Opts.Robot.Token, pkg.Opts.Robot.Secret) limiter = pkg.NewLimiterServer(1*time.Minute, 20) start() @@ -108,8 +108,15 @@ func requestHandle(w http.ResponseWriter, r *http.Request) { content = fmt.Sprintf("%s\n%s", app, content) } + dtRobot := dingTalk + dt := r.Form.Get("dt") + ds := r.Form.Get("ds") + if ds != "" && dt != "" { + dtRobot = dtn.NewRobot(dt, ds) + } + if limiter.IsAvailable() { - err = dingTalk.SendTextMessage(content, ats, pkg.Opts.Robot.IsAtAll) + err = dtRobot.SendTextMessage(content, ats, pkg.Opts.Robot.IsAtAll) if err != nil { log.Error("%+v", err) _, _ = fmt.Fprintln(w, err)