support for send message to multiple dingtalk robot
This commit is contained in:
parent
3c02d66b42
commit
c743bc6abb
15
main.go
15
main.go
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
dt "github.com/JetBlink/dingtalk-notify-go-sdk"
|
dtn "github.com/JetBlink/dingtalk-notify-go-sdk"
|
||||||
"github.com/ehlxr/ddgo/pkg"
|
"github.com/ehlxr/ddgo/pkg"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dingTalk *dt.Robot
|
dingTalk *dtn.Robot
|
||||||
limiter *pkg.LimiterServer
|
limiter *pkg.LimiterServer
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ func init() {
|
|||||||
func main() {
|
func main() {
|
||||||
pkg.ParseArg()
|
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)
|
limiter = pkg.NewLimiterServer(1*time.Minute, 20)
|
||||||
|
|
||||||
start()
|
start()
|
||||||
@ -108,8 +108,15 @@ func requestHandle(w http.ResponseWriter, r *http.Request) {
|
|||||||
content = fmt.Sprintf("%s\n%s", app, content)
|
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() {
|
if limiter.IsAvailable() {
|
||||||
err = dingTalk.SendTextMessage(content, ats, pkg.Opts.Robot.IsAtAll)
|
err = dtRobot.SendTextMessage(content, ats, pkg.Opts.Robot.IsAtAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("%+v", err)
|
log.Error("%+v", err)
|
||||||
_, _ = fmt.Fprintln(w, err)
|
_, _ = fmt.Fprintln(w, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user