Main Commit

This commit is contained in:
jhartworks
2025-04-22 14:37:58 +02:00
commit e0cdb045f1
5 changed files with 168 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
# discord
Discord websocket Message
+51
View File
@@ -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":
[
]
}
+14
View File
@@ -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"
}
+88
View File
@@ -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";
}
}
?>
+13
View File
@@ -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
}