Controlling 1 output with 2 input (RFID & Telegram) at the same time

Hi I want ask how 2 input controlling 1 output, in my case RFID and Telegram Bot, work at the same time. If I separate each code input in work. Here my code

#include "SPI.h"
#include "MFRC522.h"
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <TelegramBot.h>
#define SS_PIN D4
#define RST_PIN D3
#define led1 D8
#define rel1 D1
#define rel2 D2

MFRC522 rfid(SS_PIN, RST_PIN);

MFRC522::MIFARE_Key key;
boolean pinState;
boolean RFIDMode = true;

const char* ssid  = "xxxx";
const char* password = "xxxx";

const char* BotToken = "xxxx";

WiFiClientSecure client;
TelegramBot bot (BotToken, client);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init(); 
  int state; //adaugat

Serial.print("Connecting Wifi: "); 
WiFi.begin(ssid, password);  
while (WiFi.status() != WL_CONNECTED) {   
  Serial.print(".");   
  delay(500);   
}   
Serial.println("");   
Serial.println("WiFi connected");   
bot.begin();

  pinMode(rel1, OUTPUT);
  pinMode(rel2, OUTPUT);
  pinMode(led1, OUTPUT);
digitalWrite(rel1, HIGH);
digitalWrite(rel2, HIGH);
digitalWrite(led1, HIGH);
}

void loop() {
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return;

  // Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  // Serial.println(rfid.PICC_GetTypeName(piccType));

  // Check is the PICC of Classic MIFARE type
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
    piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
    piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }

  String strID = "";
  for (byte i = 0; i < 4; i++) {
    strID +=
    (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
    String(rfid.uid.uidByte[i], HEX) +
    (i!=3 ? ":" : "");
  }
  strID.toUpperCase();

  // LED 
  Serial.print("Tap card key: ");
  Serial.println(strID);
  
if (RFIDMode == true) {
 if (strID.indexOf("F9:62:A8:98") >= 0 ||
     strID.indexOf("02:1D:3D:2D") >= 0 ||
     strID.indexOf("BD:4D:CD:73") >= 0 ||
     strID.indexOf("03:54:68:2C") >= 0) {
          if (digitalRead(led1) == LOW) {
                digitalWrite(rel1, LOW);   
                delay(500);
                digitalWrite(rel1, HIGH);
                 digitalWrite(led1, HIGH);
           }
        //   if (digitalRead(led1) == LOW)
        else{
                digitalWrite(rel2, LOW);   
                delay(500);
                digitalWrite(rel2, HIGH);
                 digitalWrite(led1, LOW);
           }
 }
         
  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();
}

if (RFIDMode == false) {
  message m = bot.getUpdates();
  if (m.text.equals("lock")) {
                digitalWrite(rel1, LOW);   
                delay(500);
                digitalWrite(rel1, HIGH);
                Serial.println("message received lock");  

           }
        //   if (digitalRead(led1) == LOW)
  else if (m.text.equals("unlock")) {
                digitalWrite(rel2, LOW);   
                delay(500);
                digitalWrite(rel2, HIGH);
                Serial.println("message received unlock");  

  }
}
}

This code is works on RFID, but Telegram bot didn’t work, I want works at the same time

Not sure what you are asking. Do you want the RFID OR the Telegram bot to unlock or do you want to require BOTH to unlock? Your code initializes RFIDMode to true and never resets it so your code only uses the RFID.

Also, the following line of code checks for the a new card present. If there is not one the rest of the code in loop() will not get executed at all!

  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return;

both of them, RFID and Telegram bot at the same time

rizkyakhbar:
both of them, RFID and Telegram bot at the same time

So you want to require someone have a valid RFID and send a message to lock or unlock? If so, does it matter what order?