Closed leobel96 closed 6 years ago
Hello Leonardo, This is not a issue related to the library implementation but it is related to the implementation/design of the your app.
So I should close this issue but today I'm in a good mood :-) Just to better understand your problem, let me use this example. A supermarket implement a bot to make orders using the inline keyboard. The first “layer” of menu ask to the consumer if he/she want to buy vegetables or meat
What do you want to buy? [Vegetables] [Meat]
I choose “Meat”. Then the bot show the kind of meat I want to buy, for example:
What kind of meat? [Pork] [Beef] [Chicken]
Finally the bot ask me how much meat, in grams, and I have to insert the weight using the traditional keyboard.
So the problem is identify when a text digited with the keyboard is "the amount of meat ordered" rather than "the amount of vegetables" or a generic text... Is it correct?
Stefano
Yes, It's correct! I thought about saving in an array for "pork", an array for "beef" and an array for "chicken" the IDs of the users that have previously pushed those buttons but I should allocate Very long arrays (I don't know how many people could enter in a menu at the same time) and, when they enter a text, check if their ID is in one of the arrays, if yes suppose that what they have written is a quantity, parse it and remove their ID from the array. It isn't a good solution in my opinion.
Mmmm, the problem is not so simply. For every customer, you have to know the kind of food and the quantity/weight desired. So you can define every possible food like that:
Also, you define a structure like that:
typedef struct { uint32_t id; // the telegram ID of the customer uint8_t foodID; // one of the define before uint16_t quantity; // the quantity ordered } foodOrder;
When a customer choose a kind of food, you add a record of foodOrder struct in a array/dinamically allocated list.
For example, if a customer 11735 push the button [Meat] -> [Chicken] then you will add a record with id = 11735 and foodID=MEAT_CHICKEN
If a customer send a text message, the message handler function scan the array/list searching the telegram customer ID. If find it, the message is related to the order found, otherwise is a general text message.
In the example above, if the customer 11735 wrote 500, the message handler function will found a record belonging to 11735 that want a chicken meat so the order can be dispached to the kitchen.
It's not the best solution but could be a begin.
Can we close the issue?
Best wishes and good luck wit your app!
Stefano
I thought there was a simpler and better solution but I'll do it in this way. Thank you!
Hello, I know it isn't a real issue but it is partially related to this library and, so, I ask it here. I have made an Inline Keyboard for my bot (I really like your library, great work) and I know if a message comes from a button using messageType. The menu I've made is multipage and after that you have pressed a sequence of buttons, my bot asks you a text value that you have to write using the classic keyboard; is there a way to recognise a message which has been written in this way? I don't know if I was clear. Thank you!