new telegram bot

This commit is contained in:
Artem Tsyrulnikov
2025-12-28 15:50:06 +03:00
parent 69179c64be
commit 2fb8c83041
75 changed files with 3719 additions and 1046 deletions

View File

@@ -0,0 +1,47 @@
package screens
import (
"context"
"fmt"
"example.com/m/bot"
"github.com/NicoNex/echotron/v3"
"github.com/rs/zerolog/log"
)
type Login struct{}
func (s *Login) Enter(b *bot.Bot, mode bot.RenderMode) {
telegramID := b.ChatID
var username *string
chatInfo, err := b.GetChat(telegramID)
if err == nil && chatInfo.Result != nil && chatInfo.Result.Username != "" {
username = &chatInfo.Result.Username
}
token, err := b.Backend.CreateLoginToken(context.Background(), telegramID, username)
if err != nil {
log.Error().Err(err).Msg("Failed to create login token")
b.SendMessage("❌ Произошла ошибка при создании токена входа. Попробуйте позже.", b.ChatID, nil)
return
}
loginURL := b.Backend.GetLoginURL(token)
usernameDisplay := "аноним"
if username != nil && *username != "" {
usernameDisplay = *username
}
message := fmt.Sprintf("Привет, %s!\n\nНажми кнопку ниже для входа на сайт.", usernameDisplay)
b.SendMessageWithURLButton(message, "Войти на сайт", loginURL)
}
func (s *Login) HandleCallback(b *bot.Bot, u *echotron.Update) { return }
func (s *Login) HandleMessage(b *bot.Bot, u *echotron.Update) { return }
func (s *Login) Handle(b *bot.Bot, u *echotron.Update) {
b.SetState(&MainMenu{}, bot.NewMessage)
return
}