@@ -74,6 +74,10 @@ extern "C" {
74
74
#define LINESERVER " notify-api.line.me"
75
75
#define LINEPORT 443
76
76
77
+ #define WHATSAPPTIMEOUT 5000
78
+ #define WHATSAPPSERVER " api.callmebot.com"
79
+ #define WHATSAPPPORT 443
80
+
77
81
#define TELEGRAMTIMEOUT 5000
78
82
#define TELEGRAMSERVER " api.telegram.org"
79
83
#define TELEGRAMPORT 443
@@ -166,6 +170,8 @@ const char* NotificationsService::getTypeString() {
166
170
return " telegram" ;
167
171
case ESP_IFTTT_NOTIFICATION:
168
172
return " IFTTT" ;
173
+ case ESP_WHATS_APP_NOTIFICATION:
174
+ return " WhatsApp" ;
169
175
case ESP_HOMEASSISTANT_NOTIFICATION:
170
176
return " HomeAssistant" ;
171
177
default :
@@ -209,6 +215,9 @@ bool NotificationsService::sendMSG(const char* title, const char* messagetxt) {
209
215
case ESP_IFTTT_NOTIFICATION:
210
216
return sendIFTTTMSG (title, message.c_str ());
211
217
break ;
218
+ case ESP_WHATS_APP_NOTIFICATION:
219
+ return sendWhatsAppMSG (title, message.c_str ());
220
+ break ;
212
221
case ESP_HOMEASSISTANT_NOTIFICATION:
213
222
return sendHomeAssistantMSG (title, message.c_str ());
214
223
break ;
@@ -267,6 +276,48 @@ bool NotificationsService::sendPushoverMSG(const char* title,
267
276
return res;
268
277
}
269
278
279
+ // WhatsApp / CallMeBot
280
+ bool NotificationsService::sendWhatsAppMSG (const char * title,
281
+ const char * message) {
282
+ String data;
283
+ String geturl;
284
+ bool res;
285
+ #pragma GCC diagnostic push
286
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
287
+ WiFiClientSecure Notificationclient;
288
+ #pragma GCC diagnostic pop
289
+ Notificationclient.setInsecure ();
290
+ #if defined(ARDUINO_ARCH_ESP8266)
291
+ BearSSLSetup (Notificationclient);
292
+ #endif // ARDUINO_ARCH_ESP8266
293
+ if (!Notificationclient.connect (_serveraddress.c_str (), _port)) {
294
+ esp3d_log_e (" Error connecting server %s:%d" , _serveraddress.c_str (),
295
+ _port);
296
+ return false ;
297
+ }
298
+ // build data for post
299
+ data = " /whatsapp.php?phone=" ;
300
+ data += _token1;
301
+ data += " &apikey=" ;
302
+ data += _token2;
303
+ data += " &text=" ;
304
+ data += esp3d_string::urlEncode (message);
305
+ // build get query because it only accept GET
306
+ geturl =
307
+ " GET https://" + _serveraddress;
308
+ geturl+= data;
309
+ geturl+=" HTTP/1.0" ;
310
+ Notificationclient.println (geturl.c_str ());
311
+ Notificationclient.println (" Host: api.callmebot.com" );
312
+ Notificationclient.println (" Connection: close" );
313
+ Notificationclient.println ();
314
+ esp3d_log (" Query: %s" , geturl.c_str ());
315
+ // send query
316
+ res = Wait4Answer (Notificationclient, " <b>" , " Message queued." , WHATSAPPTIMEOUT);
317
+ Notificationclient.stop ();
318
+ return res;
319
+ }
320
+
270
321
// Telegram
271
322
// TODO: put error in variable to allow better error handling
272
323
bool NotificationsService::sendTelegramMSG (const char * title,
@@ -637,6 +688,12 @@ bool NotificationsService::begin() {
637
688
_port = LINEPORT;
638
689
_serveraddress = LINESERVER;
639
690
break ;
691
+ case ESP_WHATS_APP_NOTIFICATION:
692
+ _token1 = ESP3DSettings::readString (ESP_NOTIFICATION_TOKEN1);
693
+ _token2 = ESP3DSettings::readString (ESP_NOTIFICATION_TOKEN2);
694
+ _port = WHATSAPPPORT;
695
+ _serveraddress = WHATSAPPSERVER;
696
+ break ;
640
697
case ESP_IFTTT_NOTIFICATION:
641
698
_token1 = ESP3DSettings::readString (ESP_NOTIFICATION_TOKEN1);
642
699
_token2 = ESP3DSettings::readString (ESP_NOTIFICATION_TOKEN2);
0 commit comments