diff --git a/include/Telegram.h b/include/Telegram.h index 87d50d9..62064df 100644 --- a/include/Telegram.h +++ b/include/Telegram.h @@ -7,6 +7,7 @@ struct TelegramCommand { const String command; String (*const functionPointer) (const String arguments); + const String description; }; class Telegram diff --git a/src/Telegram.cpp b/src/Telegram.cpp index 66e1d27..244877b 100644 --- a/src/Telegram.cpp +++ b/src/Telegram.cpp @@ -1,5 +1,6 @@ #include #include "secrets.h" +#include const char *Telegram::BOT_TOKEN = TELEGRAM_BOT_TOKEN; const unsigned long Telegram::BOT_MTBS = 1000; // mean time between scan messages @@ -111,6 +112,33 @@ void Telegram::init() numNewMessages = bot.getUpdates(bot.last_message_received + 1); } + JsonDocument doc; + JsonArray commandsJsonArray = doc.to(); + String jsonString; + + // add all the commands to the list + for (uint32_t i = 0; i < cmdListCount; i++) + { + auto cmdObj = commandsJsonArray.add(); + + // remove the prepending slash as it is not needed here + String tmp = cmdList[i].command; + tmp.remove(0,1); + cmdObj["command"] = tmp; + cmdObj["description"] = cmdList[i].description; + } + + // add generic commands to the list + auto helpObj = commandsJsonArray.add(); + helpObj["command"] = "help"; + helpObj["description"] = "Zeigt einen Hilfstext an"; + // auto startObj = commandsJsonArray.add(); + // startObj["command"] = "start"; + // startObj["description"] = "Startet die Konversation"; + + serializeJson(doc, jsonString); + bot.setMyCommands(jsonString); + bot.sendMessage(TELEGRAM_BOT_OWNER, "Hi I'm online."); bot_lasttime = millis(); } diff --git a/src/main.cpp b/src/main.cpp index 8cc6d72..6846917 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,12 +129,17 @@ String printText(String Args); String printLate15(String Args); String printLate30(String Args); +#define OPEN_STRING "offen" +#define CLOSED_STRING "leider zu" +#define LATE15_STRING "Wir oeffnen 15 Minuten spaeter" +#define LATE30_STRING "Wir oeffnen 30 Minuten spaeter" + TelegramCommand myCmdList[]{ - {"/open", printOpen}, - {"/close", printClose}, - {"/text", printText}, - {"/late_15", printLate15}, - {"/late_30", printLate30}, + {"/open", printOpen, "Display zeigt \"" OPEN_STRING "\""}, + {"/close", printClose, "Display zeigt \"" CLOSED_STRING "\""}, + {"/text", printText, "(lange drücken) Display zeigt den Text hinter dem Kommando an"}, + {"/late_15", printLate15, "Display zeigt \"" LATE15_STRING "\""}, + {"/late_30", printLate30, "Display zeigt \"" LATE30_STRING "\""}, }; uint32_t myCmdListCnt = sizeof(myCmdList) / sizeof(myCmdList[0]); @@ -399,7 +404,7 @@ void displayText(const char *text, bool background, int16_t x, int16_t y) String printOpen(String Args) { - Text = "offen"; + Text = OPEN_STRING; publishOpen(); return Text; @@ -407,7 +412,7 @@ String printOpen(String Args) String printClose(String Args) { - Text = "leider zu"; + Text = CLOSED_STRING; publishClose(); return Text; @@ -426,7 +431,7 @@ String printText(String Args) String printLate15(String Args) { - Text = "Wir oeffnen 15 Minuten spaeter"; + Text = LATE15_STRING; publishClose(); return Text; @@ -434,7 +439,7 @@ String printLate15(String Args) String printLate30(String Args) { - Text = "Wir oeffnen 30 Minuten spaeter"; + Text = LATE30_STRING; publishClose(); return Text;