counting button presses and Sending them from NodeMcu 12E to Telegram Bot


Hope everybody is doing well.

I am seeking help with my project. I am using only the NodeMcu 12E module to send message to the telegram

bot. When the user pushes the button on the NodeMcu module, the button press counts are sent to

telegram bot.

My problem is that the program doesn't count accurately because this instruction takes about 5 seconds

and if the user presses the button when this instruction is running , the counting button presses are not


 bot.sendMessage(chat_id, String(buttonPushCounter));

Could you please guide me and help me through this.

Thanks in advance

Best Wishes

Here is my arduino code

void loop() 
   buttonState = digitalRead(button);
  if (buttonState != lastButtonState) 
    if (buttonState == HIGH) 
         Serial.print("number of button pushes:  ");
  }//BASIC if
    lastButtonState = buttonState;
    if (millis() > Bot_lasttime + Bot_mtbs)
         bot.sendMessage(chat_id, String(buttonPushCounter));
        Bot_lasttime = millis(); 
}// LOOP

Use interrupts for detecting the button presses and increment the count value in the ISR. Here are some links for reference:
External Interrupts - Adafruit
Arduino Playground
All About Circuits


thank you