fix: correct Telegram update/keyboard models and harden env parsing

This commit is contained in:
2026-03-17 16:17:26 +03:00
parent 1e043da05d
commit 4ebe76dd4a
26 changed files with 992 additions and 140 deletions

View File

@@ -100,17 +100,17 @@ func gatherCommands[T any](bot *Bot[T]) []tgapi.BotCommand {
// log.Fatal(err)
// }
func (bot *Bot[T]) AutoGenerateCommands() error {
commands := gatherCommands(bot)
if len(commands) > 100 {
return ErrTooManyCommands
}
// Clear existing commands to avoid duplication or stale entries
_, err := bot.api.DeleteMyCommands(tgapi.DeleteMyCommandsP{})
if err != nil {
return fmt.Errorf("failed to delete existing commands: %w", err)
}
commands := gatherCommands(bot)
if len(commands) > 100 {
return ErrTooManyCommands
}
// Register commands for each scope
scopes := []*tgapi.BotCommandScope{
{Type: tgapi.BotCommandScopePrivateType},
@@ -148,15 +148,16 @@ func (bot *Bot[T]) AutoGenerateCommands() error {
// log.Fatal(err)
// }
func (bot *Bot[T]) AutoGenerateCommandsForScope(scope *tgapi.BotCommandScope) error {
_, err := bot.api.DeleteMyCommands(tgapi.DeleteMyCommandsP{Scope: scope})
if err != nil {
return fmt.Errorf("failed to delete existing commands: %w", err)
}
commands := gatherCommands(bot)
if len(commands) > 100 {
return ErrTooManyCommands
}
_, err := bot.api.DeleteMyCommands(tgapi.DeleteMyCommandsP{Scope: scope})
if err != nil {
return fmt.Errorf("failed to delete existing commands: %w", err)
}
_, err = bot.api.SetMyCommands(tgapi.SetMyCommandsP{
Commands: commands,
Scope: scope,