service/library/dingtalk/client.go

40 lines
951 B
Go

package dingtalk
import (
"service/library/configcenter"
"service/library/logger"
"github.com/CatchZeng/dingtalk/pkg/dingtalk"
)
var defaultDingTalkClient *dingtalk.Client
func InitDefaultDingTalkClient(cfg *configcenter.DingTalkRobotConfig) {
defaultDingTalkClient = NewDingTalkCilent(cfg)
}
func NewDingTalkCilent(cfg *configcenter.DingTalkRobotConfig) *dingtalk.Client {
client := dingtalk.NewClient(cfg.AccessToken, cfg.Secret)
return client
}
func SendMsg(message string) error {
msg := dingtalk.NewTextMessage().SetContent(message)
_, _, err := defaultDingTalkClient.Send(msg)
if err != nil {
logger.Error("SendMsgToAll fail, err: %v", err)
return err
}
return nil
}
func SendMsgToAll(message string) error {
msg := dingtalk.NewTextMessage().SetContent(message).SetAt(nil, true)
_, _, err := defaultDingTalkClient.Send(msg)
if err != nil {
logger.Error("SendMsgToAll fail, err: %v", err)
return err
}
return nil
}