telebot icon indicating copy to clipboard operation
telebot copied to clipboard

The callback loads forever

Open fomotrader opened this issue 1 year ago • 1 comments

I'm pretty sure the issue is my understanding and not telebot, it's been about a day and a half of no progress so I thought I'd ask for help here.

Basically I'm trying to build a simple POC, where a list of buttons are displayed to a user, when the user clicks on any of the buttons I expect the matching callback handler to be triggered. Unfortunately in this case that does not happen, I've also added a test start command to confirm my bot was polling.

I'm at a loss and would appreciate if someone could look over my code and clear up any major misunderstandings on my part. Also does anyknow what the structure of inlnie buttons and callback buttons are in JSON.

"reply_markup": {
             "inline_keyboard": [[
               {
                 "text": "Test Button",
                 "callback_data": "ape_max"
               }
             ]]
           }

package main

import (
	"fmt"
	"log"
	"time"

	telebot "gopkg.in/telebot.v3"
)

var (
	TokenID = "replace_with_a_bot_id"
)

func main() {
	bot := NewBot()

	// Create an inline button for help
	btnHelp := telebot.InlineButton{
		Unique: "help",
		Text:   "ℹ Help",
	}

	// Setup inline keyboard
	inlineKeys := [][]telebot.InlineButton{
		{btnHelp},
	}

	bot.Handle("/start", func(c telebot.Context) error {
		// Send message with inline keyboard
		return c.Send("Choose an option:", &telebot.ReplyMarkup{
			InlineKeyboard: inlineKeys,
		})
	})

	// Handle the help button callback
	bot.Handle(&btnHelp, func(c telebot.Context) error {
		// Your help logic here
		fmt.Println("HELP", c)
		return c.Send("Here is some help: ...")
	})

	fmt.Println("STARTING TEST")

	// Start the bot's polling loop
	bot.Start()
}

func NewBot() *telebot.Bot {
	settings := telebot.Settings{
		Token:  TokenID,
		Poller: &telebot.LongPoller{Timeout: 10 * time.Second},
	}

	bot, err := telebot.NewBot(settings)

	if err != nil {
		log.Fatal(err)
		return nil
	}

	return bot
}

fomotrader avatar Nov 30 '23 22:11 fomotrader

Poller: &telebot.LongPoller{
			Timeout: 10 * time.Second,
			AllowedUpdates: []string{
				"message",
				"channel_post",
				"edited_channel_post",
				"callback_query", <- here
			},
		},

kslr avatar Jan 05 '24 16:01 kslr