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

Greetings!

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

accurate.

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

Could you please guide me and help me through this.

Thanks in advance

Best Wishes
Bob

Here is my arduino code

void loop() 
{
   buttonState = digitalRead(button);
  if (buttonState != lastButtonState) 
  {
    
    if (buttonState == HIGH) 
       {
         buttonPushCounter++;
         Serial.print("number of button pushes:  ");
         Serial.println(buttonPushCounter);
      
       } 
    else 
        {
 
        }
    
    delay(50);
  }//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

resolved.

thank you