Compare commits
10
Commits
7b90432a29
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f15062b3d9 | ||
|
|
12bfae95f3 | ||
|
|
111001b294 | ||
|
|
171eca4c75 | ||
|
|
53b41d01e4 | ||
|
|
cfcb0d5e66 | ||
|
|
e391f2d142 | ||
|
|
683febde0f | ||
|
|
f0a076345d | ||
|
|
771a36fed9 |
+11
-11
@@ -7,9 +7,9 @@
|
|||||||
{ "type": "ValidationTextBox", "name": "WbLang", "caption": "Language Code (de NICHT de_DE)"},
|
{ "type": "ValidationTextBox", "name": "WbLang", "caption": "Language Code (de NICHT de_DE)"},
|
||||||
{
|
{
|
||||||
"type": "List",
|
"type": "List",
|
||||||
"name": "Parameterlist",
|
"name": "Numberlist",
|
||||||
"caption": "Parameter List",
|
"caption": "Reciever List",
|
||||||
"rowCount": 2,
|
"rowCount": 5,
|
||||||
"add": true,
|
"add": true,
|
||||||
"delete": true,
|
"delete": true,
|
||||||
"sort": {
|
"sort": {
|
||||||
@@ -17,32 +17,32 @@
|
|||||||
"direction": "ascending"
|
"direction": "ascending"
|
||||||
},
|
},
|
||||||
"columns": [{
|
"columns": [{
|
||||||
"caption": "Parameter Alias",
|
"caption": "Name",
|
||||||
"name": "ParAlias",
|
"name": "Name",
|
||||||
"width": "auto",
|
"width": "auto",
|
||||||
"add": "",
|
"add": "",
|
||||||
"edit": {
|
"edit": {
|
||||||
"type": "ValidationTextBox"
|
"type": "ValidationTextBox"
|
||||||
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"caption": "Parametername",
|
"caption": "Whatsappnumber",
|
||||||
"name": "ParName",
|
"name": "Number",
|
||||||
"width": "auto",
|
"width": "auto",
|
||||||
"add": "",
|
"add": 20.0,
|
||||||
"edit": {
|
"edit": {
|
||||||
"type": "ValidationTextBox"
|
"type": "ValidationTextBox"
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
"values": [{
|
"values": [{
|
||||||
"ParAlias": "New Parameter",
|
"Name": "Hans Maier Müller der Echte",
|
||||||
"ParName": "pn"
|
"Number": "49150815123456"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
],
|
],
|
||||||
"actions":
|
"actions":
|
||||||
[
|
[
|
||||||
{ "type": "Button", "label": "Send Message", "onClick": "WBM_SendMessage($id, $Params);" }
|
|
||||||
],
|
],
|
||||||
"status":
|
"status":
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class WhatsappMessage extends IPSModule {
|
|||||||
$this->RegisterPropertyString("WbAppId","");
|
$this->RegisterPropertyString("WbAppId","");
|
||||||
$this->RegisterPropertyString("WbTemplate","stoerung");
|
$this->RegisterPropertyString("WbTemplate","stoerung");
|
||||||
$this->RegisterPropertyString("WbLang","de");
|
$this->RegisterPropertyString("WbLang","de");
|
||||||
$this->RegisterPropertyString("Parameterlist","");
|
$this->RegisterPropertyString("Numberlist","");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Überschreibt die intere IPS_ApplyChanges($id) Funktion
|
// Überschreibt die intere IPS_ApplyChanges($id) Funktion
|
||||||
@@ -25,7 +25,24 @@ class WhatsappMessage extends IPSModule {
|
|||||||
* DWM_SendMessage($id);
|
* DWM_SendMessage($id);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function SendMessage($topic,$recip, array $paramvals) {
|
|
||||||
|
|
||||||
|
private function normalizePhoneNumber($number) {
|
||||||
|
// 1. Entferne führendes + oder 0
|
||||||
|
$number = ltrim($number, '+');
|
||||||
|
if (strpos($number, '0') === 0) {
|
||||||
|
$number = substr($number, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Wenn keine 49 am Anfang steht, füge sie hinzu
|
||||||
|
if (strpos($number, '49') !== 0) {
|
||||||
|
$number = '49' . $number;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SendMessageEx(string $recip, array $paramvals) {
|
||||||
|
|
||||||
$token = $this->ReadPropertyString("WbToken");
|
$token = $this->ReadPropertyString("WbToken");
|
||||||
$appId = $this->ReadPropertyString("WbAppId");
|
$appId = $this->ReadPropertyString("WbAppId");
|
||||||
@@ -37,10 +54,7 @@ class WhatsappMessage extends IPSModule {
|
|||||||
|
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
|
|
||||||
for ($i = 0; $i < count($paramarr); $i++) {
|
foreach ($paramvals as $paramName => $paramValue) {
|
||||||
$paramName = $paramarr[$i]['ParName'];
|
|
||||||
$paramValue = isset($paramvals[$i]) ? $paramvals[$i] : '';
|
|
||||||
|
|
||||||
$parameters[] = [
|
$parameters[] = [
|
||||||
"type" => "text",
|
"type" => "text",
|
||||||
"parameter_name" => $paramName,
|
"parameter_name" => $paramName,
|
||||||
@@ -48,6 +62,10 @@ class WhatsappMessage extends IPSModule {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//print_r($parameters);
|
||||||
|
|
||||||
|
$recip = $this->normalizePhoneNumber($recip);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
"messaging_product" => "whatsapp",
|
"messaging_product" => "whatsapp",
|
||||||
"to" => $recip,
|
"to" => $recip,
|
||||||
@@ -55,7 +73,7 @@ class WhatsappMessage extends IPSModule {
|
|||||||
"template" => [
|
"template" => [
|
||||||
"name" => $template,
|
"name" => $template,
|
||||||
"language" => [
|
"language" => [
|
||||||
"code" => lang
|
"code" => $lang
|
||||||
],
|
],
|
||||||
"components" => [
|
"components" => [
|
||||||
[
|
[
|
||||||
@@ -66,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');
|
$ch = curl_init('https://graph.facebook.com/v22.0/'.$appId.'/messages');
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
@@ -80,9 +98,31 @@ class WhatsappMessage extends IPSModule {
|
|||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
return $this->isMessageAccepted($response);
|
||||||
|
// echo "HTTP-Code: $httpcode\nAntwort: $response\n";
|
||||||
|
|
||||||
echo "HTTP-Code: $httpcode\nAntwort: $response\n";
|
}
|
||||||
|
public function SendMessage(array $paramvals) {
|
||||||
|
|
||||||
|
$arrnumbers = $this->ReadPropertyString("Numberlist");
|
||||||
|
$entries = json_decode($arrnumbers, true);
|
||||||
|
|
||||||
|
foreach ($entries as $entry){
|
||||||
|
$number = $entry['Number'];
|
||||||
|
$this->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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
+2
-2
@@ -7,7 +7,7 @@
|
|||||||
"version": "6.0",
|
"version": "6.0",
|
||||||
"date": 1491343200
|
"date": 1491343200
|
||||||
},
|
},
|
||||||
"version": "1.0",
|
"version": "1.2",
|
||||||
"build": 2,
|
"build": 0,
|
||||||
"date": 0
|
"date": 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user