feat: notify by telegram while new memo create by HTTP (#2215)

* Inject telegram bot into API service

* Add support for send telegram message

* Send notification by telegram while new memo post
This commit is contained in:
Athurg Gooth
2023-09-13 21:36:43 +08:00
committed by GitHub
parent 36209eaef1
commit 626ff5e3a7
4 changed files with 58 additions and 12 deletions

View File

@ -46,6 +46,7 @@ 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,
@ -53,7 +54,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store
// Asynchronous runners.
backupRunner: service.NewBackupRunner(store),
telegramBot: telegram.NewBotWithHandler(newTelegramHandler(store)),
telegramBot: telegramBot,
}
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
@ -103,7 +104,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)
apiV1Service := apiv1.NewAPIV1Service(s.Secret, profile, store, telegramBot)
apiV1Service.Register(rootGroup)
s.apiV2Service = apiv2.NewAPIV2Service(s.Secret, profile, store, s.Profile.Port+1)