Closed konig87nikkinakki closed 2 years ago
I'm sorry, but there was a small bug, I've just uploaded a fix and drafted a new release.
Aniway, why you set TBMessage msg;
as global?
It should be local, otherwise it keeps in memory your last message and in the next loop it will be processed again.
You could clear the content of msg.text
, but it's a non-sense, keep it local.
Regarding the welcome message, could be clearer in this way (C ++ 11 range-based for, and no use of global variables) Concatenating String as you have done it is not recommended because a lot of unnecessarily "temporary" copies are created.
For your needs, maybe is more convenient create a group and send message only once. Every member of groups will can then interact with bot directly from group chat.
If you are using ESP32, I would suggest also to update to latest versione of core 2.0.3 because they have done a very good work in this latest release.
const int64_t destinatari[] = {755575XXX, 76154XXX2};
....
....
for (int64_t destinatario : destinatari)
{
char welcomeMessage[100];
snprintf (welcomeMessage, sizeof(welcomeMessage),
"ESP32 è stato spento e riacceso. IP: %d.%d.%d.%d\n",
WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);
myBot.sendTo(destinatario, welcomeMessage);
delay(100);
}
Thank you for support, i use TBMessage msg as global because in other functions i use myBot.sendTo(msg.sender.id, "risposta") to answer only to the sender of message, and (i ve thought) if TBMessage is local, msg.sender.id in other function could be Null. i ll try to use it local and see what happens.
i dont want to create a Telegram Group because users dont need to contact each other, that s why I better like to do what i was trying to code.
where is the fix that you just uploaded? is it a library's new version?
ok i ll download 2.0.3 this afternoon :-D
Some time it's needed in order to see new versions with Arduino Library manager.
If you need to do something with message inside a function, you can pass the reference to TBMessage
void doSomething (TBMessage &theMsg) {
Serial.print("New message from ");
Serial.println(theMsg.sender.id);
Serial.println(theMsg.text);
}
void loop() {
TBMessage msg;
if (myBot.getNewMessage(msg)) {
doSomething (msg);
}
}
Hi, this is not properly an issue: it's something wrong on sketch i think. i tried to modify lightbot.ino because i need a welcome message at startup, so this is sketch:
As you can see, a FOR send to DESTINATARI the welcome message. it WORKS, both my phones receive welcome message but then when one of them send command /light_on or /light_off ESP32 answers him twice "Light is now ON" or "off".
i don't ask you to fix my problem, please just tell me if it's a library bug or if it's my sketch not good. before to code harder, i d like to fix these small issues, thank you so much!