Files
ai-agent/internal/handlers/api/channel_handler.go
T

75 lines
1.8 KiB
Go
Raw Normal View History

package api
2026-04-09 10:01:23 +08:00
import (
"agent-desk/internal/pkg/dto/response"
"agent-desk/internal/pkg/enums"
"agent-desk/internal/pkg/errorsx"
"agent-desk/internal/pkg/httpx"
"agent-desk/internal/services"
2026-04-09 10:01:23 +08:00
"github.com/gin-gonic/gin"
2026-04-09 10:01:23 +08:00
)
func ChannelAnyConfig(ctx *gin.Context) {
channel := services.ChannelService.GetEnabledChannel(ctx)
2026-04-09 10:01:23 +08:00
if channel == nil {
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0211"))
return
2026-04-09 10:01:23 +08:00
}
cfg, err := resolveWidgetConfig(channel.ChannelType, channel.ConfigJSON)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
2026-04-09 10:01:23 +08:00
ret := response.WidgetConfigResponse{
ChannelID: channel.ChannelID,
ChannelType: channel.ChannelType,
Title: cfg.Title,
Subtitle: cfg.Subtitle,
ThemeColor: cfg.ThemeColor,
Position: cfg.Position,
Width: cfg.Width,
2026-04-09 10:01:23 +08:00
}
httpx.WriteJSON(ctx, ret)
2026-04-09 10:01:23 +08:00
}
type webLikeWidgetConfig struct {
Title string
Subtitle string
ThemeColor string
Position string
Width string
}
func resolveWidgetConfig(channelType, rawConfig string) (*webLikeWidgetConfig, error) {
switch channelType {
case enums.ChannelTypeWeb:
cfg, err := services.ChannelService.ParseWebChannelConfig(rawConfig)
if err != nil {
return nil, err
}
return &webLikeWidgetConfig{
Title: cfg.Title,
Subtitle: cfg.Subtitle,
ThemeColor: cfg.ThemeColor,
Position: cfg.Position,
Width: cfg.Width,
}, nil
case enums.ChannelTypeWechatMP:
cfg, err := services.ChannelService.ParseWechatMPChannelConfig(rawConfig)
if err != nil {
return nil, err
}
return &webLikeWidgetConfig{
Title: cfg.Title,
Subtitle: cfg.Subtitle,
ThemeColor: cfg.ThemeColor,
Position: "right",
Width: "100%",
}, nil
default:
return nil, errorsx.InvalidParamI18n("error.e0313")
}
}