fix for long incoming messages and /cmd@bot_name handling

This commit is contained in:
Marcel Walter 2026-01-21 12:30:32 +01:00
parent 2121251553
commit 163fe83c8a

View File

@ -19,7 +19,7 @@ void Telegram::handleNewMessages(int numNewMessages)
if (from_name == "")
from_name = "Guest";
if (text == "/send_test_action")
if (text.startsWith("/send_test_action"))
{
bot.sendChatAction(chat_id, "typing");
delay(4000);
@ -53,11 +53,11 @@ void Telegram::handleNewMessages(int numNewMessages)
String DisplayText = cmdList[i].functionPointer(Arguments);
if (DisplayText.isEmpty())
{
bot.sendMessage(chat_id, "Display text is empty!!");
bot.sendMessage(chat_id, "Display text ist leer!!");
}
else
{
String Answer = "Display text is \"";
String Answer = "Display zeigt \"";
Answer += DisplayText;
Answer += "\".";
bot.sendMessage(chat_id, Answer);
@ -67,7 +67,7 @@ void Telegram::handleNewMessages(int numNewMessages)
}
}
if ((text == "/display_start") || (text == "/start") || (text == "/help"))
if (text.startsWith("/start") || text.startsWith("/help"))
{
String welcome = "Willkommen beim Tür-Display-Bot, " + from_name + ".\n\n";
welcome += "Hier kommen die möglichen Kommandos, die ich verstehe:\n";
@ -97,6 +97,7 @@ void Telegram::init()
Serial.println("clearing old messages");
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
bot.maxMessageLength = 2500;
while (numNewMessages)
{
for (int i = 0; i < numNewMessages; i++)
@ -139,7 +140,7 @@ void Telegram::init()
serializeJson(doc, jsonString);
bot.setMyCommands(jsonString);
bot.sendMessage(TELEGRAM_BOT_OWNER, "Hi I'm online.");
bot.sendMessage(TELEGRAM_BOT_OWNER, "Hi, ich bin online.");
bot_lasttime = millis();
}