refactor: restructure channel gateway and chat module architecture

- Refactor channel adapters (feishu, telegram, local) with enhanced descriptor and config
- Restructure channel manager, service, types, and outbound messaging
- Simplify chat module by removing normalize.go and chat.go, consolidating into resolver and types
- Update router channel handlers and tests
- Sync swagger documentation
This commit is contained in:
BBQ
2026-02-06 20:22:37 +08:00
parent c3cfdc4096
commit a246b79a4f
42 changed files with 1683 additions and 1745 deletions
+16 -2
View File
@@ -17,8 +17,9 @@ import (
)
type Service struct {
queries *sqlc.Queries
logger *slog.Logger
queries *sqlc.Queries
logger *slog.Logger
containerLifecycle ContainerLifecycle
}
var (
@@ -40,6 +41,11 @@ func NewService(log *slog.Logger, queries *sqlc.Queries) *Service {
}
}
// SetContainerLifecycle registers a container lifecycle handler for bot operations.
func (s *Service) SetContainerLifecycle(lc ContainerLifecycle) {
s.containerLifecycle = lc
}
func (s *Service) AuthorizeAccess(ctx context.Context, actorID, botID string, isAdmin bool, policy AccessPolicy) (Bot, error) {
if s.queries == nil {
return Bot{}, fmt.Errorf("bot queries not configured")
@@ -279,6 +285,14 @@ func (s *Service) Delete(ctx context.Context, botID string) error {
if _, err := s.queries.GetBotByID(ctx, botUUID); err != nil {
return err
}
if s.containerLifecycle != nil {
if err := s.containerLifecycle.CleanupBotContainer(ctx, botID); err != nil {
s.logger.Error("failed to cleanup bot container",
slog.String("bot_id", botID),
slog.Any("error", err),
)
}
}
return s.queries.DeleteBotByID(ctx, botUUID)
}
+9 -1
View File
@@ -1,6 +1,9 @@
package bots
import "time"
import (
"context"
"time"
)
type Bot struct {
ID string `json:"id"`
@@ -53,6 +56,11 @@ type ListMembersResponse struct {
Items []BotMember `json:"items"`
}
// ContainerLifecycle handles container lifecycle events bound to bot operations.
type ContainerLifecycle interface {
CleanupBotContainer(ctx context.Context, botID string) error
}
const (
BotTypePersonal = "personal"
BotTypePublic = "public"