Skip to content

Commit 6be1e70

Browse files
committed
Deserializing JSon instead of that string search. we'll use the JSon to access the
1 parent 4f54ee3 commit 6be1e70

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,16 +763,10 @@ String UniversalTelegramBot::sendPhoto(String chat_id, String photo,
763763
}
764764

765765
bool UniversalTelegramBot::checkForOkResponse(String response) {
766-
int responseLength = response.length();
766+
DynamicJsonDocument doc(response.length());
767+
deserializeJson(doc, response);
767768

768-
for (int m = 5; m < responseLength + 1; m++) {
769-
if (response.substring(m - 10, m) ==
770-
"{\"ok\":true") { // Chek if message has been properly sent
771-
return true;
772-
}
773-
}
774-
775-
return false;
769+
return doc["ok"] | false; // default is false, but this is more explicit and clear
776770
}
777771

778772
bool UniversalTelegramBot::sendChatAction(String chat_id, String text) {

0 commit comments

Comments
 (0)