new telegram bot
This commit is contained in:
47
telegram_bot/main.go
Normal file
47
telegram_bot/main.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"example.com/m/adapter/backend"
|
||||
"example.com/m/bot"
|
||||
"example.com/m/handlers"
|
||||
"example.com/m/pkg/logger"
|
||||
"example.com/m/screens"
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const botToken = "8134938541:AAFcZhIGfYynQ9axyuA35R1nd7sPQZodrrQ"
|
||||
|
||||
func main() {
|
||||
logger.Init(logger.Config{
|
||||
AppName: "tgex-bot",
|
||||
AppVersion: "v0.0.1",
|
||||
PrettyConsole: true,
|
||||
})
|
||||
|
||||
// Инициализация backend client
|
||||
backendClient := backend.New(backend.Config{
|
||||
BaseURL: "http://localhost:8000",
|
||||
LoginURL: "https://unstabilising-lora-unframable.ngrok-free.dev/api/v1/auth/complete?token=",
|
||||
})
|
||||
|
||||
var mainMenu = func() bot.State { return &screens.MainMenu{} }
|
||||
newBot := func(chatID int64) echotron.Bot {
|
||||
return bot.NewBot(chatID, botToken, mainMenu, backendClient, handlers.HandleGlobalCallback)
|
||||
}
|
||||
|
||||
dsp := echotron.NewDispatcher(botToken, newBot)
|
||||
|
||||
log.Info().Msg("bot starting...")
|
||||
|
||||
for {
|
||||
if err := dsp.Poll(); err != nil {
|
||||
log.Error().Err(err).Msg("dsp.Poll failed, retrying in 5 seconds...")
|
||||
time.Sleep(5 * time.Second)
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user