From 7da10cd367f5776730b7f752010b08955cdc50f1 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 19 Sep 2023 22:35:20 +0800 Subject: [PATCH] chore: update telegram integration folder --- server/{ => integration}/telegram.go | 14 +++++++------- server/server.go | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) rename server/{ => integration}/telegram.go (94%) diff --git a/server/telegram.go b/server/integration/telegram.go similarity index 94% rename from server/telegram.go rename to server/integration/telegram.go index aadd8ab7..4ffa90f6 100644 --- a/server/telegram.go +++ b/server/integration/telegram.go @@ -1,4 +1,4 @@ -package server +package integration import ( "bytes" @@ -15,15 +15,15 @@ import ( "github.com/usememos/memos/store" ) -type telegramHandler struct { +type TelegramHandler struct { store *store.Store } -func newTelegramHandler(store *store.Store) *telegramHandler { - return &telegramHandler{store: store} +func NewTelegramHandler(store *store.Store) *TelegramHandler { + return &TelegramHandler{store: store} } -func (t *telegramHandler) BotToken(ctx context.Context) string { +func (t *TelegramHandler) BotToken(ctx context.Context) string { return t.store.GetSystemSettingValueWithDefault(&ctx, apiv1.SystemSettingTelegramBotTokenName.String(), "") } @@ -32,7 +32,7 @@ const ( successMessage = "Success" ) -func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot, message telegram.Message, attachments []telegram.Attachment) error { +func (t *TelegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot, message telegram.Message, attachments []telegram.Attachment) error { reply, err := bot.SendReplyMessage(ctx, message.Chat.ID, message.MessageID, workingMessage) if err != nil { return errors.Wrap(err, "Failed to SendReplyMessage") @@ -121,7 +121,7 @@ func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot, return err } -func (t *telegramHandler) CallbackQueryHandle(ctx context.Context, bot *telegram.Bot, callbackQuery telegram.CallbackQuery) error { +func (t *TelegramHandler) CallbackQueryHandle(ctx context.Context, bot *telegram.Bot, callbackQuery telegram.CallbackQuery) error { var memoID int32 var visibility store.Visibility n, err := fmt.Sscanf(callbackQuery.Data, "%s %d", &visibility, &memoID) diff --git a/server/server.go b/server/server.go index ddd66c4e..f074a8ef 100644 --- a/server/server.go +++ b/server/server.go @@ -20,6 +20,7 @@ import ( apiv2 "github.com/usememos/memos/api/v2" "github.com/usememos/memos/common/log" "github.com/usememos/memos/plugin/telegram" + "github.com/usememos/memos/server/integration" "github.com/usememos/memos/server/profile" "github.com/usememos/memos/server/service" "github.com/usememos/memos/store" @@ -47,7 +48,6 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store e.HideBanner = true e.HidePort = true - telegramBot := telegram.NewBotWithHandler(newTelegramHandler(store)) s := &Server{ e: e, Store: store, @@ -55,7 +55,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store // Asynchronous runners. backupRunner: service.NewBackupRunner(store), - telegramBot: telegramBot, + telegramBot: telegram.NewBotWithHandler(integration.NewTelegramHandler(store)), } e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ @@ -118,7 +118,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store s.Secret = secret rootGroup := e.Group("") - apiV1Service := apiv1.NewAPIV1Service(s.Secret, profile, store, telegramBot) + apiV1Service := apiv1.NewAPIV1Service(s.Secret, profile, store, s.telegramBot) apiV1Service.Register(rootGroup) s.apiV2Service = apiv2.NewAPIV2Service(s.Secret, profile, store, s.Profile.Port+1)