Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abnormal keyboard callback data #757

Open
bokuore opened this issue Nov 10, 2024 · 1 comment
Open

Abnormal keyboard callback data #757

bokuore opened this issue Nov 10, 2024 · 1 comment

Comments

@bokuore
Copy link

bokuore commented Nov 10, 2024

set property of button with constant string "nav_merchant", but invisible character 'FF' insert in string when handling callback.

code like:

const uniqueNavMerchant = "nav_merchant"
...
//create button with data callback
btnMerchant := guideMenu.Data("Merchant", uniqueNavMerchant)

...
// handle callback
func (nav *Navigation) onCallback(c telebot.Context) (err error) {
	var callback = c.Callback()
...
	if callback.Data == uniqueNavMerchant {
                //should go here
		log.Printf("merchant menu")
		return nav.onMerchantMenu(c)
	} else {
                // but run to here
		log.Printf("[%s/%d] not equal [%s/%d]",
			data, len(data),
			uniqueNavMerchant, len(uniqueNavMerchant))
	}

above log output like this, same text but different length
[ nav_merchant/13] not equal [nav_merchant/12]

when copy this log to text editor, this a abnormal at head of string
image

same problem to context.Callback().Data and context.Data()

@cyrillus31
Copy link

What I've just noticed with InlineKeyboard callbacks is that somehow in my case c.Context().Data contains both unique button identifier and button data divided by pipe ("|") symbol and preceded by some whitespace characters I didn't care to define. Here's an example of how you can work around it:

	bot.Handle(tele.OnCallback, func(ctx tele.Context) error {
		callback := ctx.Callback()
		if data := strings.Split(callback.Data, "|")[1]; strings.TrimSpace(data) == "someDataToCheckFor" {
			return ctx.Respond(&tele.CallbackResponse{Text: "some response"})
		}
		return nil
	})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants