-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Hi! Thank you for https://github.com/go-telegram/bot library, it's awesome and helped a lot.
But this library has several important points that made me waste lots of time.
Let's look at inline keyboard. It uses callbacks. What if our app exits/crashes, but inline button still exist in chat? Right, when the button is clicked, this request will be routed to default handler.
Okay, I made some recover mechanism in default handler that checks for callback query. But it looks such ugly. Because the data that was stored in-memory is lost, I have to put my data to callbackData (which is right way as telegram devs intented it to be used). And then parse it, removing btn num from the end which is added to callbackData by this lib.
So how I suggest to work with inline keyboard callbacks: DO NOT use callback data as some handler prefix, it's not a command text to parse. Check for message CallbackQuery is enough. If it's not nil, then we have a deal with inline button. So we should register only one handler for callbacks. And use callback query data as data container, not in-memory - there we can place keyboard name, btn num, user id and etc. Then we can parse callback data (for example, we marshalled it as json and have some basic schema for callbacks), get keyboard name and btn num and then route to necessary logic.
I'm writing this without any aggression or disrespect, you made great work, but I think this part of lib should be completely refactored. If any help needed, can make some pull requests