Main Commit
This commit is contained in:
@@ -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":
|
||||
[
|
||||
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?
|
||||
// Klassendefinition
|
||||
class DiscordMessage extends IPSModule {
|
||||
// Überschreibt die interne IPS_Create($id) Funktion
|
||||
public function Create() {
|
||||
// Diese Zeile nicht löschen.
|
||||
parent::Create();
|
||||
|
||||
$this->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";
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user