mirror of
https://github.com/usememos/memos.git
synced 2024-12-19 00:51:30 +03:00
chore: update telegram integration folder
This commit is contained in:
parent
6d45616dbe
commit
7da10cd367
@ -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)
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user