telebot icon indicating copy to clipboard operation
telebot copied to clipboard

Is it possible to handle ReplyButtons with the same text?

Open Nekr0bz opened this issue 3 years ago • 1 comments

How can I make ReplyMarkups with buttons that have the same text but different handlers?

Nekr0bz avatar Aug 05 '22 20:08 Nekr0bz

How can I make ReplyMarkups with buttons that have the same text but different handlers?

It's just a matter of setting unique ID to a button You can do it llike so:

rpayload := fmt.Sprintf("%x",sha256.Sum256(some_random_bytes))
rpayload2 := fmt.Sprintf("%x",sha256.Sum256(some_random_bytes2))
var btnConfirm = menu.Data("CONFIRM","confirm_"+rpayload[0:9],"resp")
var btnConfirm2 = menu.Data("CONFIRM","confirm_"+rpayload2[0:9],"resp")
menu.Inline(menu.Row(btnConfirm,btnConfirm2),)

One downside of that is when you making new buttons more and more, you'll end up with a pile of garbage in handlers, because telebot has no particular way to unregister them. You'll have to hack its code a bit to make it work better then.

klebed avatar Sep 08 '22 15:09 klebed