mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user