mirror of
https://github.com/usememos/memos.git
synced 2024-12-23 19:21:57 +03:00
chore: update telegram integration folder
This commit is contained in:
parent
6d45616dbe
commit
7da10cd367
server
@ -1,4 +1,4 @@
|
|||||||
package server
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -15,15 +15,15 @@ import (
|
|||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type telegramHandler struct {
|
type TelegramHandler struct {
|
||||||
store *store.Store
|
store *store.Store
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTelegramHandler(store *store.Store) *telegramHandler {
|
func NewTelegramHandler(store *store.Store) *TelegramHandler {
|
||||||
return &telegramHandler{store: store}
|
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(), "")
|
return t.store.GetSystemSettingValueWithDefault(&ctx, apiv1.SystemSettingTelegramBotTokenName.String(), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ const (
|
|||||||
successMessage = "Success"
|
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)
|
reply, err := bot.SendReplyMessage(ctx, message.Chat.ID, message.MessageID, workingMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed to SendReplyMessage")
|
return errors.Wrap(err, "Failed to SendReplyMessage")
|
||||||
@ -121,7 +121,7 @@ func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
|
|||||||
return err
|
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 memoID int32
|
||||||
var visibility store.Visibility
|
var visibility store.Visibility
|
||||||
n, err := fmt.Sscanf(callbackQuery.Data, "%s %d", &visibility, &memoID)
|
n, err := fmt.Sscanf(callbackQuery.Data, "%s %d", &visibility, &memoID)
|
@ -20,6 +20,7 @@ import (
|
|||||||
apiv2 "github.com/usememos/memos/api/v2"
|
apiv2 "github.com/usememos/memos/api/v2"
|
||||||
"github.com/usememos/memos/common/log"
|
"github.com/usememos/memos/common/log"
|
||||||
"github.com/usememos/memos/plugin/telegram"
|
"github.com/usememos/memos/plugin/telegram"
|
||||||
|
"github.com/usememos/memos/server/integration"
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/server/profile"
|
||||||
"github.com/usememos/memos/server/service"
|
"github.com/usememos/memos/server/service"
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
@ -47,7 +48,6 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
|
|||||||
e.HideBanner = true
|
e.HideBanner = true
|
||||||
e.HidePort = true
|
e.HidePort = true
|
||||||
|
|
||||||
telegramBot := telegram.NewBotWithHandler(newTelegramHandler(store))
|
|
||||||
s := &Server{
|
s := &Server{
|
||||||
e: e,
|
e: e,
|
||||||
Store: store,
|
Store: store,
|
||||||
@ -55,7 +55,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
|
|||||||
|
|
||||||
// Asynchronous runners.
|
// Asynchronous runners.
|
||||||
backupRunner: service.NewBackupRunner(store),
|
backupRunner: service.NewBackupRunner(store),
|
||||||
telegramBot: telegramBot,
|
telegramBot: telegram.NewBotWithHandler(integration.NewTelegramHandler(store)),
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
|
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
|
||||||
@ -118,7 +118,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
|
|||||||
s.Secret = secret
|
s.Secret = secret
|
||||||
|
|
||||||
rootGroup := e.Group("")
|
rootGroup := e.Group("")
|
||||||
apiV1Service := apiv1.NewAPIV1Service(s.Secret, profile, store, telegramBot)
|
apiV1Service := apiv1.NewAPIV1Service(s.Secret, profile, store, s.telegramBot)
|
||||||
apiV1Service.Register(rootGroup)
|
apiV1Service.Register(rootGroup)
|
||||||
|
|
||||||
s.apiV2Service = apiv2.NewAPIV2Service(s.Secret, profile, store, s.Profile.Port+1)
|
s.apiV2Service = apiv2.NewAPIV2Service(s.Secret, profile, store, s.Profile.Port+1)
|
||||||
|
Loading…
Reference in New Issue
Block a user