From fd608a857cc46e835abad61787a3fb4fea63191b Mon Sep 17 00:00:00 2001 From: "Benjamin A. Shelton" Date: Thu, 5 Nov 2026 19:50:12 -0700 Subject: [PATCH] Committing current WIP with command set for administrators. For whatever reason, it wasn't displaying or refreshing in Telegram for Desktop. --- internal/app/bot.go | 55 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/internal/app/bot.go b/internal/app/bot.go index 54f0829..cab7707 100644 --- a/internal/app/bot.go +++ b/internal/app/bot.go @@ -70,7 +70,7 @@ func (b *bot) init() { } func (b *bot) AttachHandlers() { - fmt.Println("add handlers") + fmt.Println("add handlers", b.handler) b.handler.HandleMessage(func(ctx *th.Context, message telego.Message) error { fmt.Println("handling message") if !slices.Contains(b.settings.Chat.Channels, message.Chat.ID) { @@ -88,6 +88,21 @@ func (b *bot) AttachHandlers() { ))*/ return nil }, th.CommandEqual("start")) + + b.handler.HandleMessage(func(ctx *th.Context, message telego.Message) error { + fmt.Println("received help command:", message.Text) + // Send a message with inline keyboard + /*_, _ = ctx.Bot().SendMessage(ctx, tu.Message( + tu.ID(message.Chat.ID), + fmt.Sprintf("Hello %s!", message.From.FirstName), + ).WithReplyMarkup(tu.InlineKeyboard( + tu.InlineKeyboardRow( + tu.InlineKeyboardButton("Go!").WithCallbackData("go"), + )), + ))*/ + return nil + }, th.CommandEqual("help")) + } func (b *bot) SendMarkdownMessage(chatid int64, message string) error { @@ -143,7 +158,19 @@ func (b *bot) SendScripture() { } func (b *bot) SetCommands(ctx context.Context) (err error) { - commands, err := b.tgbot.GetMyCommands(ctx, &telego.GetMyCommandsParams{}) + commands, err := b.tgbot.GetMyCommands(ctx, &telego.GetMyCommandsParams{ + Scope: &telego.BotCommandScopeAllGroupChats{ + Type: "all_group_chats", + }, + }) + fmt.Println("all_group_chats:") + fmt.Println(commands) + commands, err = b.tgbot.GetMyCommands(ctx, &telego.GetMyCommandsParams{ + Scope: &telego.BotCommandScopeAllChatAdministrators{ + Type: "all_chat_administrators", + }, + }) + fmt.Println("all_chat_administrators:") fmt.Println(commands) if len(commands) > 0 { if b.settings.Debug.Commands.Reset { @@ -152,12 +179,13 @@ func (b *bot) SetCommands(ctx context.Context) (err error) { Type: "all_chat_administrators", }, }) - b.tgbot.DeleteMyCommands(ctx, &telego.DeleteMyCommandsParams{}) + b.tgbot.DeleteMyCommands(ctx, &telego.DeleteMyCommandsParams{ + Scope: &telego.BotCommandScopeAllGroupChats{ + Type: "all_group_chats", + }, + }) } - for _, command := range commands { - fmt.Println(command) - } - return + //return } if !b.settings.Debug.Commands.Register { return @@ -210,6 +238,9 @@ func (b *bot) SetCommands(ctx context.Context) (err error) { }, }) b.tgbot.SetMyCommands(ctx, &telego.SetMyCommandsParams{ + Scope: &telego.BotCommandScopeAllGroupChats{ + Type: "all_group_chats", + }, Commands: []telego.BotCommand{ { Command: "help", @@ -285,6 +316,11 @@ func (b *bot) SetWebhook(ctx context.Context, conf *settings.Settings) (err erro return } + info, err := b.tgbot.GetWebhookInfo(b.ctx) + if err != nil { + return + } + fmt.Println("webhook info:", info) err = b.tgbot.SetWebhook(b.ctx, &telego.SetWebhookParams{ URL: b.settings.Service.Webhook.URI, SecretToken: b.tgbot.SecretToken(), @@ -292,11 +328,6 @@ func (b *bot) SetWebhook(ctx context.Context, conf *settings.Settings) (err erro if err != nil { return } - info, err := b.tgbot.GetWebhookInfo(b.ctx) - if err != nil { - fmt.Println(info, err) - return - } mux := http.NewServeMux() updates, err := b.tgbot.UpdatesViaWebhook(ctx,