diff --git a/config/config_test.yaml b/config/config_test.yaml index baedada..4ebccb8 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -88,7 +88,7 @@ permissionConfig: permission_url: "http://api.test.user.1688sup.cn:8001/v1/menu/myCodes?systemId=" -ding_talk_bots: - public: - client_id: "dingchg59zwwvmuuvldx", - client_secret: "ZwetAnRiTQobNFVlNrshRagSMAJIFpBAepWkWI7on7Tt_o617KHtTjBLp8fQfplz", \ No newline at end of file +#ding_talk_bots: +# public: +# client_id: "dingchg59zwwvmuuvldx", +# client_secret: "ZwetAnRiTQobNFVlNrshRagSMAJIFpBAepWkWI7on7Tt_o617KHtTjBLp8fQfplz", \ No newline at end of file diff --git a/internal/biz/ding_talk_bot.go b/internal/biz/ding_talk_bot.go index 09de5d4..f2abea1 100644 --- a/internal/biz/ding_talk_bot.go +++ b/internal/biz/ding_talk_bot.go @@ -2,29 +2,61 @@ package biz import ( "ai_scheduler/internal/biz/do" + "ai_scheduler/internal/data/constants" + "ai_scheduler/internal/data/impl" + "ai_scheduler/internal/data/model" "ai_scheduler/internal/entitys" + "ai_scheduler/internal/pkg/mapstructure" "context" + "fmt" + "github.com/gofiber/fiber/v2/log" "github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot" + "xorm.io/builder" ) // AiRouterBiz 智能路由服务 type DingTalkBotBiz struct { - do *do.Do - handle *do.Handle + do *do.Do + handle *do.Handle + botConfigImpl *impl.BotConfigImpl + replier *chatbot.ChatbotReplier + log log.Logger } // NewDingTalkBotBiz func NewDingTalkBotBiz( do *do.Do, handle *do.Handle, + botConfigImpl *impl.BotConfigImpl, ) *DingTalkBotBiz { return &DingTalkBotBiz{ - do: do, - handle: handle, + do: do, + handle: handle, + botConfigImpl: botConfigImpl, + replier: chatbot.NewChatbotReplier(), } } +func (d *DingTalkBotBiz) GetDingTalkBotCfgList() (dingBotList []entitys.DingTalkBot, err error) { + botConfig := make([]model.AiBotConfig, 0) + + cond := builder.NewCond() + cond = cond.And(builder.Eq{"status": constants.Enable}) + cond = cond.And(builder.Eq{"bot_type": constants.BotTypeDingTalk}) + err = d.botConfigImpl.GetRangeToMapStruct(&cond, &botConfig) + for _, v := range botConfig { + var config entitys.DingTalkBot + err = mapstructure.Decode(v, &config) + if err != nil { + d.log.Info("初始化“%s”失败:%s", v.BotName, err.Error()) + } + dingBotList = append(dingBotList, config) + } + return + +} + func (d *DingTalkBotBiz) InitRequire(ctx context.Context, data *chatbot.BotCallbackDataModel) (requireData *entitys.RequireDataDingTalkBot, err error) { requireData = &entitys.RequireDataDingTalkBot{ Req: data, @@ -37,6 +69,74 @@ func (d *DingTalkBotBiz) InitRequire(ctx context.Context, data *chatbot.BotCallb return } -func (d *DingTalkBotBiz) Recognize(ctx context.Context, rec *entitys.Recognize, ch chan entitys.Response) (match *entitys.Match, err error) { - return d.handle.RecognizeBot(ctx, rec, ch) +func (d *DingTalkBotBiz) Recognize(ctx context.Context, bot *chatbot.BotCallbackDataModel) (match entitys.Match, err error) { + + return d.handle.Recognize(ctx, nil, &do.WithDingTalkBot{}) +} + +func (d *DingTalkBotBiz) HandleRes(ctx context.Context, data *chatbot.BotCallbackDataModel, resp entitys.Response) error { + switch resp.Type { + case entitys.ResponseText: + return d.replyText(ctx, data.SessionWebhook, resp.Content) + case entitys.ResponseStream: + return d.replySteam(ctx, data.SessionWebhook, resp.Content) + case entitys.ResponseImg: + return d.replyImg(ctx, data.SessionWebhook, resp.Content) + case entitys.ResponseFile: + return d.replyFile(ctx, data.SessionWebhook, resp.Content) + case entitys.ResponseMarkdown: + return d.replyMarkdown(ctx, data.SessionWebhook, resp.Content) + case entitys.ResponseActionCard: + return d.replyActionCard(ctx, data.SessionWebhook, resp.Content) + default: + return nil + } +} + +func (d *DingTalkBotBiz) replySteam(ctx context.Context, SessionWebhook string, content string, arg ...string) error { + msg := content + if len(arg) > 0 { + msg = fmt.Sprintf(content, arg) + } + return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) +} + +func (d *DingTalkBotBiz) replyText(ctx context.Context, SessionWebhook string, content string, arg ...string) error { + msg := content + if len(arg) > 0 { + msg = fmt.Sprintf(content, arg) + } + return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) +} + +func (d *DingTalkBotBiz) replyImg(ctx context.Context, SessionWebhook string, content string, arg ...string) error { + msg := content + if len(arg) > 0 { + msg = fmt.Sprintf(content, arg) + } + return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) +} + +func (d *DingTalkBotBiz) replyFile(ctx context.Context, SessionWebhook string, content string, arg ...string) error { + msg := content + if len(arg) > 0 { + msg = fmt.Sprintf(content, arg) + } + return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) +} + +func (d *DingTalkBotBiz) replyMarkdown(ctx context.Context, SessionWebhook string, content string, arg ...string) error { + msg := content + if len(arg) > 0 { + msg = fmt.Sprintf(content, arg) + } + return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) +} + +func (d *DingTalkBotBiz) replyActionCard(ctx context.Context, SessionWebhook string, content string, arg ...string) error { + msg := content + if len(arg) > 0 { + msg = fmt.Sprintf(content, arg) + } + return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) } diff --git a/internal/biz/do/prompt.go b/internal/biz/do/prompt.go index cb1ca18..f25cf95 100644 --- a/internal/biz/do/prompt.go +++ b/internal/biz/do/prompt.go @@ -1,6 +1,7 @@ package do import ( + "ai_scheduler/internal/biz/handle" "ai_scheduler/internal/entitys" "ai_scheduler/internal/pkg" "context" @@ -42,7 +43,7 @@ func (f *WithSys) CreatePrompt(ctx context.Context, rec *entitys.Recognize) (mes func (f *WithSys) getUserContent(ctx context.Context, rec *entitys.Recognize) (content strings.Builder, err error) { var hasFile bool - if len(rec.UserContent.FileUrl) > 0 || rec.UserContent.File != nil { + if rec.UserContent.File != nil && (len(rec.UserContent.File.FileUrl) > 0 || rec.UserContent.File.File != nil) { hasFile = true } content.WriteString(rec.UserContent.Text) @@ -64,7 +65,65 @@ func (f *WithSys) getUserContent(ctx context.Context, rec *entitys.Recognize) (c if hasFile { content.WriteString("\n") content.WriteString("### 文件内容:\n") - hand.WriteString(rec.UserContent.FileUrl, rec.UserContent.FileUrl) + handle.HandleRecognizeFile(rec.UserContent.File) + //...do something with file + } + return +} + +type WithDingTalkBot struct { +} + +func (f *WithDingTalkBot) CreatePrompt(ctx context.Context, rec *entitys.Recognize) (mes []api.Message, err error) { + var ( + prompt = make([]api.Message, 0) // 初始化一个空的api.Message切片 + ) + // 获取用户内容,如果出错则直接返回错误 + content, err := f.getUserContent(ctx, rec) + if err != nil { + return nil, err + } + // 构建提示消息列表,包含系统提示、助手回复和用户内容 + mes = append(prompt, api.Message{ + Role: "system", // 系统角色 + Content: rec.SystemPrompt, // 系统提示内容 + }, api.Message{ + Role: "assistant", // 助手角色 + Content: "### 聊天记录:" + pkg.JsonStringIgonErr(rec.ChatHis), // 助手回复内容 + }, api.Message{ + Role: "user", // 用户角色 + Content: content.String(), // 用户输入内容 + }) + + return +} + +func (f *WithDingTalkBot) getUserContent(ctx context.Context, rec *entitys.Recognize) (content strings.Builder, err error) { + var hasFile bool + if rec.UserContent.File != nil && (len(rec.UserContent.File.FileUrl) > 0 || rec.UserContent.File.File != nil) { + hasFile = true + } + content.WriteString(rec.UserContent.Text) + if hasFile { + content.WriteString("\n") + } + + if len(rec.UserContent.Tag) > 0 { + content.WriteString("\n") + content.WriteString("### 工具必须使用:") + content.WriteString(rec.UserContent.Tag) + } + + if len(rec.ChatHis.Messages) > 0 { + content.WriteString("### 引用历史聊天记录:\n") + content.WriteString(pkg.JsonStringIgonErr(rec.ChatHis)) + } + + if hasFile { + content.WriteString("\n") + content.WriteString("### 文件内容:\n") + handle.HandleRecognizeFile(rec.UserContent.File) + //...do something with file } return } diff --git a/internal/config/config.go b/internal/config/config.go index 85b8be8..160275f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -9,22 +9,17 @@ import ( // Config 应用配置 type Config struct { - Server ServerConfig `mapstructure:"server"` - Ollama OllamaConfig `mapstructure:"ollama"` - Vllm VllmConfig `mapstructure:"vllm"` - Sys SysConfig `mapstructure:"sys"` - Tools ToolsConfig `mapstructure:"tools"` - Logging LoggingConfig `mapstructure:"logging"` - Redis Redis `mapstructure:"redis"` - DB DB `mapstructure:"db"` - DefaultPrompt SysPrompt `mapstructure:"default_prompt"` - PermissionConfig PermissionConfig `mapstructure:"permissionConfig"` - DingTalkBots map[string]*DingTalkBot `mapstructure:"ding_talk_bots"` -} - -type DingTalkBot struct { - ClientId string `mapstructure:"client_id"` - ClientSecret string `mapstructure:"client_secret"` + Server ServerConfig `mapstructure:"server"` + Ollama OllamaConfig `mapstructure:"ollama"` + Vllm VllmConfig `mapstructure:"vllm"` + Sys SysConfig `mapstructure:"sys"` + Tools ToolsConfig `mapstructure:"tools"` + Logging LoggingConfig `mapstructure:"logging"` + Redis Redis `mapstructure:"redis"` + DB DB `mapstructure:"db"` + DefaultPrompt SysPrompt `mapstructure:"default_prompt"` + PermissionConfig PermissionConfig `mapstructure:"permissionConfig"` + // DingTalkBots map[string]*DingTalkBot `mapstructure:"ding_talk_bots"` } type SysPrompt struct { @@ -57,18 +52,18 @@ type ServerConfig struct { // OllamaConfig Ollama配置 type OllamaConfig struct { - BaseURL string `mapstructure:"base_url"` - Model string `mapstructure:"model"` - GenerateModel string `mapstructure:"generate_model"` - VlModel string `mapstructure:"vl_model"` - Timeout time.Duration `mapstructure:"timeout"` + BaseURL string `mapstructure:"base_url"` + Model string `mapstructure:"model"` + GenerateModel string `mapstructure:"generate_model"` + VlModel string `mapstructure:"vl_model"` + Timeout time.Duration `mapstructure:"timeout"` } type VllmConfig struct { - BaseURL string `mapstructure:"base_url"` - VlModel string `mapstructure:"vl_model"` - Timeout time.Duration `mapstructure:"timeout"` - Level string `mapstructure:"level"` + BaseURL string `mapstructure:"base_url"` + VlModel string `mapstructure:"vl_model"` + Timeout time.Duration `mapstructure:"timeout"` + Level string `mapstructure:"level"` } type Redis struct { diff --git a/internal/data/constants/bot.go b/internal/data/constants/bot.go index bfe004c..2b24cfe 100644 --- a/internal/data/constants/bot.go +++ b/internal/data/constants/bot.go @@ -25,3 +25,9 @@ var ChatStyleMap = map[ChatStyle]string{ ChatStyleCute: "可爱", ChatStyleAngry: "愤怒", } + +type BotType int + +const ( + BotTypeDingTalk BotType = 1 // 系统的bug/优化建议 +) diff --git a/internal/data/impl/base.go b/internal/data/impl/base.go index 7aee0b7..b7abf1a 100644 --- a/internal/data/impl/base.go +++ b/internal/data/impl/base.go @@ -22,7 +22,7 @@ BaseModel 是一个泛型结构体,用于封装GORM数据库通用操作。 // 定义受支持的PO类型集合(可根据需要扩展), 只有包含表结构才能使用BaseModel,避免使用出现问题 type PO interface { model.AiChatHi | - model.AiSy | model.AiSession | model.AiTask | model.AiBot + model.AiSy | model.AiSession | model.AiTask | model.AiBotConfig } type BaseModel[P PO] struct { diff --git a/internal/data/impl/bot_chat_history.go b/internal/data/impl/bot_chat_history.go index 3da5184..7e4de3c 100644 --- a/internal/data/impl/bot_chat_history.go +++ b/internal/data/impl/bot_chat_history.go @@ -10,6 +10,6 @@ type BotChatHisImpl struct { dataTemp.DataTemp } -func NewBotChatHisImpl(db *utils.Db) *TaskImpl { - return &TaskImpl{*dataTemp.NewDataTemp(db, new(model.AiBotChatHi))} +func NewBotChatHisImpl(db *utils.Db) *BotChatHisImpl { + return &BotChatHisImpl{*dataTemp.NewDataTemp(db, new(model.AiBotChatHi))} } diff --git a/internal/data/impl/bot_config.go b/internal/data/impl/bot_config.go new file mode 100644 index 0000000..2c98ffb --- /dev/null +++ b/internal/data/impl/bot_config.go @@ -0,0 +1,17 @@ +package impl + +import ( + "ai_scheduler/internal/data/model" + "ai_scheduler/tmpl/dataTemp" + "ai_scheduler/utils" +) + +type BotConfigImpl struct { + dataTemp.DataTemp +} + +func NewBotConfigImpl(db *utils.Db) *BotConfigImpl { + return &BotConfigImpl{ + DataTemp: *dataTemp.NewDataTemp(db, new(model.AiBotConfig)), + } +} diff --git a/internal/data/impl/bot_impl.go b/internal/data/impl/bot_impl.go deleted file mode 100644 index e76e8de..0000000 --- a/internal/data/impl/bot_impl.go +++ /dev/null @@ -1,28 +0,0 @@ -package impl - -import ( - "ai_scheduler/internal/data/model" - "ai_scheduler/tmpl/dataTemp" - "ai_scheduler/utils" - - "gorm.io/gorm" -) - -type BotImpl struct { - dataTemp.DataTemp - BaseRepository[model.AiBot] -} - -func NewBotImpl(db *utils.Db) *BotImpl { - return &BotImpl{ - DataTemp: *dataTemp.NewDataTemp(db, new(model.AiBot)), - BaseRepository: NewBaseModel[model.AiBot](db.Client), - } -} - -// WithSysId 系统id -func (s *BotImpl) WithSysId(sysId interface{}) CondFunc { - return func(db *gorm.DB) *gorm.DB { - return db.Where("sys_id = ?", sysId) - } -} diff --git a/internal/data/impl/provider_set.go b/internal/data/impl/provider_set.go index 1284f11..53d389c 100644 --- a/internal/data/impl/provider_set.go +++ b/internal/data/impl/provider_set.go @@ -4,4 +4,10 @@ import ( "github.com/google/wire" ) -var ProviderImpl = wire.NewSet(NewSessionImpl, NewSysImpl, NewTaskImpl, NewChatHisImpl) +var ProviderImpl = wire.NewSet( + NewSessionImpl, + NewSysImpl, + NewTaskImpl, + NewChatHisImpl, + NewBotConfigImpl, +) diff --git a/internal/data/model/ai_bot.gen.go b/internal/data/model/ai_bot_config.gen.go similarity index 72% rename from internal/data/model/ai_bot.gen.go rename to internal/data/model/ai_bot_config.gen.go index ffe73c2..5c4f27a 100644 --- a/internal/data/model/ai_bot.gen.go +++ b/internal/data/model/ai_bot_config.gen.go @@ -8,13 +8,13 @@ import ( "time" ) -const TableNameAiBot = "ai_bot" +const TableNameAiBotConfig = "ai_bot_config" -// AiBot mapped from table -type AiBot struct { +// AiBotConfig mapped from table +type AiBotConfig struct { BotID int32 `gorm:"column:bot_id;primaryKey;autoIncrement:true" json:"bot_id"` SysID int32 `gorm:"column:sys_id;not null" json:"sys_id"` - BotType int32 `gorm:"column:bot_type" json:"bot_type"` + BotType int32 `gorm:"column:bot_type;not null;default:1" json:"bot_type"` BotName string `gorm:"column:bot_name;not null" json:"bot_name"` BotConfig string `gorm:"column:bot_config;not null" json:"bot_config"` CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"` @@ -23,7 +23,7 @@ type AiBot struct { DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"` } -// TableName AiBot's table name -func (*AiBot) TableName() string { - return TableNameAiBot +// TableName AiBotConfig's table name +func (*AiBotConfig) TableName() string { + return TableNameAiBotConfig } diff --git a/internal/entitys/bot.go b/internal/entitys/bot.go index 0a99113..fc24764 100644 --- a/internal/entitys/bot.go +++ b/internal/entitys/bot.go @@ -22,3 +22,8 @@ type RequireDataDingTalkBot struct { ImgByte []api.ImageData ImgUrls []string } + +type DingTalkBot struct { + ClientId string `mapstructure:"client_id"` + ClientSecret string `mapstructure:"client_secret"` +} diff --git a/internal/server/ding_talk_bot.go b/internal/server/ding_talk_bot.go index cda0e1c..1d6c4a4 100644 --- a/internal/server/ding_talk_bot.go +++ b/internal/server/ding_talk_bot.go @@ -1,7 +1,7 @@ package server import ( - "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" "ai_scheduler/internal/services" "context" @@ -11,7 +11,7 @@ import ( ) type DingBotServiceInterface interface { - GetServiceCfg(cfg map[string]*config.DingTalkBot) (*config.DingTalkBot, string) + GetServiceCfg() ([]entitys.DingTalkBot, error) OnChatBotMessageReceived(ctx context.Context, data *chatbot.BotCallbackDataModel) (content []byte, err error) } @@ -19,23 +19,28 @@ type DingTalkBotServer struct { Clients []*client.StreamClient } +// NewDingTalkBotServer 批量注册钉钉客户端cli +// 这里支持两种方式,一种是完全独立service,一种是直接用现成的service +// 独立的service,在本页的ProvideAllDingBotServices方法进行注册 +// 现成的service参考services->dtalk_bot.go +// 具体使用请根据实际业务需求 func NewDingTalkBotServer( - cfg *config.Config, services []DingBotServiceInterface, ) *DingTalkBotServer { clients := make([]*client.StreamClient, 0) for _, service := range services { - serviceConf, index := service.GetServiceCfg(cfg.DingTalkBots) - if serviceConf == nil { - log.Info("未找到%s配置", index) - continue + serviceConfigs, index := service.GetServiceCfg() + for _, serviceConf := range serviceConfigs { + if serviceConf.ClientId == "" || serviceConf.ClientSecret == "" { + continue + } + cli := DingBotServerInit(serviceConf.ClientId, serviceConf.ClientSecret, service) + if cli == nil { + log.Info("%s客户端初始失败", index) + continue + } + clients = append(clients, cli) } - cli := DingBotServerInit(serviceConf.ClientId, serviceConf.ClientSecret, service) - if cli == nil { - log.Info("%s客户端初始失败", index) - continue - } - clients = append(clients, cli) } return &DingTalkBotServer{ Clients: clients, diff --git a/internal/services/dtalk_bot.go b/internal/services/dtalk_bot.go index 2855471..864f5d7 100644 --- a/internal/services/dtalk_bot.go +++ b/internal/services/dtalk_bot.go @@ -3,6 +3,7 @@ package services import ( "ai_scheduler/internal/biz" "ai_scheduler/internal/config" + "ai_scheduler/internal/entitys" "context" "fmt" @@ -11,41 +12,39 @@ import ( ) type DingBotService struct { - config *config.Config - replier *chatbot.ChatbotReplier - env string - DingTalkBotBiz *biz.DingTalkBotBiz + config *config.Config + + dingTalkBotBiz *biz.DingTalkBotBiz } func NewDingBotService(config *config.Config, DingTalkBotBiz *biz.DingTalkBotBiz) *DingBotService { - return &DingBotService{config: config, replier: chatbot.NewChatbotReplier(), env: "public", DingTalkBotBiz: DingTalkBotBiz} + return &DingBotService{config: config, dingTalkBotBiz: DingTalkBotBiz} } -func (d *DingBotService) GetServiceCfg(cfg map[string]*config.DingTalkBot) (*config.DingTalkBot, string) { - return cfg[d.env], d.env +func (d *DingBotService) GetServiceCfg() ([]entitys.DingTalkBot, error) { + return d.dingTalkBotBiz.GetDingTalkBotCfgList() } func (d *DingBotService) OnChatBotMessageReceived(ctx context.Context, data *chatbot.BotCallbackDataModel) (content []byte, err error) { - requireData, err := d.DingTalkBotBiz.InitRequire(ctx, data) + requireData, err := d.dingTalkBotBiz.InitRequire(ctx, data) if err != nil { return } go func() { defer close(requireData.Ch) - - if recognizeErr := d.DingTalkBotBiz.Recognize(ctx, requireData); recognizeErr != nil { - requireData.Ch <- entitys.Response{ - Type: entitys.ResponseEnd, - Content: fmt.Sprintf("处理消息时出错: %v", recognizeErr), - } - } - //向下传递 - if err = d.handle.HandleMatch(ctx, nil, requireData); err != nil { - requireData.Ch <- entitys.Response{ - Type: entitys.ResponseEnd, - Content: fmt.Sprintf("匹配失败: %v", err), - } - } + //if match, _err := d.dingTalkBotBiz.Recognize(ctx, data); _err != nil { + // requireData.Ch <- entitys.Response{ + // Type: entitys.ResponseEnd, + // Content: fmt.Sprintf("处理消息时出错: %s", _err.Error()), + // } + //} + ////向下传递 + //if err = d.dingTalkBotBiz.HandleMatch(ctx, nil, requireData); err != nil { + // requireData.Ch <- entitys.Response{ + // Type: entitys.ResponseEnd, + // Content: fmt.Sprintf("匹配失败: %v", err), + // } + //} }() for { select { @@ -59,77 +58,10 @@ func (d *DingBotService) OnChatBotMessageReceived(ctx context.Context, data *cha if resp.Type == entitys.ResponseLog { return } - if err := d.handleRes(ctx, data, resp); err != nil { + if err := d.dingTalkBotBiz.HandleRes(ctx, data, resp); err != nil { return nil, fmt.Errorf("回复失败: %w", err) } } } return } - -func (d *DingBotService) handleRes(ctx context.Context, data *chatbot.BotCallbackDataModel, resp entitys.Response) error { - switch resp.Type { - case entitys.ResponseText: - return d.replyText(ctx, data.SessionWebhook, resp.Content) - case entitys.ResponseStream: - return d.replySteam(ctx, data.SessionWebhook, resp.Content) - case entitys.ResponseImg: - return d.replyImg(ctx, data.SessionWebhook, resp.Content) - case entitys.ResponseFile: - return d.replyFile(ctx, data.SessionWebhook, resp.Content) - case entitys.ResponseMarkdown: - return d.replyMarkdown(ctx, data.SessionWebhook, resp.Content) - case entitys.ResponseActionCard: - return d.replyActionCard(ctx, data.SessionWebhook, resp.Content) - default: - return nil - } -} - -func (d *DingBotService) replyText(ctx context.Context, SessionWebhook string, content string, arg ...string) error { - msg := content - if len(arg) > 0 { - msg = fmt.Sprintf(content, arg) - } - return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) -} - -func (d *DingBotService) replySteam(ctx context.Context, SessionWebhook string, content string, arg ...string) error { - msg := content - if len(arg) > 0 { - msg = fmt.Sprintf(content, arg) - } - return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) -} - -func (d *DingBotService) replyImg(ctx context.Context, SessionWebhook string, content string, arg ...string) error { - msg := content - if len(arg) > 0 { - msg = fmt.Sprintf(content, arg) - } - return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) -} - -func (d *DingBotService) replyFile(ctx context.Context, SessionWebhook string, content string, arg ...string) error { - msg := content - if len(arg) > 0 { - msg = fmt.Sprintf(content, arg) - } - return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) -} - -func (d *DingBotService) replyMarkdown(ctx context.Context, SessionWebhook string, content string, arg ...string) error { - msg := content - if len(arg) > 0 { - msg = fmt.Sprintf(content, arg) - } - return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) -} - -func (d *DingBotService) replyActionCard(ctx context.Context, SessionWebhook string, content string, arg ...string) error { - msg := content - if len(arg) > 0 { - msg = fmt.Sprintf(content, arg) - } - return d.replier.SimpleReplyText(ctx, SessionWebhook, []byte(msg)) -} diff --git a/internal/services/provider_set.go b/internal/services/provider_set.go index 668c7fe..867eb11 100644 --- a/internal/services/provider_set.go +++ b/internal/services/provider_set.go @@ -6,4 +6,10 @@ import ( "github.com/google/wire" ) -var ProviderSetServices = wire.NewSet(NewChatService, NewSessionService, gateway.NewGateway, NewTaskService, NewCallbackService, NewHistoryService) +var ProviderSetServices = wire.NewSet( + NewChatService, + NewSessionService, gateway.NewGateway, + NewTaskService, + NewCallbackService, + NewDingBotService, + NewHistoryService)