66
77// Telegram Bot is technically a connector, especially with admin notifications. Might want to rename it.
88
9- #include " secrets .h"
9+ #include " shared/secretsService .h"
1010#include " shared/serialWrapper.h"
1111#include < Arduino.h>
12+ #include < SafeString.h>
1213#include < UniversalTelegramBot.h> // https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
1314#include < WiFiClientSecure.h>
14- #include < SafeString.h>
1515
1616namespace Input_Telegram {
1717
@@ -36,8 +36,7 @@ void logMsg(const telegramMessage& msg) {
3636}
3737
3838void sendModeKeyboard (const String& chat_id) {
39- bot.sendMessageWithReplyKeyboard (chat_id, F (" Choose a command: " ), " " ,
40- F (" [[\" /off\" ,\" /on\" ], \" /clock\" ]" ), true );
39+ bot.sendMessageWithReplyKeyboard (chat_id, F (" Choose a command: " ), " " , F (" [[\" /off\" ,\" /on\" ], \" /clock\" ]" ), true );
4140}
4241
4342void displayPairingKey () {
@@ -47,8 +46,7 @@ void displayPairingKey() {
4746}
4847
4948void pairUser (const String& chat_id) {
50- if (iPairs >= N_MAX_PAIRED)
51- iPairs -= N_MAX_PAIRED;
49+ if (iPairs >= N_MAX_PAIRED) iPairs -= N_MAX_PAIRED;
5250 // add to Set of IDs
5351 pairedKeys[iPairs++] = chat_id.c_str ();
5452}
@@ -58,27 +56,22 @@ bool isPaired(const String& chat_id) {
5856 for (const char * i : pairedKeys) {
5957 printRaw (i);
6058 println (F (" , " ));
61- if (chat_id.equals (i))
62- return true ;
59+ if (chat_id.equals (i)) return true ;
6360 }
6461 return false ;
6562}
6663
6764void handleCommand (const String& chat_id, SafeString& cmd, SafeString& param1, SafeString& param2) {
6865 if (cmd == " /pair" ) {
69- if (param1.isEmpty ()) {
70- bot.sendMessage (chat_id, F (" Missing key, I expect \" /pair KEY\" " ));
71- }
66+ if (param1.isEmpty ()) { bot.sendMessage (chat_id, F (" Missing key, I expect \" /pair KEY\" " )); }
7267 if (param1 != pairingKey) {
7368 bot.sendMessage (chat_id, F (" Sorry, that's not my key" ));
7469 return ;
7570 }
7671 pairUser (chat_id);
7772 bot.sendMessage (chat_id, F (" Paired successfully!" ));
7873 } else if (!isPaired (chat_id)) {
79- bot.sendMessage (
80- chat_id,
81- F (" I don't know you yet, let's pair! \n Call /pair KEY with the displayed characters" ));
74+ bot.sendMessage (chat_id, F (" I don't know you yet, let's pair! \n Call /pair KEY with the displayed characters" ));
8275 displayPairingKey ();
8376 return ;
8477 }
@@ -88,9 +81,8 @@ void handleCommand(const String& chat_id, SafeString& cmd, SafeString& param1, S
8881
8982void handleCommand (const telegramMessage& msg) {
9083 if (msg.text .startsWith (" /start" ) || msg.text .startsWith (" /help" )) {
91- bot.sendMessage (
92- msg.chat_id ,
93- F (" Hello there 👋🏼 I'm here to give you easy access to ModischMatrix functions." ));
84+ bot.sendMessage (msg.chat_id ,
85+ F (" Hello there 👋🏼 I'm here to give you easy access to ModischMatrix functions." ));
9486 // probably useless, Telegram offers native command selection now
9587 sendModeKeyboard (msg.chat_id );
9688 return ;
@@ -149,9 +141,7 @@ void setup() {
149141 // secured_client.setInsecure(); // this shouldn't be necessary with active Cert
150142 bot.waitForResponse = 5 * 1000 ;
151143
152- if (!bot.getMe ()) {
153- logWarning (F (" T: Can't find myself!" ));
154- }
144+ if (!bot.getMe ()) { logWarning (F (" T: Can't find myself!" )); }
155145
156146 // pairUser(T_ADMIN_ID);
157147
@@ -161,8 +151,7 @@ void setup() {
161151
162152uint32_t t_last_poll = 0 ;
163153void loop () {
164- if (!ready)
165- return ;
154+ if (!ready) return ;
166155
167156 uint32_t now = millis ();
168157 if (now - t_last_poll > POLL_DELAY) {
0 commit comments