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