witnessmenow / Universal-Arduino-Telegram-Bot

Use Telegram on your Arduino (ESP8266 or Wifi-101 boards)
MIT License
1.12k stars 307 forks source link

Can't use the Bulk Messages for ESP8266 code! #232

Open Clarathms opened 3 years ago

Clarathms commented 3 years ago

I copied the Bulk Message code the same way it was written, and added the SSID ,password and bot token as it told me to do. But when I tested it, all the bot functions wouldn't work. For example : Even tho there were 2 subscribed users, it just kept saying ´´null´´

I would like to know how to proceed

wirewound commented 2 years ago

I can not solve this in a pretty way but i found that if e new subscribedUsersFile is created serializeJson(users, subscribedUsersFile) writes "null" in the file because getSubscribedUsers() returns null becaus the file is empty yet.

if (usersDoc.isNull())
      {
        users = usersDoc.to<JsonObject>();
      }
      else 
      { 
        users = usersDoc.as<JsonObject>();
      }

This was my workaround for the problem.

SebouhArmenakian commented 2 years ago

wirewound, you saved my days trying to figure out the issue why I always get "null" for "/showallusers".

I added your suggestion in bool addSubscribedUser(String chat_id, String from_name) after serializeJson(users, subscribedUsersFile); and the sketch works like a charm.

Thank you @witnessmenow Brian Lough and @wirewound

I can not solve this in a pretty way but i found that if e new subscribedUsersFile is created serializeJson(users, subscribedUsersFile) writes "null" in the file because getSubscribedUsers() returns null becaus the file is empty yet.

if (usersDoc.isNull())
      {
        users = usersDoc.to<JsonObject>();
      }
      else 
      { 
        users = usersDoc.as<JsonObject>();
      }

This was my workaround for the problem.

SebouhArmenakian commented 2 years ago

Unfortunately for unforeseen reasons the suggestion of @wirewound doesn't work always. Based on his suggestions adding the below by replacing between //users.getOrCreateMember(chat_id, from_name); and subscribedUsersFile.close(); will solve the issue:-

if ((usersDoc.isNull()) && (subscribedUsersFile)) { subscribedUsersFile.print("{\"" + chat_id + "\":" + "\"" + from_name + "\"}" ); } else { serializeJson(users, subscribedUsersFile); users = usersDoc.as(); }