iobroker.gotify-ws 0.1.13 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -52
- package/build/main.js +370 -0
- package/build/main.js.map +7 -0
- package/io-package.json +14 -14
- package/package.json +40 -7
- package/lib/adapter-config.d.ts +0 -19
- package/main.js +0 -440
package/README.md
CHANGED
|
@@ -39,14 +39,14 @@ Gotify-WS receives messages and forwards them to a notification service supporte
|
|
|
39
39
|
|
|
40
40
|
Spotify-WS currently supports the following notification services
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
* e-mail
|
|
43
|
+
* Matrix
|
|
44
|
+
* Notification-Manager
|
|
45
|
+
* Pushover
|
|
46
|
+
* Discord
|
|
47
|
+
* Signal
|
|
48
|
+
* Telegram
|
|
49
|
+
* Whatsapp
|
|
50
50
|
|
|
51
51
|
---
|
|
52
52
|
|
|
@@ -67,79 +67,67 @@ You can then configure a notification service of your choice for forwarding.
|
|
|
67
67
|
## Changelog
|
|
68
68
|
|
|
69
69
|
<!-- ### **WORK IN PROGRESS** -->
|
|
70
|
-
### 0.
|
|
70
|
+
### 0.2.0 (2025-04-22)
|
|
71
|
+
* (simatec) Adapter rewritten in Typescript
|
|
71
72
|
|
|
72
|
-
-
|
|
73
|
-
|
|
73
|
+
### 0.1.13 (2025-04-16)
|
|
74
|
+
* (simatec) Dependencies updated
|
|
75
|
+
* (simatec) migrated to json5
|
|
74
76
|
|
|
75
77
|
### 0.1.12 (2025-02-22)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
- (simatec) small fix
|
|
78
|
+
* (simatec) Dependencies updated
|
|
79
|
+
* (simatec) small fix
|
|
79
80
|
|
|
80
81
|
### 0.1.11 (2025-01-09)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
- (simatec) Update License
|
|
82
|
+
* (simatec) eslint-config fix
|
|
83
|
+
* (simatec) Code fix
|
|
84
|
+
* (simatec) Dependencies updated
|
|
85
|
+
* (simatec) Update License
|
|
86
86
|
|
|
87
87
|
### 0.1.10 (2024-11-24)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
- (simatec) eslint-config added
|
|
88
|
+
* (simatec) Dependencies updated
|
|
89
|
+
* (simatec) Responsive Design fix
|
|
90
|
+
* (simatec) Issue Action added
|
|
91
|
+
* (simatec) eslint-config added
|
|
93
92
|
|
|
94
93
|
### 0.1.9 (2024-09-26)
|
|
95
|
-
|
|
96
|
-
- (simatec) Fix for admin 7.1.5
|
|
94
|
+
* (simatec) Fix for admin 7.1.5
|
|
97
95
|
|
|
98
96
|
### 0.1.8 (2024-09-24)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
- (simatec) Cleaned code
|
|
97
|
+
* (simatec) Responsive Design fix
|
|
98
|
+
* (simatec) Cleaned code
|
|
102
99
|
|
|
103
100
|
### 0.1.7 (2024-09-16)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
- (simatec) Responsive Design fix
|
|
101
|
+
* (simatec) Dependencies updated
|
|
102
|
+
* (simatec) Responsive Design fix
|
|
107
103
|
|
|
108
104
|
### 0.1.6 (2024-09-10)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
- (simatec) Responsive Design added
|
|
105
|
+
* (simatec) Fix Adapter Check
|
|
106
|
+
* (simatec) Dependencies updated
|
|
107
|
+
* (simatec) Responsive Design added
|
|
113
108
|
|
|
114
109
|
### 0.1.5 (2024-07-22)
|
|
115
|
-
|
|
116
|
-
- (simatec) small fix
|
|
110
|
+
* (simatec) small fix
|
|
117
111
|
|
|
118
112
|
### 0.1.4 (2024-07-19)
|
|
119
|
-
|
|
120
|
-
- (simatec) Dependencies updated
|
|
113
|
+
* (simatec) Dependencies updated
|
|
121
114
|
|
|
122
115
|
### 0.1.3 (2024-07-17)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
- (simatec) Fix Timeout
|
|
116
|
+
* (simatec) Fix Test & Release
|
|
117
|
+
* (simatec) Fix Timeout
|
|
126
118
|
|
|
127
119
|
### 0.1.2 (2024-06-26)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
- (simatec) Notification-Manager added
|
|
120
|
+
* (simatec) Fix io-package
|
|
121
|
+
* (simatec) Notification-Manager added
|
|
131
122
|
|
|
132
123
|
### 0.1.1 (2024-06-19)
|
|
133
|
-
|
|
134
|
-
- (simatec) Fix Branch
|
|
124
|
+
* (simatec) Fix Branch
|
|
135
125
|
|
|
136
126
|
### 0.1.0 (2024-06-19)
|
|
137
|
-
|
|
138
|
-
- (simatec) First Release
|
|
127
|
+
* (simatec) First Release
|
|
139
128
|
|
|
140
129
|
### 0.0.1 (2024-03-15)
|
|
141
|
-
|
|
142
|
-
- (simatec) initial release
|
|
130
|
+
* (simatec) initial release
|
|
143
131
|
|
|
144
132
|
---
|
|
145
133
|
|
package/build/main.js
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_ws = __toESM(require("ws"));
|
|
25
|
+
var utils = __toESM(require("@iobroker/adapter-core"));
|
|
26
|
+
class GotifyWs extends utils.Adapter {
|
|
27
|
+
systemLang = "de";
|
|
28
|
+
ws;
|
|
29
|
+
timer = void 0;
|
|
30
|
+
stopNow = false;
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
super({
|
|
33
|
+
...options,
|
|
34
|
+
name: "gotify-ws"
|
|
35
|
+
});
|
|
36
|
+
this.on("ready", this.onReady.bind(this));
|
|
37
|
+
this.on("unload", this.onUnload.bind(this));
|
|
38
|
+
}
|
|
39
|
+
async onReady() {
|
|
40
|
+
const sysLang = await this.getForeignObjectAsync("system.config");
|
|
41
|
+
if (sysLang && sysLang.common && sysLang.common.language) {
|
|
42
|
+
this.systemLang = sysLang.common.language;
|
|
43
|
+
}
|
|
44
|
+
await this.setState("info.connection", false, true);
|
|
45
|
+
this.connectWebSocket();
|
|
46
|
+
}
|
|
47
|
+
async onUnload(callback) {
|
|
48
|
+
await this.setState("info.connection", false, true);
|
|
49
|
+
try {
|
|
50
|
+
if (this.ws) {
|
|
51
|
+
this.stopNow = true;
|
|
52
|
+
this.ws.close();
|
|
53
|
+
this.ws.terminate();
|
|
54
|
+
this.clearTimeout(this.timer);
|
|
55
|
+
this.timer = null;
|
|
56
|
+
}
|
|
57
|
+
callback();
|
|
58
|
+
} catch (e) {
|
|
59
|
+
callback();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async onMessage(obj) {
|
|
63
|
+
switch (obj == null ? void 0 : obj.command) {
|
|
64
|
+
case "sendToInstance":
|
|
65
|
+
if (obj && obj.command === "sendToInstance" && obj.message && obj.message.type) {
|
|
66
|
+
const resultInstances = [];
|
|
67
|
+
const instances = await this.getObjectViewAsync("system", "instance", {
|
|
68
|
+
startkey: `system.adapter.${obj.message.type}.`,
|
|
69
|
+
endkey: `system.adapter.${obj.message.type}.\u9999`
|
|
70
|
+
}).catch((err) => this.log.error(err));
|
|
71
|
+
if (instances && instances.rows && instances.rows.length != 0) {
|
|
72
|
+
instances.rows.forEach((row) => {
|
|
73
|
+
resultInstances.push({
|
|
74
|
+
label: row.id.replace("system.adapter.", ""),
|
|
75
|
+
value: row.id.replace("system.adapter.", "")
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
resultInstances.push({
|
|
80
|
+
label: this._("none", this.systemLang),
|
|
81
|
+
value: "none"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
this.log.debug(`sendToInstance - ${JSON.stringify(obj)}`);
|
|
85
|
+
this.sendTo(obj.from, obj.command, resultInstances, obj.callback);
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case "sendToTelegramUser": {
|
|
89
|
+
let useUsername = false;
|
|
90
|
+
if (obj && obj.command === "sendToTelegramUser" && obj.message && obj.message.instance) {
|
|
91
|
+
const inst = obj.message.instance ? obj.message.instance : this.config.telegramInstance;
|
|
92
|
+
const userList = await this.getForeignStateAsync(`${inst}.communicate.users`);
|
|
93
|
+
const configTelegram = await this.getForeignObjectAsync(`system.adapter.${inst}`);
|
|
94
|
+
if (configTelegram && configTelegram.native) {
|
|
95
|
+
const native = configTelegram.native;
|
|
96
|
+
useUsername = native.useUsername;
|
|
97
|
+
}
|
|
98
|
+
const resultUser = [{ label: this._("All Receiver", this.systemLang), value: "allTelegramUsers" }];
|
|
99
|
+
if (userList && (userList == null ? void 0 : userList.val)) {
|
|
100
|
+
const users = JSON.parse(userList == null ? void 0 : userList.val);
|
|
101
|
+
for (const i in users) {
|
|
102
|
+
resultUser.push({
|
|
103
|
+
label: useUsername === true ? users[i].userName : users[i].firstName,
|
|
104
|
+
value: useUsername === true ? users[i].userName : users[i].firstName
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
this.sendTo(obj.from, obj.command, resultUser, obj.callback);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
this.log.error(`Cannot parse stored user IDs from Telegram: ${err}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case "sendToDiscordTarget":
|
|
117
|
+
if (obj && obj.command === "sendToDiscordTarget" && obj.message && obj.message.instance) {
|
|
118
|
+
const resultTarget = [{ label: this._("none", this.systemLang), value: "none" }];
|
|
119
|
+
const targetList = await this.sendToAsync(obj.message.instance, "getNotificationTargets", {});
|
|
120
|
+
if (Array.isArray(targetList)) {
|
|
121
|
+
for (const i in targetList) {
|
|
122
|
+
resultTarget.push({
|
|
123
|
+
label: targetList[i].value,
|
|
124
|
+
value: targetList[i].value
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
this.sendTo(obj.from, obj.command, resultTarget, obj.callback);
|
|
130
|
+
} catch (err) {
|
|
131
|
+
this.log.error(`Cannot parse stored user IDs from Discord: ${err}`);
|
|
132
|
+
}
|
|
133
|
+
} else if (obj && obj.command === "sendToDiscordTarget") {
|
|
134
|
+
const resultTarget = [{ label: this._("none", this.systemLang), value: "none" }];
|
|
135
|
+
try {
|
|
136
|
+
this.sendTo(obj.from, obj.command, resultTarget, obj.callback);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
this.log.error(`Cannot parse stored user IDs from Discord: ${err}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
connectWebSocket() {
|
|
145
|
+
if (this.config.ip && this.config.port) {
|
|
146
|
+
const uri = `ws://${this.config.ip}:${this.config.port}/stream`;
|
|
147
|
+
this.ws = new import_ws.default(uri, {
|
|
148
|
+
headers: {
|
|
149
|
+
"X-Gotify-Key": this.config.token
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
this.ws.on("open", async () => {
|
|
153
|
+
await this.setState("info.connection", true, true);
|
|
154
|
+
this.log.info("WebSocket connected");
|
|
155
|
+
});
|
|
156
|
+
this.ws.on("message", async (data) => {
|
|
157
|
+
const line = JSON.parse(data.toString("utf-8"));
|
|
158
|
+
await this.pushMessage(line);
|
|
159
|
+
});
|
|
160
|
+
this.ws.on("close", async () => {
|
|
161
|
+
await this.setState("info.connection", false, true);
|
|
162
|
+
this.log.info("WebSocket closed");
|
|
163
|
+
if (this.stopNow === false) {
|
|
164
|
+
this.timer = this.setTimeout(this.connectWebSocket, 5e3);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
this.ws.on("error", async (err) => {
|
|
168
|
+
await this.setState("info.connection", false, true);
|
|
169
|
+
this.log.error(`WebSocket error: ${err}`);
|
|
170
|
+
});
|
|
171
|
+
} else {
|
|
172
|
+
this.log.error("WebSocket error: Please check your Configuration");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async pushMessage(line) {
|
|
176
|
+
if (this.config.notificationType) {
|
|
177
|
+
switch (this.config.notificationType) {
|
|
178
|
+
case "telegram":
|
|
179
|
+
if (this.config.telegramUser && this.config.telegramUser === "allTelegramUsers" && this.config.telegramInstance) {
|
|
180
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
181
|
+
const title = line.title != "" ? `<b>${line.title.replace(/[`]/g, "")}</b>` : "<b>Gotifi WS Message</b>";
|
|
182
|
+
try {
|
|
183
|
+
await this.sendToAsync(this.config.telegramInstance, "send", {
|
|
184
|
+
parse_mode: "HTML",
|
|
185
|
+
text: `${title != "" ? `${title}
|
|
186
|
+
` : ""}${formatMessage}`
|
|
187
|
+
});
|
|
188
|
+
} catch (err) {
|
|
189
|
+
this.log.warn(`Error sending Telegram message: ${err}`);
|
|
190
|
+
}
|
|
191
|
+
} else if (this.config.telegramUser && this.config.telegramUser != "allTelegramUsers" && this.config.telegramInstance) {
|
|
192
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
193
|
+
const title = line.title != "" ? `<b>${line.title.replace(/[`]/g, "")}</b>` : "<b>Gotifi WS Message</b>";
|
|
194
|
+
try {
|
|
195
|
+
await this.sendToAsync(this.config.telegramInstance, "send", {
|
|
196
|
+
user: this.config.telegramUser,
|
|
197
|
+
parse_mode: "HTML",
|
|
198
|
+
text: `${title != "" ? `${title}
|
|
199
|
+
` : ""}${formatMessage}`
|
|
200
|
+
});
|
|
201
|
+
} catch (err) {
|
|
202
|
+
this.log.warn(`Error sending Telegram message: ${err}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
case "email":
|
|
207
|
+
if (this.config.emailInstance && this.config.emailReceiver && this.config.emailSender) {
|
|
208
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
209
|
+
const title = line.title != "" ? line.title.replace(/[`]/g, "") : "Gotifi WS Message";
|
|
210
|
+
try {
|
|
211
|
+
await this.sendToAsync(this.config.emailInstance, "send", {
|
|
212
|
+
text: formatMessage,
|
|
213
|
+
to: this.config.emailReceiver,
|
|
214
|
+
subject: title,
|
|
215
|
+
from: this.config.emailSender
|
|
216
|
+
});
|
|
217
|
+
} catch (err) {
|
|
218
|
+
this.log.warn(`Error sending E-Mail message: ${err}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
case "pushover":
|
|
223
|
+
if (this.config.pushoverSilentNotice === true && this.config.pushoverInstance && this.config.pushoverDeviceID) {
|
|
224
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
225
|
+
const title = line.title != "" ? `<b>${line.title.replace(/[`]/g, "")}</b>` : "<b>Gotifi WS Message</b>";
|
|
226
|
+
try {
|
|
227
|
+
await this.sendToAsync(this.config.pushoverInstance, "send", {
|
|
228
|
+
message: `${title != "" ? `${title}
|
|
229
|
+
` : ""}${formatMessage}`,
|
|
230
|
+
sound: "",
|
|
231
|
+
priority: -1,
|
|
232
|
+
title,
|
|
233
|
+
device: this.config.pushoverDeviceID,
|
|
234
|
+
html: 1
|
|
235
|
+
});
|
|
236
|
+
} catch (err) {
|
|
237
|
+
this.log.warn(`Error sending Pushover message: ${err}`);
|
|
238
|
+
}
|
|
239
|
+
} else if (this.config.pushoverInstance && this.config.pushoverDeviceID) {
|
|
240
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
241
|
+
const title = line.title != "" ? `<b>${line.title.replace(/[`]/g, "")}</b>` : "<b>Gotifi WS Message</b>";
|
|
242
|
+
try {
|
|
243
|
+
await this.sendToAsync(this.config.pushoverInstance, "send", {
|
|
244
|
+
message: `${title != "" ? `${title}
|
|
245
|
+
` : ""}${formatMessage}`,
|
|
246
|
+
sound: "",
|
|
247
|
+
title,
|
|
248
|
+
device: this.config.pushoverDeviceID,
|
|
249
|
+
html: 1
|
|
250
|
+
});
|
|
251
|
+
} catch (err) {
|
|
252
|
+
this.log.warn(`Error sending Pushover message: ${err}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
case "whatsapp-cmb":
|
|
257
|
+
if (this.config.whatsappInstance) {
|
|
258
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
259
|
+
const title = line.title != "" ? `*${line.title.replace(/[`]/g, "")}*` : "*Gotifi WS Message*";
|
|
260
|
+
try {
|
|
261
|
+
await this.sendToAsync(this.config.whatsappInstance, "send", {
|
|
262
|
+
text: `${title != "" ? `${title}
|
|
263
|
+
` : ""}${formatMessage}`
|
|
264
|
+
});
|
|
265
|
+
} catch (err) {
|
|
266
|
+
this.log.warn(`Error sending WhatsApp message: ${err}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
break;
|
|
270
|
+
case "notification-manager":
|
|
271
|
+
if (this.config.notificationManagerInstance) {
|
|
272
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
273
|
+
const title = line.title != "" ? `<b>${line.title.replace(/[`]/g, "")}</b>` : "<b>Gotifi WS Message</b>";
|
|
274
|
+
try {
|
|
275
|
+
await this.sendToAsync(
|
|
276
|
+
this.config.notificationManagerInstance,
|
|
277
|
+
"registerUserNotification",
|
|
278
|
+
{
|
|
279
|
+
category: "notify",
|
|
280
|
+
message: `${title != "" ? `${title}
|
|
281
|
+
` : ""}${formatMessage}`
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
} catch (err) {
|
|
285
|
+
this.log.warn(`Error sending Notification-Manager message: ${err}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
break;
|
|
289
|
+
case "signal-cmb":
|
|
290
|
+
if (this.config.signalInstance) {
|
|
291
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
292
|
+
const title = line.title != "" ? line.title.replace(/[`]/g, "") : "Gotifi WS Message";
|
|
293
|
+
try {
|
|
294
|
+
await this.sendToAsync(this.config.signalInstance, "send", {
|
|
295
|
+
text: `${title != "" ? `${title}
|
|
296
|
+
` : ""}${formatMessage}`
|
|
297
|
+
});
|
|
298
|
+
} catch (err) {
|
|
299
|
+
this.log.warn(`Error sending Signal message: ${err}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
case "matrix-org":
|
|
304
|
+
if (this.config.matrixInstance) {
|
|
305
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
306
|
+
const title = line.title != "" ? `<b>${line.title.replace(/[`]/g, "")}</b>` : "<b>Gotifi WS Message</b>";
|
|
307
|
+
try {
|
|
308
|
+
await this.sendToAsync(this.config.matrixInstance, {
|
|
309
|
+
html: `${title != "" ? `${title}
|
|
310
|
+
` : ""}${formatMessage}`
|
|
311
|
+
});
|
|
312
|
+
} catch (err) {
|
|
313
|
+
this.log.warn(`Error sending Matrix message: ${err}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
break;
|
|
317
|
+
case "discord":
|
|
318
|
+
if (this.config.discordInstance && this.config.discordTarget) {
|
|
319
|
+
const formatMessage = line.message.replace(/[`]/g, "").replace(/[']/g, '"');
|
|
320
|
+
const title = line.title != "" ? `<b>${line.title.replace(/[`]/g, "")}</b>` : "Gotifi WS Message";
|
|
321
|
+
if (this.config.discordTarget.match(/^\d+$/)) {
|
|
322
|
+
try {
|
|
323
|
+
await this.sendToAsync(this.config.discordInstance, "sendMessage", {
|
|
324
|
+
userId: this.config.discordTarget,
|
|
325
|
+
content: `${title != "" ? `${title}
|
|
326
|
+
` : ""}${formatMessage}`
|
|
327
|
+
});
|
|
328
|
+
} catch (err) {
|
|
329
|
+
this.log.warn(`Error sending Discord message: ${err}`);
|
|
330
|
+
}
|
|
331
|
+
} else if (this.config.discordTarget.match(/^\d+\/\d+$/)) {
|
|
332
|
+
const [serverId, channelId] = this.config.discordTarget.split("/");
|
|
333
|
+
try {
|
|
334
|
+
await this.sendToAsync(this.config.discordInstance, "sendMessage", {
|
|
335
|
+
serverId,
|
|
336
|
+
channelId,
|
|
337
|
+
content: `${title != "" ? `${title}
|
|
338
|
+
` : ""}${formatMessage}`
|
|
339
|
+
});
|
|
340
|
+
} catch (err) {
|
|
341
|
+
this.log.warn(`Error sending Discord message: ${err}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
this.log.error("Push-Message error: Please check your Configuration");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async _(word, systemLang) {
|
|
352
|
+
return new Promise((resolve) => {
|
|
353
|
+
void (async () => {
|
|
354
|
+
const translations = await Promise.resolve().then(() => __toESM(require(`../admin/i18n/${systemLang ? systemLang : "en"}/translations.json`)));
|
|
355
|
+
if (translations[word]) {
|
|
356
|
+
resolve(translations[word]);
|
|
357
|
+
} else {
|
|
358
|
+
this.log.debug(`Please translate in translations.json: ${word}`);
|
|
359
|
+
resolve(word);
|
|
360
|
+
}
|
|
361
|
+
})();
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (require.main !== module) {
|
|
366
|
+
module.exports = (options) => new GotifyWs(options);
|
|
367
|
+
} else {
|
|
368
|
+
(() => new GotifyWs())();
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/main.ts"],
|
|
4
|
+
"sourcesContent": ["'use strict';\n\nimport WebSocket from 'ws';\nimport * as utils from '@iobroker/adapter-core';\n\nclass GotifyWs extends utils.Adapter {\n private systemLang: string = 'de';\n private ws!: WebSocket;\n private timer: ioBroker.Timeout | undefined = undefined;\n private stopNow: boolean = false;\n\n public constructor(options: Partial<utils.AdapterOptions> = {}) {\n super({\n ...options,\n name: 'gotify-ws',\n });\n this.on('ready', this.onReady.bind(this));\n this.on('unload', this.onUnload.bind(this));\n }\n\n private async onReady(): Promise<void> {\n const sysLang = await this.getForeignObjectAsync('system.config');\n\n if (sysLang && sysLang.common && sysLang.common.language) {\n this.systemLang = sysLang.common.language;\n }\n\n await this.setState('info.connection', false, true);\n this.connectWebSocket();\n }\n\n private async onUnload(callback: () => void): Promise<void> {\n await this.setState('info.connection', false, true);\n\n try {\n if (this.ws) {\n this.stopNow = true;\n this.ws.close();\n this.ws.terminate();\n this.clearTimeout(this.timer);\n this.timer = null;\n }\n callback();\n } catch (e) {\n callback();\n }\n }\n\n private async onMessage(obj: ioBroker.Message | null): Promise<void> {\n switch (obj?.command) {\n case 'sendToInstance':\n if (obj && obj.command === 'sendToInstance' && obj.message && obj.message.type) {\n const resultInstances = [];\n\n const instances = await this.getObjectViewAsync('system', 'instance', {\n startkey: `system.adapter.${obj.message.type}.`,\n\n endkey: `system.adapter.${obj.message.type}.\\u9999`,\n }).catch(err => this.log.error(err));\n\n if (instances && instances.rows && instances.rows.length != 0) {\n instances.rows.forEach(row => {\n resultInstances.push({\n label: row.id.replace('system.adapter.', ''),\n value: row.id.replace('system.adapter.', ''),\n });\n });\n } else {\n resultInstances.push({\n label: this._('none', this.systemLang),\n value: 'none',\n });\n }\n this.log.debug(`sendToInstance - ${JSON.stringify(obj)}`);\n this.sendTo(obj.from, obj.command, resultInstances, obj.callback);\n }\n break;\n\n case 'sendToTelegramUser': {\n let useUsername = false;\n\n if (obj && obj.command === 'sendToTelegramUser' && obj.message && obj.message.instance) {\n const inst = obj.message.instance ? obj.message.instance : this.config.telegramInstance;\n const userList = (await this.getForeignStateAsync(`${inst}.communicate.users`)) as ioBroker.State;\n const configTelegram = await this.getForeignObjectAsync(`system.adapter.${inst}`);\n\n if (configTelegram && configTelegram.native) {\n const native = configTelegram.native;\n useUsername = native.useUsername;\n }\n\n const resultUser = [{ label: this._('All Receiver', this.systemLang), value: 'allTelegramUsers' }];\n\n if (userList && userList?.val) {\n const users = JSON.parse(userList?.val as string);\n\n for (const i in users) {\n resultUser.push({\n label: useUsername === true ? users[i].userName : users[i].firstName,\n value: useUsername === true ? users[i].userName : users[i].firstName,\n });\n }\n\n try {\n this.sendTo(obj.from, obj.command, resultUser, obj.callback);\n } catch (err) {\n this.log.error(`Cannot parse stored user IDs from Telegram: ${err}`);\n }\n }\n }\n break;\n }\n case 'sendToDiscordTarget':\n if (obj && obj.command === 'sendToDiscordTarget' && obj.message && obj.message.instance) {\n const resultTarget = [{ label: this._('none', this.systemLang), value: 'none' }];\n\n const targetList = await this.sendToAsync(obj.message.instance, 'getNotificationTargets', {});\n\n if (Array.isArray(targetList)) {\n for (const i in targetList) {\n resultTarget.push({\n label: targetList[i].value,\n value: targetList[i].value,\n });\n }\n }\n\n try {\n this.sendTo(obj.from, obj.command, resultTarget, obj.callback);\n } catch (err) {\n this.log.error(`Cannot parse stored user IDs from Discord: ${err}`);\n }\n } else if (obj && obj.command === 'sendToDiscordTarget') {\n const resultTarget = [{ label: this._('none', this.systemLang), value: 'none' }];\n\n try {\n this.sendTo(obj.from, obj.command, resultTarget, obj.callback);\n } catch (err) {\n this.log.error(`Cannot parse stored user IDs from Discord: ${err}`);\n }\n }\n break;\n }\n }\n\n private connectWebSocket(): void {\n if (this.config.ip && this.config.port) {\n const uri = `ws://${this.config.ip}:${this.config.port}/stream`;\n\n this.ws = new WebSocket(uri, {\n headers: {\n 'X-Gotify-Key': this.config.token,\n },\n });\n\n this.ws.on('open', async () => {\n await this.setState('info.connection', true, true);\n this.log.info('WebSocket connected');\n });\n\n this.ws.on('message', async data => {\n const line = JSON.parse(data.toString('utf-8'));\n await this.pushMessage(line);\n });\n\n this.ws.on('close', async () => {\n await this.setState('info.connection', false, true);\n this.log.info('WebSocket closed');\n if (this.stopNow === false) {\n this.timer = this.setTimeout(this.connectWebSocket, 5000);\n }\n });\n\n this.ws.on('error', async err => {\n await this.setState('info.connection', false, true);\n\n this.log.error(`WebSocket error: ${err}`);\n });\n } else {\n this.log.error('WebSocket error: Please check your Configuration');\n }\n }\n\n private async pushMessage(line: ioBroker.GotifyMessage): Promise<void> {\n if (this.config.notificationType) {\n switch (this.config.notificationType) {\n case 'telegram':\n if (\n this.config.telegramUser &&\n this.config.telegramUser === 'allTelegramUsers' &&\n this.config.telegramInstance\n ) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title =\n line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';\n\n try {\n await this.sendToAsync(this.config.telegramInstance, 'send', {\n parse_mode: 'HTML',\n text: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n });\n } catch (err) {\n this.log.warn(`Error sending Telegram message: ${err}`);\n }\n } else if (\n this.config.telegramUser &&\n this.config.telegramUser != 'allTelegramUsers' &&\n this.config.telegramInstance\n ) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title =\n line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';\n\n try {\n await this.sendToAsync(this.config.telegramInstance, 'send', {\n user: this.config.telegramUser,\n parse_mode: 'HTML',\n text: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n });\n } catch (err) {\n this.log.warn(`Error sending Telegram message: ${err}`);\n }\n }\n break;\n case 'email':\n if (this.config.emailInstance && this.config.emailReceiver && this.config.emailSender) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title = line.title != '' ? line.title.replace(/[`]/g, '') : 'Gotifi WS Message';\n\n try {\n await this.sendToAsync(this.config.emailInstance, 'send', {\n text: formatMessage,\n to: this.config.emailReceiver,\n subject: title,\n from: this.config.emailSender,\n });\n } catch (err) {\n this.log.warn(`Error sending E-Mail message: ${err}`);\n }\n }\n break;\n case 'pushover':\n if (\n this.config.pushoverSilentNotice === true &&\n this.config.pushoverInstance &&\n this.config.pushoverDeviceID\n ) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title =\n line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';\n\n try {\n await this.sendToAsync(this.config.pushoverInstance, 'send', {\n message: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n sound: '',\n priority: -1,\n title: title,\n device: this.config.pushoverDeviceID,\n html: 1,\n });\n } catch (err) {\n this.log.warn(`Error sending Pushover message: ${err}`);\n }\n } else if (this.config.pushoverInstance && this.config.pushoverDeviceID) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title =\n line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';\n\n try {\n await this.sendToAsync(this.config.pushoverInstance, 'send', {\n message: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n sound: '',\n title: title,\n device: this.config.pushoverDeviceID,\n html: 1,\n });\n } catch (err) {\n this.log.warn(`Error sending Pushover message: ${err}`);\n }\n }\n break;\n case 'whatsapp-cmb':\n if (this.config.whatsappInstance) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title = line.title != '' ? `*${line.title.replace(/[`]/g, '')}*` : '*Gotifi WS Message*';\n\n try {\n await this.sendToAsync(this.config.whatsappInstance, 'send', {\n text: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n });\n } catch (err) {\n this.log.warn(`Error sending WhatsApp message: ${err}`);\n }\n }\n break;\n case 'notification-manager':\n if (this.config.notificationManagerInstance) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title =\n line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';\n\n try {\n await this.sendToAsync(\n this.config.notificationManagerInstance,\n 'registerUserNotification',\n {\n category: 'notify',\n message: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n },\n );\n } catch (err) {\n this.log.warn(`Error sending Notification-Manager message: ${err}`);\n }\n }\n break;\n case 'signal-cmb':\n if (this.config.signalInstance) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title = line.title != '' ? line.title.replace(/[`]/g, '') : 'Gotifi WS Message';\n\n try {\n await this.sendToAsync(this.config.signalInstance, 'send', {\n text: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n });\n } catch (err) {\n this.log.warn(`Error sending Signal message: ${err}`);\n }\n }\n break;\n case 'matrix-org':\n if (this.config.matrixInstance) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title =\n line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';\n\n try {\n await this.sendToAsync(this.config.matrixInstance, {\n html: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n });\n } catch (err) {\n this.log.warn(`Error sending Matrix message: ${err}`);\n }\n }\n break;\n case 'discord':\n if (this.config.discordInstance && this.config.discordTarget) {\n const formatMessage = line.message.replace(/[`]/g, '').replace(/[']/g, '\"');\n\n const title =\n line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : 'Gotifi WS Message';\n\n if (this.config.discordTarget.match(/^\\d+$/)) {\n // send to a single user\n try {\n await this.sendToAsync(this.config.discordInstance, 'sendMessage', {\n userId: this.config.discordTarget,\n content: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n });\n } catch (err) {\n this.log.warn(`Error sending Discord message: ${err}`);\n }\n } else if (this.config.discordTarget.match(/^\\d+\\/\\d+$/)) {\n // send to a server channel\n const [serverId, channelId] = this.config.discordTarget.split('/');\n try {\n await this.sendToAsync(this.config.discordInstance, 'sendMessage', {\n serverId,\n channelId,\n content: `${title != '' ? `${title}\\n` : ''}${formatMessage}`,\n });\n } catch (err) {\n this.log.warn(`Error sending Discord message: ${err}`);\n }\n }\n }\n break;\n }\n } else {\n this.log.error('Push-Message error: Please check your Configuration');\n }\n }\n\n private async _(word: string, systemLang: string): Promise<string> {\n return new Promise(resolve => {\n void (async () => {\n const translations = await import(`../admin/i18n/${systemLang ? systemLang : 'en'}/translations.json`);\n if (translations[word]) {\n resolve(translations[word]);\n } else {\n this.log.debug(`Please translate in translations.json: ${word}`);\n resolve(word);\n }\n })();\n });\n }\n}\n\nif (require.main !== module) {\n // Export the constructor in compact mode\n module.exports = (options: Partial<utils.AdapterOptions> | undefined) => new GotifyWs(options);\n} else {\n // otherwise start the instance directly\n (() => new GotifyWs())();\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAEA,gBAAsB;AACtB,YAAuB;AAEvB,MAAM,iBAAiB,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H,GAAC,MAAM,IAAI,SAAS,GAAG;AAC3B;",
|
|
6
|
+
"names": ["WebSocket"]
|
|
7
|
+
}
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "gotify-ws",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"news": {
|
|
6
|
+
"0.2.0": {
|
|
7
|
+
"en": "Adapter rewritten in Typescript",
|
|
8
|
+
"de": "Adapter neu geschrieben in Typescript",
|
|
9
|
+
"ru": "Адаптер переписан в Typescript",
|
|
10
|
+
"pt": "Adaptador reescrito no Typescript",
|
|
11
|
+
"nl": "Adapter herschreven in Typescript",
|
|
12
|
+
"fr": "Adaptateur réécrit dans Typescript",
|
|
13
|
+
"it": "Adattatore riscritto in Typescript",
|
|
14
|
+
"es": "Adaptador reescrito en Tiposcript",
|
|
15
|
+
"pl": "Adapter przepisywany na maszynie",
|
|
16
|
+
"uk": "Переписка адаптера в Typescript",
|
|
17
|
+
"zh-cn": "用 Typescript 重写适配器"
|
|
18
|
+
},
|
|
6
19
|
"0.1.13": {
|
|
7
20
|
"en": "Dependencies updated\nmigrated to json5",
|
|
8
21
|
"de": "Ausgaben aktualisiert\nzu json5 migriert",
|
|
@@ -80,19 +93,6 @@
|
|
|
80
93
|
"pl": "Responsive Design fix\nKod oczyszczony",
|
|
81
94
|
"uk": "Кріплення адаптивного дизайну\nЧистий код",
|
|
82
95
|
"zh-cn": "反应设计修正\n已清理代码"
|
|
83
|
-
},
|
|
84
|
-
"0.1.7": {
|
|
85
|
-
"en": "Dependencies updated\nResponsive Design fix",
|
|
86
|
-
"de": "Ausgaben aktualisiert\nResponsive Design fix",
|
|
87
|
-
"ru": "Обновленные данные о зависимостях\nРеакция Responsive Design",
|
|
88
|
-
"pt": "Dependências atualizadas\nCorreção de design responsivo",
|
|
89
|
-
"nl": "Afhankelijkheden bijgewerkt\nResponsive Design fix",
|
|
90
|
-
"fr": "Dépendances actualisées\nCorrection de conception sensible",
|
|
91
|
-
"it": "Dipendenze aggiornate\nResponsive Design fix",
|
|
92
|
-
"es": "Actualización de las dependencias\nResponsive Design fix",
|
|
93
|
-
"pl": "Aktualizacja zależności\nResponsive Design fix",
|
|
94
|
-
"uk": "Залежність оновлено\nКріплення адаптивного дизайну",
|
|
95
|
-
"zh-cn": "更新的依赖关系\n反应设计修正"
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"titleLang": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.gotify-ws",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Gotify web socket for connection to various notification systems",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "simatec",
|
|
@@ -40,19 +40,23 @@
|
|
|
40
40
|
"@iobroker/adapter-dev": "^1.4.0",
|
|
41
41
|
"@iobroker/eslint-config": "^2.0.1",
|
|
42
42
|
"@iobroker/testing": "^5.0.4",
|
|
43
|
+
"@tsconfig/node20": "^20.1.5",
|
|
44
|
+
"@types/ws": "^8.18.1",
|
|
43
45
|
"chai": "^5.2.0",
|
|
44
46
|
"chai-as-promised": "^8.0.1",
|
|
45
47
|
"mocha": "^11.1.0",
|
|
48
|
+
"rimraf": "^6.0.1",
|
|
46
49
|
"sinon": "^20.0.0",
|
|
47
|
-
"sinon-chai": "^4.0.0"
|
|
50
|
+
"sinon-chai": "^4.0.0",
|
|
51
|
+
"ts-node": "^10.9.2",
|
|
52
|
+
"typescript": "^5.8.3"
|
|
48
53
|
},
|
|
49
|
-
"main": "main.js",
|
|
54
|
+
"main": "build/main.js",
|
|
50
55
|
"files": [
|
|
51
56
|
"admin/",
|
|
52
57
|
"!admin/**/*/flat.txt",
|
|
53
58
|
"!admin/**/tsconfig.json",
|
|
54
|
-
"
|
|
55
|
-
"!lib/**/*.{sh,bat,log}",
|
|
59
|
+
"build/",
|
|
56
60
|
"!.dev-server",
|
|
57
61
|
"!.vscode",
|
|
58
62
|
"!.github",
|
|
@@ -70,9 +74,18 @@
|
|
|
70
74
|
"main.js"
|
|
71
75
|
],
|
|
72
76
|
"scripts": {
|
|
73
|
-
"
|
|
74
|
-
"
|
|
77
|
+
"prebuild": "rimraf build",
|
|
78
|
+
"build": "build-adapter ts",
|
|
79
|
+
"watch": "build-adapter ts --watch",
|
|
80
|
+
"prebuild:ts": "rimraf build",
|
|
81
|
+
"build:ts": "build-adapter ts",
|
|
82
|
+
"watch:ts": "build-adapter ts --watch",
|
|
83
|
+
"test:ts": "mocha --config test/mocharc.custom.json src/**/*.test.ts",
|
|
75
84
|
"test:unit": "mocha test/unit --exit",
|
|
85
|
+
"test": "npm run test:ts && npm run test:package",
|
|
86
|
+
"check": "tsc --noEmit",
|
|
87
|
+
"coverage": "nyc npm run test:ts",
|
|
88
|
+
"test:package": "mocha test/package --exit",
|
|
76
89
|
"test:integration": "mocha test/integration --exit",
|
|
77
90
|
"release": "release-script",
|
|
78
91
|
"release-patch": "release-script patch --yes",
|
|
@@ -84,6 +97,26 @@
|
|
|
84
97
|
"npm": "npm install",
|
|
85
98
|
"lint": "eslint -c eslint.config.mjs ."
|
|
86
99
|
},
|
|
100
|
+
"nyc": {
|
|
101
|
+
"include": [
|
|
102
|
+
"src/**/*.ts"
|
|
103
|
+
],
|
|
104
|
+
"exclude": [
|
|
105
|
+
"src/**/*.test.ts"
|
|
106
|
+
],
|
|
107
|
+
"extension": [
|
|
108
|
+
".ts"
|
|
109
|
+
],
|
|
110
|
+
"require": [
|
|
111
|
+
"ts-node/register"
|
|
112
|
+
],
|
|
113
|
+
"reporter": [
|
|
114
|
+
"text-summary",
|
|
115
|
+
"html"
|
|
116
|
+
],
|
|
117
|
+
"sourceMap": true,
|
|
118
|
+
"instrument": true
|
|
119
|
+
},
|
|
87
120
|
"bugs": {
|
|
88
121
|
"url": "https://github.com/simatec/ioBroker.gotify-ws/issues"
|
|
89
122
|
},
|
package/lib/adapter-config.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// This file extends the AdapterConfig type from "@types/iobroker"
|
|
2
|
-
// using the actual properties present in io-package.json
|
|
3
|
-
// in order to provide typings for adapter.config properties
|
|
4
|
-
|
|
5
|
-
import { native } from "../io-package.json";
|
|
6
|
-
|
|
7
|
-
type _AdapterConfig = typeof native;
|
|
8
|
-
|
|
9
|
-
// Augment the globally declared type ioBroker.AdapterConfig
|
|
10
|
-
declare global {
|
|
11
|
-
namespace ioBroker {
|
|
12
|
-
interface AdapterConfig extends _AdapterConfig {
|
|
13
|
-
// Do not enter anything here!
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// this is required so the above AdapterConfig is found by TypeScript / type checking
|
|
19
|
-
export {};
|
package/main.js
DELETED
|
@@ -1,440 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const WebSocket = require('ws');
|
|
4
|
-
const utils = require('@iobroker/adapter-core');
|
|
5
|
-
const adapterName = require('./package.json').name.split('.').pop();
|
|
6
|
-
|
|
7
|
-
let systemLang = 'de'; // system language
|
|
8
|
-
let ws = null;
|
|
9
|
-
let timer = null;
|
|
10
|
-
let stop = false;
|
|
11
|
-
|
|
12
|
-
class GotifyWs extends utils.Adapter {
|
|
13
|
-
/**
|
|
14
|
-
* @param {Partial<utils.AdapterOptions>} [options={}]
|
|
15
|
-
*/
|
|
16
|
-
constructor(options) {
|
|
17
|
-
super({
|
|
18
|
-
...options,
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
name: adapterName,
|
|
21
|
-
});
|
|
22
|
-
this.on('ready', this.onReady.bind(this));
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
this.on('message', this.onMessage.bind(this));
|
|
25
|
-
this.on('unload', this.onUnload.bind(this));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async onReady() {
|
|
29
|
-
const sysLang = await this.getForeignObjectAsync('system.config');
|
|
30
|
-
|
|
31
|
-
if (sysLang && sysLang.common && sysLang.common.language) {
|
|
32
|
-
systemLang = sysLang.common.language;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.setState('info.connection', false, true);
|
|
36
|
-
this.connectWebSocket();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param {() => void} callback
|
|
41
|
-
*/
|
|
42
|
-
onUnload(callback) {
|
|
43
|
-
this.setState('info.connection', false, true);
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
if (ws) {
|
|
47
|
-
stop = true;
|
|
48
|
-
ws.close();
|
|
49
|
-
ws.terminate();
|
|
50
|
-
this.clearTimeout(timer);
|
|
51
|
-
timer = null;
|
|
52
|
-
}
|
|
53
|
-
callback();
|
|
54
|
-
} catch (e) {
|
|
55
|
-
callback();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @param {{ command: string; from: string; callback: ioBroker.MessageCallback | ioBroker.MessageCallbackInfo | undefined; }} obj
|
|
61
|
-
*/
|
|
62
|
-
async onMessage(obj) {
|
|
63
|
-
switch (obj.command) {
|
|
64
|
-
case 'sendToInstance':
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
if (obj && obj.command === 'sendToInstance' && obj.message && obj.message.type) {
|
|
67
|
-
let resultInstances = [];
|
|
68
|
-
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
const instances = await this.getObjectViewAsync('system', 'instance', {
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
startkey: `system.adapter.${obj.message.type}.`,
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
endkey: `system.adapter.${obj.message.type}.\u9999`,
|
|
75
|
-
}).catch((err) => this.log.error(err));
|
|
76
|
-
|
|
77
|
-
if (instances && instances.rows && instances.rows.length != 0) {
|
|
78
|
-
instances.rows.forEach(async (row) => {
|
|
79
|
-
resultInstances.push({
|
|
80
|
-
label: row.id.replace('system.adapter.', ''),
|
|
81
|
-
value: row.id.replace('system.adapter.', ''),
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
} else {
|
|
85
|
-
resultInstances.push({
|
|
86
|
-
label: this._('none', systemLang),
|
|
87
|
-
value: 'none',
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
this.log.debug(`sendToInstance - ${JSON.stringify(obj)}`);
|
|
91
|
-
this.sendTo(obj.from, obj.command, resultInstances, obj.callback);
|
|
92
|
-
}
|
|
93
|
-
break;
|
|
94
|
-
|
|
95
|
-
case 'sendToTelegramUser':
|
|
96
|
-
// eslint-disable-next-line no-case-declarations
|
|
97
|
-
let useUsername = false;
|
|
98
|
-
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
if (obj && obj.command === 'sendToTelegramUser' && obj.message && obj.message.instance) {
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
const inst = obj.message.instance ? obj.message.instance : this.config.telegramInstance;
|
|
103
|
-
const userList = await this.getForeignStateAsync(`${inst}.communicate.users`);
|
|
104
|
-
const configTelegram = await this.getForeignObjectAsync(`system.adapter.${inst}`);
|
|
105
|
-
|
|
106
|
-
if (configTelegram && configTelegram.native) {
|
|
107
|
-
const native = configTelegram.native;
|
|
108
|
-
useUsername = native.useUsername;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let resultUser = [{ label: this._('All Receiver', systemLang), value: 'allTelegramUsers' }];
|
|
112
|
-
|
|
113
|
-
if (userList && userList.val) {
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
const users = JSON.parse(userList.val);
|
|
116
|
-
|
|
117
|
-
for (const i in users) {
|
|
118
|
-
resultUser.push({
|
|
119
|
-
label: useUsername === true ? users[i].userName : users[i].firstName,
|
|
120
|
-
value: useUsername === true ? users[i].userName : users[i].firstName,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
this.sendTo(obj.from, obj.command, resultUser, obj.callback);
|
|
126
|
-
} catch (err) {
|
|
127
|
-
this.log.error(`Cannot parse stored user IDs from Telegram: ${err}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
case 'sendToDiscordTarget':
|
|
133
|
-
// @ts-ignore
|
|
134
|
-
if (obj && obj.command === 'sendToDiscordTarget' && obj.message && obj.message.instance) {
|
|
135
|
-
let resultTarget = [{ label: this._('none', systemLang), value: 'none' }];
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
const targetList = await this.sendToAsync(obj.message.instance, 'getNotificationTargets', {});
|
|
138
|
-
|
|
139
|
-
if (Array.isArray(targetList)) {
|
|
140
|
-
for (const i in targetList) {
|
|
141
|
-
resultTarget.push({
|
|
142
|
-
label: targetList[i].value,
|
|
143
|
-
value: targetList[i].value,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
this.sendTo(obj.from, obj.command, resultTarget, obj.callback);
|
|
150
|
-
} catch (err) {
|
|
151
|
-
this.log.error(`Cannot parse stored user IDs from Discord: ${err}`);
|
|
152
|
-
}
|
|
153
|
-
} else if (obj && obj.command === 'sendToDiscordTarget') {
|
|
154
|
-
let resultTarget = [{ label: this._('none', systemLang), value: 'none' }];
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
this.sendTo(obj.from, obj.command, resultTarget, obj.callback);
|
|
158
|
-
} catch (err) {
|
|
159
|
-
this.log.error(`Cannot parse stored user IDs from Discord: ${err}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async connectWebSocket() {
|
|
167
|
-
if (this.config.ip && this.config.port) {
|
|
168
|
-
const uri = `ws://${this.config.ip}:${this.config.port}/stream`;
|
|
169
|
-
|
|
170
|
-
ws = new WebSocket(uri, {
|
|
171
|
-
headers: {
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
'X-Gotify-Key': this.config.token,
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
ws.on('open', () => {
|
|
178
|
-
this.setState('info.connection', true, true);
|
|
179
|
-
this.log.info('WebSocket connected');
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
ws.on('message', async (data) => {
|
|
183
|
-
const line = JSON.parse(data);
|
|
184
|
-
this.pushMessage(line);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
ws.on('close', () => {
|
|
188
|
-
this.setState('info.connection', false, true);
|
|
189
|
-
this.log.info('WebSocket closed');
|
|
190
|
-
if (stop === false) {
|
|
191
|
-
timer = this.setTimeout(this.connectWebSocket, 5000);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
ws.on('error', (err) => {
|
|
196
|
-
this.setState('info.connection', false, true);
|
|
197
|
-
// @ts-ignore
|
|
198
|
-
this.log.error('WebSocket error:', err);
|
|
199
|
-
});
|
|
200
|
-
} else {
|
|
201
|
-
this.log.error('WebSocket error: Please check your Configuration');
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
async pushMessage(line) {
|
|
206
|
-
if (this.config.notificationType) {
|
|
207
|
-
switch (this.config.notificationType) {
|
|
208
|
-
case 'telegram':
|
|
209
|
-
if (
|
|
210
|
-
this.config.telegramUser &&
|
|
211
|
-
this.config.telegramUser === 'allTelegramUsers' &&
|
|
212
|
-
this.config.telegramInstance
|
|
213
|
-
) {
|
|
214
|
-
const formatMessage = line.message
|
|
215
|
-
.replace(/[`]/g, '')
|
|
216
|
-
.replace(/[']/g, '"');
|
|
217
|
-
|
|
218
|
-
const title = line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
await this.sendToAsync(this.config.telegramInstance, 'send', {
|
|
222
|
-
parse_mode: 'HTML',
|
|
223
|
-
text: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
224
|
-
});
|
|
225
|
-
} catch (err) {
|
|
226
|
-
this.log.warn(`Error sending Telegram message: ${err}`);
|
|
227
|
-
}
|
|
228
|
-
} else if (
|
|
229
|
-
this.config.telegramUser &&
|
|
230
|
-
this.config.telegramUser != 'allTelegramUsers' &&
|
|
231
|
-
this.config.telegramInstance
|
|
232
|
-
) {
|
|
233
|
-
const formatMessage = line.message
|
|
234
|
-
.replace(/[`]/g, '')
|
|
235
|
-
.replace(/[']/g, '"');
|
|
236
|
-
|
|
237
|
-
const title = line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
await this.sendToAsync(this.config.telegramInstance, 'send', {
|
|
241
|
-
user: this.config.telegramUser,
|
|
242
|
-
parse_mode: 'HTML',
|
|
243
|
-
text: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
244
|
-
});
|
|
245
|
-
} catch (err) {
|
|
246
|
-
this.log.warn(`Error sending Telegram message: ${err}`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
break;
|
|
250
|
-
case 'email':
|
|
251
|
-
if (this.config.emailInstance && this.config.emailReceiver && this.config.emailSender) {
|
|
252
|
-
const formatMessage = line.message
|
|
253
|
-
.replace(/[`]/g, '')
|
|
254
|
-
.replace(/[']/g, '"');
|
|
255
|
-
|
|
256
|
-
const title = line.title != '' ? line.title.replace(/[`]/g, '') : 'Gotifi WS Message';
|
|
257
|
-
|
|
258
|
-
try {
|
|
259
|
-
await this.sendToAsync(this.config.emailInstance, 'send', {
|
|
260
|
-
text: formatMessage,
|
|
261
|
-
to: this.config.emailReceiver,
|
|
262
|
-
subject: title,
|
|
263
|
-
from: this.config.emailSender,
|
|
264
|
-
});
|
|
265
|
-
} catch (err) {
|
|
266
|
-
this.log.warn(`Error sending E-Mail message: ${err}`);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
break;
|
|
270
|
-
case 'pushover':
|
|
271
|
-
if (
|
|
272
|
-
this.config.pushoverSilentNotice === true &&
|
|
273
|
-
this.config.pushoverInstance &&
|
|
274
|
-
this.config.pushoverDeviceID
|
|
275
|
-
) {
|
|
276
|
-
const formatMessage = line.message
|
|
277
|
-
.replace(/[`]/g, '')
|
|
278
|
-
.replace(/[']/g, '"');
|
|
279
|
-
|
|
280
|
-
const title = line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';
|
|
281
|
-
|
|
282
|
-
try {
|
|
283
|
-
await this.sendToAsync(this.config.pushoverInstance, 'send', {
|
|
284
|
-
message: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
285
|
-
sound: '',
|
|
286
|
-
priority: -1,
|
|
287
|
-
title: title,
|
|
288
|
-
device: this.config.pushoverDeviceID,
|
|
289
|
-
html: 1,
|
|
290
|
-
});
|
|
291
|
-
} catch (err) {
|
|
292
|
-
this.log.warn(`Error sending Pushover message: ${err}`);
|
|
293
|
-
}
|
|
294
|
-
} else if (this.config.pushoverInstance && this.config.pushoverDeviceID) {
|
|
295
|
-
const formatMessage = line.message
|
|
296
|
-
.replace(/[`]/g, '')
|
|
297
|
-
.replace(/[']/g, '"');
|
|
298
|
-
|
|
299
|
-
const title = line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';
|
|
300
|
-
|
|
301
|
-
try {
|
|
302
|
-
await this.sendToAsync(this.config.pushoverInstance, 'send', {
|
|
303
|
-
message: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
304
|
-
sound: '',
|
|
305
|
-
title: title,
|
|
306
|
-
device: this.config.pushoverDeviceID,
|
|
307
|
-
html: 1,
|
|
308
|
-
});
|
|
309
|
-
} catch (err) {
|
|
310
|
-
this.log.warn(`Error sending Pushover message: ${err}`);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
break;
|
|
314
|
-
case 'whatsapp-cmb':
|
|
315
|
-
if (this.config.whatsappInstance) {
|
|
316
|
-
const formatMessage = line.message
|
|
317
|
-
.replace(/[`]/g, '')
|
|
318
|
-
.replace(/[']/g, '"');
|
|
319
|
-
|
|
320
|
-
const title = line.title != '' ? `*${line.title.replace(/[`]/g, '')}*` : '*Gotifi WS Message*';
|
|
321
|
-
|
|
322
|
-
try {
|
|
323
|
-
await this.sendToAsync(this.config.whatsappInstance, 'send', {
|
|
324
|
-
text: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
325
|
-
});
|
|
326
|
-
} catch (err) {
|
|
327
|
-
this.log.warn(`Error sending WhatsApp message: ${err}`);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
break;
|
|
331
|
-
case 'notification-manager':
|
|
332
|
-
if (this.config.notificationManagerInstance) {
|
|
333
|
-
const formatMessage = line.message
|
|
334
|
-
.replace(/[`]/g, '')
|
|
335
|
-
.replace(/[']/g, '"');
|
|
336
|
-
|
|
337
|
-
const title = line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';
|
|
338
|
-
|
|
339
|
-
try {
|
|
340
|
-
await this.sendToAsync(this.config.notificationManagerInstance, 'registerUserNotification', {
|
|
341
|
-
category: 'notify',
|
|
342
|
-
message: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
343
|
-
});
|
|
344
|
-
} catch (err) {
|
|
345
|
-
this.log.warn(`Error sending Notification-Manager message: ${err}`);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
break;
|
|
349
|
-
case 'signal-cmb':
|
|
350
|
-
if (this.config.signalInstance) {
|
|
351
|
-
const formatMessage = line.message
|
|
352
|
-
.replace(/[`]/g, '')
|
|
353
|
-
.replace(/[']/g, '"');
|
|
354
|
-
|
|
355
|
-
const title = line.title != '' ? line.title.replace(/[`]/g, '') : 'Gotifi WS Message';
|
|
356
|
-
|
|
357
|
-
try {
|
|
358
|
-
await this.sendToAsync(this.config.signalInstance, 'send', {
|
|
359
|
-
text: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
360
|
-
});
|
|
361
|
-
} catch (err) {
|
|
362
|
-
this.log.warn(`Error sending Signal message: ${err}`);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
break;
|
|
366
|
-
case 'matrix-org':
|
|
367
|
-
if (this.config.matrixInstance) {
|
|
368
|
-
const formatMessage = line.message
|
|
369
|
-
.replace(/[`]/g, '')
|
|
370
|
-
.replace(/[']/g, '"');
|
|
371
|
-
|
|
372
|
-
const title = line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : '<b>Gotifi WS Message</b>';
|
|
373
|
-
|
|
374
|
-
try {
|
|
375
|
-
await this.sendToAsync(this.config.matrixInstance, {
|
|
376
|
-
html: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
377
|
-
});
|
|
378
|
-
} catch (err) {
|
|
379
|
-
this.log.warn(`Error sending Matrix message: ${err}`);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
break;
|
|
383
|
-
case 'discord':
|
|
384
|
-
if (this.config.discordInstance && this.config.discordTarget) {
|
|
385
|
-
const formatMessage = line.message
|
|
386
|
-
.replace(/[`]/g, '')
|
|
387
|
-
.replace(/[']/g, '"');
|
|
388
|
-
|
|
389
|
-
const title = line.title != '' ? `<b>${line.title.replace(/[`]/g, '')}</b>` : 'Gotifi WS Message';
|
|
390
|
-
|
|
391
|
-
if (this.config.discordTarget.match(/^\d+$/)) {
|
|
392
|
-
// send to a single user
|
|
393
|
-
try {
|
|
394
|
-
await this.sendToAsync(this.config.discordInstance, 'sendMessage', {
|
|
395
|
-
userId: this.config.discordTarget,
|
|
396
|
-
content: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
397
|
-
});
|
|
398
|
-
} catch (err) {
|
|
399
|
-
this.log.warn(`Error sending Discord message: ${err}`);
|
|
400
|
-
}
|
|
401
|
-
} else if (this.config.discordTarget.match(/^\d+\/\d+$/)) {
|
|
402
|
-
// send to a server channel
|
|
403
|
-
const [serverId, channelId] = this.config.discordTarget.split('/');
|
|
404
|
-
try {
|
|
405
|
-
await this.sendToAsync(this.config.discordInstance, 'sendMessage', {
|
|
406
|
-
serverId,
|
|
407
|
-
channelId,
|
|
408
|
-
content: `${title != '' ? `${title}\n` : ''}${formatMessage}`,
|
|
409
|
-
});
|
|
410
|
-
} catch (err) {
|
|
411
|
-
this.log.warn(`Error sending Discord message: ${err}`);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
} else {
|
|
418
|
-
this.log.error('Push-Message error: Please check your Configuration');
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
_(word, systemLang) {
|
|
422
|
-
const translations = require(`./admin/i18n/${systemLang ? systemLang : 'en'}/translations.json`);
|
|
423
|
-
|
|
424
|
-
if (translations[word]) {
|
|
425
|
-
return translations[word];
|
|
426
|
-
} else {
|
|
427
|
-
this.log.debug(`Please translate in translations.json: ${word}`);
|
|
428
|
-
return word;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if (require.main !== module) {
|
|
434
|
-
/**
|
|
435
|
-
* @param {Partial<utils.AdapterOptions>} [options={}]
|
|
436
|
-
*/
|
|
437
|
-
module.exports = (options) => new GotifyWs(options);
|
|
438
|
-
} else {
|
|
439
|
-
new GotifyWs();
|
|
440
|
-
}
|