commit e0cdb045f160d1c2f880ddf3d524ee44713a63c0 Author: jhartworks Date: Tue Apr 22 14:37:58 2025 +0200 Main Commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..912a83a --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# discord +Discord websocket Message diff --git a/Whatsapp Message/form.json b/Whatsapp Message/form.json new file mode 100644 index 0000000..84f3edc --- /dev/null +++ b/Whatsapp Message/form.json @@ -0,0 +1,51 @@ +{ + "elements": + [ + { "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": "List", + "name": "Parameterlist", + "caption": "Parameter List", + "rowCount": 2, + "add": true, + "delete": true, + "sort": { + "column": "Name", + "direction": "ascending" + }, + "columns": [{ + "caption": "Parameter Alias", + "name": "ParAlias", + "width": "auto", + "add": "", + "edit": { + "type": "ValidationTextBox" + } + }, { + "caption": "Parametername", + "name": "ParName", + "width": "auto", + "add": "", + "edit": { + "type": "ValidationTextBox" + } + }], + "values": [{ + "ParAlias": "New Parameter", + "ParName": "pn" + }] + } + + ], + "actions": + [ + { "type": "Button", "label": "Send Message", "onClick": "WBM_SendMessage($id, $Params);" } + ], + "status": + [ + + ] +} \ No newline at end of file diff --git a/Whatsapp Message/module.json b/Whatsapp Message/module.json new file mode 100644 index 0000000..9ca49f0 --- /dev/null +++ b/Whatsapp Message/module.json @@ -0,0 +1,14 @@ +{ + "id": "{F5B46BA7-5F72-3AC4-5BBA-D2B111679F91}", + "name": "Whatsapp Message", + "type": 3, + "vendor": "Meta, Whatsapp", + "aliases": + [ + ], + "url": "https://developers.facebook.com/", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "WBM" +} \ No newline at end of file diff --git a/Whatsapp Message/module.php b/Whatsapp Message/module.php new file mode 100644 index 0000000..2c84aa8 --- /dev/null +++ b/Whatsapp Message/module.php @@ -0,0 +1,88 @@ +RegisterPropertyString("WbToken",""); + $this->RegisterPropertyString("WbAppId",""); + $this->RegisterPropertyString("WbTemplate","stoerung"); + $this->RegisterPropertyString("WbLang","de"); + $this->RegisterPropertyString("Parameterlist",""); + } + + // Überschreibt die intere IPS_ApplyChanges($id) Funktion + public function ApplyChanges() { + // Diese Zeile nicht löschen + parent::ApplyChanges(); + } + /** + * Die folgenden Funktionen stehen automatisch zur Verfügung, wenn das Modul über die "Module Control" eingefügt wurden. + * Die Funktionen werden, mit dem selbst eingerichteten Prefix, in PHP und JSON-RPC wiefolgt zur Verfügung gestellt: + * + * DWM_SendMessage($id); + * + */ + public function SendMessage($topic,$recip, array $paramvals) { + + $token = $this->ReadPropertyString("WbToken"); + $appId = $this->ReadPropertyString("WbAppId"); + $template = $this->ReadPropertyString("WbTemplate"); + $lang = $this->ReadPropertyString("WbLang"); + + $arrString = $this->ReadPropertyString("Parameterlist"); + $paramarr= json_decode($arrString, true); + + $parameters = []; + + for ($i = 0; $i < count($paramarr); $i++) { + $paramName = $paramarr[$i]['ParName']; + $paramValue = isset($paramvals[$i]) ? $paramvals[$i] : ''; + + $parameters[] = [ + "type" => "text", + "parameter_name" => $paramName, + "text" => $paramValue + ]; + } + + $data = [ + "messaging_product" => "whatsapp", + "to" => $recip, + "type" => "template", + "template" => [ + "name" => $template, + "language" => [ + "code" => lang + ], + "components" => [ + [ + "type" => "body", + "parameters" => $parameters + ] + ] + ] + ]; + + 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); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Authorization: Bearer ' . $token, + 'Content-Type: application/json' + ]); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + + $response = curl_exec($ch); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + echo "HTTP-Code: $httpcode\nAntwort: $response\n"; + + } +} +?> \ No newline at end of file diff --git a/library.json b/library.json new file mode 100644 index 0000000..89a9a52 --- /dev/null +++ b/library.json @@ -0,0 +1,13 @@ +{ + "id": "{881D977F-3E7F-7142-1F4B-3974E8AEFB61}", + "author": "J.H. Artworks", + "name": "WhatsApp Business", + "url": "https://jh-artworks.com", + "compatibility": { + "version": "6.0", + "date": 1491343200 + }, + "version": "1.0", + "build": 1, + "date": 0 +} \ No newline at end of file