shurillu / CTBot

A simple (and easy to use) Arduino Telegram BOT Library for ESP8266/ESP32
MIT License
147 stars 34 forks source link

possible to act on only the last received message? #102

Closed mjtrini closed 1 year ago

mjtrini commented 1 year ago

Hello and greetings again. I was wondering if it is possible to CTBot act on only the last received message upon reconnection to the internet. For example if I send 9 messages while power is lost to my esp8266 , it would act on all 9 messages when power is restored and the Internet connection made.

I'm using my esp8266 to control my gate, so I prefer it to act on the most recent message when power is lost then restored (instead of activating my gate 9 times in the example).

Is there any way for your awesome library to do this?

Much respect, Michael.

shurillu commented 1 year ago

Hello Michael, it's quite easy to implement: when the bot start (in the setup phase), you can download all messages using a getNewMessage() inside a while loop. Something like that:

...
TBMessage msg;
while (myBot.getNewMessage(msg, true)) {
   Serial.print("Message dropped: ");
   Serial.println(msg.text);
}
...

This code should "purge" all messages. After that, tou can manage the new incoming messages as usual. Keep in mind that you have to connect to the WiFi network and set the token BEFORE that snippet.

Finally, these are not issues, just ways to implement something ;-)

Cheers,

Stefano

mjtrini commented 1 year ago

As always my deepest thanks to you Sir! You are a genius!