Files
ai-agent/internal/wxwork/wxwork.go
T

46 lines
915 B
Go
Raw Normal View History

2026-04-09 10:01:23 +08:00
package wxwork
import (
"code.tczkiot.com/wlw/ai-agent/internal/pkg/config"
2026-04-09 10:01:23 +08:00
"strings"
"github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/work"
wxconfig "github.com/silenceper/wechat/v2/work/config"
)
var (
w *work.Work
wxCfg config.WxWorkConfig
)
func Init() {
w = nil
wxCfg = config.WxWorkConfig{}
cfg := config.Current()
if !cfg.WxWork.Enabled {
return
}
wxCfg = cfg.WxWork
if strings.TrimSpace(wxCfg.CorpID) == "" || strings.TrimSpace(wxCfg.CorpSecret) == "" {
return
}
w = work.NewWork(&wxconfig.Config{
CorpID: wxCfg.CorpID,
CorpSecret: wxCfg.CorpSecret,
AgentID: wxCfg.AgentID,
RasPrivateKey: wxCfg.RSAPrivateKey,
Token: wxCfg.Token,
EncodingAESKey: wxCfg.EncodingAESKey,
Cache: cache.NewMemory(),
})
}
func Enabled() bool {
return w != nil && wxCfg.Enabled
}
func GetWorkCli() *work.Work {
return w
}