How to receive messages on Telegram using this library ?

I'm moving forward and getting to know the FastBot.h library a little more

msg.text are the messages we type in Telegram and send to, in my case, a NodeMCU 12E.

I would like the String phrase to be the same as the message I type, but only if it starts with 12345. For example:

I type this on Telegram: 12345my Telegram message

Then on the serial monitor I will see what sentence became 12345my Telegram message

Then I will find a way to cut 12345 leaving just the rest. Realize then that 12345 is just a kind of password so that the String phrase is equal to a specific message (and not any message).

Then I will limit the size of the message using length(). As it stands, the code below makes the String phrase equal to 12345. But that is not the objective. I need to add free text to 12345.

//https://github.com/GyverLibs/FastBot/tree/main

#define WIFI_SSID "AAAAAA"
#define WIFI_PASS "BBBBBBB"
#define BOT_TOKEN "5653478678346909:AAHyfEJzNJGJKJRRRRHRElDSKbu4Q1f3Cmo"
#define CHAT_ID "6789994109"

#include <FastBot.h>
FastBot bot(BOT_TOKEN);

String frase;

void setup() {
  
  Serial.begin(115200);
  delay(1000);
  
  connectWiFi();

  bot.setToken(BOT_TOKEN);
  bot.setChatID(CHAT_ID);
  bot.attach(newMsg);    
  bot.setBufferSizes(512, 512);
  
}

void newMsg(FB_msg& msg) {

  if (msg.text == "12345") {
        frase = msg.text;
        Serial.print("frase é: ");Serial.println(frase);
      }

}

void loop() {
  bot.tick();
}

void connectWiFi() {
  delay(2000);
  Serial.begin(115200);
  Serial.println();

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    if (millis() > 15000) ESP.restart();
  }
  Serial.println("Connected");
}

Does anyone know how to do this ?

Thanks

What happens now? What responce do You get?

As it stands, the phrase code equals 12345 because the message I am typing on Telegram is 12345. I don't understand and I don't see how it would be typing 12345mysentence and the code accepting this addition. This is because the text of my sentence that I will type in front of the 12345, the Arduino code does not know. It would have to be something like this: "12345"+any text Anyway, I think it's going to be difficult

[image]

Sorry, I just don't get it. Maybe another day.

There is no reason to apologize. Let's wait. Who knows, maybe someone will come up with a good solution.

I solved it myself:

Only messages starting with 12345 sent from BOT telegram to Nodemcu will be accepted in the String phrase.

void newMsg(FB_msg& msg) {

  if (msg.text != "0") {
        String mensagem = msg.text;
        Serial.print("mensagem é: ");Serial.println(mensagem);
         if(mensagem.indexOf("12345") != -1) {
           mensagem.remove(0, 5);
           frase = mensagem;
           Serial.print("frase é: ");Serial.println(frase);
         }
        msg.text = "";
        mensagem = "";
        frase = "";
      }
}

Is Telegram is a real-time example for an instant messaging app?

in a blog that I came across the mentioned it as an instant message: