service/library/dingtalk/client.go

40 lines
951 B
Go
Raw Normal View History

2024-02-29 09:55:56 +08:00
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
}
2024-03-02 08:29:20 +08:00
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
}
2024-02-29 09:55:56 +08:00
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
}