Open joroMaser opened 2 years ago
No, it won't crash @joroMaser.
The bot.getUpdate
code always return one update at a time. That is, the array length will always be 1. The question "why are we using an array?" was also raised at https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/issues/65
This is why you see code along these lines:
int num_messages = bot.getUpdates(bot.last_message_received + 1); // 0..1
while (num_messages) {
handle_new_messages(bot.messages)
num_messages = bot.getUpdates(bot.last_message_received + 1); // <- extra polling
}
When something like this should be enough, in my opinion:
int num_messages = bot.getUpdates(bot.last_message_received + 1); // 0..N
for (int i = 0; i < num_messages; i++) {
handle_new_message(bot.messages[i]);
}
I guess HANDLE_MESSAGES should be configurable in the future, to be able to process several messages in a single batch.
In UniversalTelegramBot.h we can see:
So in examples that you show how to handle message
If numNewMessages will be bigger than 1 the program will crash , because the maximum size of bot.messages is 1