@@ -35,7 +35,7 @@ String UniversalTelegramBot::sendGetToTelegram(String command) {
35
35
bool avail;
36
36
// Connect with api.telegram.org
37
37
if (client->connect (HOST, SSL_PORT)) {
38
- // Serial.println(".... connected to server");
38
+ if (_debug) Serial.println (" .... connected to server" );
39
39
String a=" " ;
40
40
char c;
41
41
int ch_count=0 ;
@@ -53,9 +53,11 @@ String UniversalTelegramBot::sendGetToTelegram(String command) {
53
53
avail=true ;
54
54
}
55
55
if (avail) {
56
- // Serial.println();
57
- // Serial.println(mess);
58
- // Serial.println();
56
+ if (_debug) {
57
+ Serial.println ();
58
+ Serial.println (mess);
59
+ Serial.println ();
60
+ }
59
61
break ;
60
62
}
61
63
}
@@ -102,9 +104,11 @@ String UniversalTelegramBot::sendPostToTelegram(String command, JsonObject& payl
102
104
responseRecieved=true ;
103
105
}
104
106
if (responseRecieved) {
105
- // Serial.println();
106
- // Serial.println(response);
107
- // Serial.println();
107
+ if (_debug) {
108
+ Serial.println ();
109
+ Serial.println (response);
110
+ Serial.println ();
111
+ }
108
112
break ;
109
113
}
110
114
}
@@ -145,14 +149,16 @@ bool UniversalTelegramBot::getMe() {
145
149
146
150
int UniversalTelegramBot::getUpdates (long offset) {
147
151
148
- // Serial.println("GET Update Messages ");
152
+ if (_debug) Serial.println (" GET Update Messages " );
149
153
String command=" bot" +_token+" /getUpdates?offset=" +String (offset)+" &limit=" +String (HANDLE_MESSAGES);
150
154
String response = sendGetToTelegram (command); // recieve reply from telegram.org
151
155
if (response != " " ) {
152
- // Serial.print("incoming message length");
153
- // Serial.println(response.length());
154
- // Serial.print("Creating StaticJsonBuffer of size: ");
155
- // Serial.println(MAX_BUFFER_SIZE);
156
+ if (_debug) {
157
+ Serial.print (" incoming message length" );
158
+ Serial.println (response.length ());
159
+ Serial.print (" Creating StaticJsonBuffer of size: " );
160
+ Serial.println (MAX_BUFFER_SIZE);
161
+ }
156
162
157
163
// Parse response into Json object
158
164
// StaticJsonBuffer<MAX_BUFFER_SIZE> jsonBuffer;
@@ -161,7 +167,7 @@ int UniversalTelegramBot::getUpdates(long offset) {
161
167
162
168
if (root.success ()) {
163
169
// root.printTo(Serial);
164
- // Serial.println();
170
+ if (_debug) Serial.println ();
165
171
if (root.containsKey (" result" )) {
166
172
int resultArrayLength = root[" result" ].size ();
167
173
if (resultArrayLength > 0 ) {
@@ -186,14 +192,14 @@ int UniversalTelegramBot::getUpdates(long offset) {
186
192
}
187
193
return newMessageIndex;
188
194
} else {
189
- // Serial.println("no new messages");
195
+ if (_debug) Serial.println (" no new messages" );
190
196
}
191
197
} else {
192
- Serial.println (" Response contained no 'result'" );
198
+ if (_debug) Serial.println (" Response contained no 'result'" );
193
199
}
194
200
} else {
195
201
// Buffer may not be big enough, increase buffer or reduce max number of messages
196
- Serial.println (" Failed to parse update, the message could be too big for the buffer" );
202
+ if (_debug) Serial.println (" Failed to parse update, the message could be too big for the buffer" );
197
203
}
198
204
199
205
return 0 ;
@@ -207,13 +213,13 @@ int UniversalTelegramBot::getUpdates(long offset) {
207
213
bool UniversalTelegramBot::sendSimpleMessage (String chat_id, String text, String parse_mode) {
208
214
209
215
bool sent=false ;
210
- Serial.println (" SEND Simple Message " );
216
+ if (_debug) Serial.println (" SEND Simple Message " );
211
217
long sttime=millis ();
212
218
if (text!=" " ) {
213
219
while (millis ()<sttime+8000 ) { // loop for a while to send the message
214
220
String command=" bot" +_token+" /sendMessage?chat_id=" +chat_id+" &text=" +text+" &parse_mode=" +parse_mode;
215
221
String response = sendGetToTelegram (command);
216
- // Serial.println(response);
222
+ if (_debug) Serial.println (response);
217
223
sent = checkForOkResponse (response);
218
224
if (sent){
219
225
break ;
@@ -281,13 +287,13 @@ bool UniversalTelegramBot::sendMessageWithReplyKeyboard(String chat_id, String t
281
287
bool UniversalTelegramBot::sendPostMessage (JsonObject& payload) {
282
288
283
289
bool sent=false ;
284
- Serial.println (" SEND Post Message " );
290
+ if (_debug) Serial.println (" SEND Post Message " );
285
291
long sttime=millis ();
286
292
if (payload.containsKey (" text" )) {
287
293
while (millis ()<sttime+8000 ) { // loop for a while to send the message
288
294
String command = " bot" +_token+" /sendMessage" ;
289
295
String response = sendPostToTelegram (command, payload);
290
- // Serial.println(response);
296
+ if (_debug) Serial.println (response);
291
297
sent = checkForOkResponse (response);
292
298
if (sent){
293
299
break ;
0 commit comments