diff --git a/Whatsapp Message/form.json b/Whatsapp Message/form.json index 8588e08..f51f1f2 100644 --- a/Whatsapp Message/form.json +++ b/Whatsapp Message/form.json @@ -4,8 +4,41 @@ { "type": "ValidationTextBox", "name": "WbToken", "caption": "Token" }, { "type": "ValidationTextBox", "name": "WbAppId", "caption": "App ID"}, { "type": "ValidationTextBox", "name": "WbTemplate", "caption": "Templatename"}, - { "type": "ValidationTextBox", "name": "WbLang", "caption": "Language Code (de NICHT de_DE)"} + { "type": "ValidationTextBox", "name": "WbLang", "caption": "Language Code (de NICHT de_DE)"}, + { + "type": "List", + "name": "Numberlist", + "caption": "Reciever List", + "rowCount": 5, + "add": true, + "delete": true, + "sort": { + "column": "Name", + "direction": "ascending" + }, + "columns": [{ + "caption": "Name", + "name": "Name", + "width": "auto", + "add": "", + "edit": { + "type": "ValidationTextBox" + } + }, { + "caption": "Whatsappnumber", + "name": "Number", + "width": "75px", + "add": 20.0, + "edit": { + "type": "ValidationTextBox" + } + }], + "values": [{ + "Name": "Hans Maier Müller der Echte", + "Number": "49150815123456" + }] + } ], "actions": diff --git a/Whatsapp Message/module.php b/Whatsapp Message/module.php index 390989b..933e23d 100644 --- a/Whatsapp Message/module.php +++ b/Whatsapp Message/module.php @@ -10,7 +10,7 @@ class WhatsappMessage extends IPSModule { $this->RegisterPropertyString("WbAppId",""); $this->RegisterPropertyString("WbTemplate","stoerung"); $this->RegisterPropertyString("WbLang","de"); - $this->RegisterPropertyString("Parameterlist",""); + $this->RegisterPropertyString("Numberlist",""); } // Überschreibt die intere IPS_ApplyChanges($id) Funktion @@ -41,8 +41,8 @@ class WhatsappMessage extends IPSModule { return $number; } - - public function SendMessage(string $recip, array $paramvals) { + + public function SendMessageEx(string $recip, array $paramvals) { $token = $this->ReadPropertyString("WbToken"); $appId = $this->ReadPropertyString("WbAppId"); @@ -84,7 +84,7 @@ class WhatsappMessage extends IPSModule { ] ]; - echo "JSON:\n" . json_encode($data, JSON_PRETTY_PRINT) . "\n\n"; + //echo "JSON:\n" . json_encode($data, JSON_PRETTY_PRINT) . "\n\n"; $ch = curl_init('https://graph.facebook.com/v22.0/'.$appId.'/messages'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -98,9 +98,31 @@ class WhatsappMessage extends IPSModule { $response = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); - + return isMessageAccepted($response); // echo "HTTP-Code: $httpcode\nAntwort: $response\n"; } + private function SendMessage(array $paramvals) { + + $arrnumbers = $this->ReadPropertyString("Numberlist"); + $entries = json_decode($arrnumbers, true); + + foreach ($entries as $entry){ + $number = $entry['Number']; + SendMessageEx($number[], $paramvals); + } + + } + private function isMessageAccepted($jsonResponse) { + $data = json_decode($jsonResponse, true); + + // message_status MUSS vorhanden und accepted sein + if (isset($data['messages'][0]['message_status']) && $data['messages'][0]['message_status'] === 'accepted') { + return true; + } + + // Wenn message_status fehlt oder nicht "accepted" ist → false + return false; + } } ?> \ No newline at end of file diff --git a/library.json b/library.json index 69c7874..986ed24 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "version": "6.0", "date": 1491343200 }, - "version": "1.0", + "version": "1.1", "build": 5, "date": 0 } \ No newline at end of file