matterbridge-webhooks 0.0.2 → 0.0.4
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/CHANGELOG.md +31 -0
- package/dist/fetch.js +1 -1
- package/dist/platform.js +49 -25
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/tsconfig.jest.json +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,37 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
8
8
|
<img src="bmc-button.svg" alt="Buy me a coffee" width="120">
|
|
9
9
|
</a>
|
|
10
10
|
|
|
11
|
+
## [0.0.4] - 2025-05-05
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- [package]: Updated package.
|
|
16
|
+
- [package]: Updated dependencies.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- [platform]: Fixed bug on unselected webhooks.
|
|
21
|
+
|
|
22
|
+
<a href="https://www.buymeacoffee.com/luligugithub">
|
|
23
|
+
<img src="bmc-button.svg" alt="Buy me a coffee" width="80">
|
|
24
|
+
</a>
|
|
25
|
+
|
|
26
|
+
## [0.0.3] - 2025-05-01
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- [readme]: Added the possibility to test the hook before confirming the changes in the config editor.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- [package]: Require matterbridge 3.0.0.
|
|
35
|
+
- [package]: Updated package.
|
|
36
|
+
- [package]: Updated dependencies.
|
|
37
|
+
|
|
38
|
+
<a href="https://www.buymeacoffee.com/luligugithub">
|
|
39
|
+
<img src="bmc-button.svg" alt="Buy me a coffee" width="80">
|
|
40
|
+
</a>
|
|
41
|
+
|
|
11
42
|
## [0.0.2] - 2025-03-30
|
|
12
43
|
|
|
13
44
|
### Added
|
package/dist/fetch.js
CHANGED
|
@@ -44,7 +44,7 @@ export async function fetch(url, method = 'GET', data = {}, timeout = 5000) {
|
|
|
44
44
|
clearTimeout(timeoutId);
|
|
45
45
|
res.resume();
|
|
46
46
|
req.destroy();
|
|
47
|
-
|
|
47
|
+
reject(new Error(`Request failed with status code: ${res.statusCode}`));
|
|
48
48
|
}
|
|
49
49
|
res.on('data', (chunk) => {
|
|
50
50
|
responseData += chunk;
|
package/dist/platform.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { bridgedNode, MatterbridgeDynamicPlatform, MatterbridgeEndpoint, onOffLight, onOffOutlet, onOffSwitch } from 'matterbridge';
|
|
2
|
+
import { isValidObject } from 'matterbridge/utils';
|
|
2
3
|
import { fetch } from './fetch.js';
|
|
3
4
|
export class Platform extends MatterbridgeDynamicPlatform {
|
|
4
5
|
webhooks;
|
|
5
6
|
bridgedDevices = new Map();
|
|
6
7
|
constructor(matterbridge, log, config) {
|
|
7
8
|
super(matterbridge, log, config);
|
|
8
|
-
if (this.verifyMatterbridgeVersion === undefined || typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('
|
|
9
|
-
throw new Error(`This plugin requires Matterbridge version >= "
|
|
9
|
+
if (this.verifyMatterbridgeVersion === undefined || typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.0.0')) {
|
|
10
|
+
throw new Error(`This plugin requires Matterbridge version >= "3.0.0". Please update Matterbridge to the latest version in the frontend.`);
|
|
10
11
|
}
|
|
11
12
|
this.log.info('Initializing platform:', this.config.name);
|
|
12
13
|
this.webhooks = this.config.webhooks;
|
|
@@ -16,30 +17,29 @@ export class Platform extends MatterbridgeDynamicPlatform {
|
|
|
16
17
|
this.log.info('onStart called with reason:', reason ?? 'none');
|
|
17
18
|
await this.ready;
|
|
18
19
|
await this.clearSelect();
|
|
19
|
-
let i =
|
|
20
|
+
let i = 0;
|
|
20
21
|
for (const webhookName in this.webhooks) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
22
|
+
this.log.debug(`Loading webhook ${++i} ${webhookName} with method ${this.webhooks[webhookName].method} and url ${this.webhooks[webhookName].httpUrl}`);
|
|
23
|
+
const webhook = this.webhooks[webhookName];
|
|
24
|
+
this.setSelectDevice('webhook' + i, webhookName, undefined, 'hub');
|
|
25
|
+
if (!this.validateDevice(['webhook' + i, webhookName], true))
|
|
26
|
+
continue;
|
|
27
|
+
this.log.info(`Registering device: ${webhookName} with method ${webhook.method} and url ${webhook.httpUrl}`);
|
|
28
|
+
const device = new MatterbridgeEndpoint([this.config.deviceType === 'Outlet' ? onOffOutlet : this.config.deviceType === 'Light' ? onOffLight : onOffSwitch, bridgedNode], { uniqueStorageKey: webhookName }, this.config.debug)
|
|
29
|
+
.createDefaultBridgedDeviceBasicInformationClusterServer(webhookName, 'webhook' + i++, this.matterbridge.aggregatorVendorId, 'Matterbridge', 'Matterbridge Webhook', 0, this.config.version)
|
|
30
|
+
.createOnOffClusterServer(false)
|
|
31
|
+
.addRequiredClusterServers()
|
|
32
|
+
.addCommandHandler('on', async () => {
|
|
33
|
+
this.log.info(`Webhook ${webhookName} triggered.`);
|
|
34
|
+
await device.setAttribute('onOff', 'onOff', false, device.log);
|
|
35
|
+
fetch(webhook.httpUrl, webhook.method)
|
|
36
|
+
.then(() => this.log.notice(`Webhook ${webhookName} successful!`))
|
|
37
|
+
.catch((err) => {
|
|
38
|
+
this.log.error(`Webhook ${webhookName} failed: ${err instanceof Error ? err.message : err}`);
|
|
39
39
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
});
|
|
41
|
+
await this.registerDevice(device);
|
|
42
|
+
this.bridgedDevices.set(webhookName, device);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
async onConfigure() {
|
|
@@ -50,9 +50,33 @@ export class Platform extends MatterbridgeDynamicPlatform {
|
|
|
50
50
|
await device.setAttribute('onOff', 'onOff', false, device.log);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
async onAction(action, value, id) {
|
|
53
|
+
async onAction(action, value, id, formData) {
|
|
54
54
|
this.log.info('onAction called with action:', action, 'and value:', value ?? 'none', 'and id:', id ?? 'none');
|
|
55
|
+
this.log.debug('onAction called with formData:', formData ?? 'none');
|
|
56
|
+
if (id?.startsWith('root_webhooks_'))
|
|
57
|
+
id = id.replace('root_webhooks_', '');
|
|
58
|
+
if (id?.endsWith('_test'))
|
|
59
|
+
id = id.replace('_test', '');
|
|
55
60
|
if (action === 'test') {
|
|
61
|
+
if (isValidObject(formData, 1) && isValidObject(formData.webhooks, 1)) {
|
|
62
|
+
const webhooks = formData.webhooks;
|
|
63
|
+
for (const webhookName in webhooks) {
|
|
64
|
+
if (Object.prototype.hasOwnProperty.call(webhooks, webhookName)) {
|
|
65
|
+
const webhook = webhooks[webhookName];
|
|
66
|
+
if (id?.includes(webhookName)) {
|
|
67
|
+
this.log.info(`Testing new webhook ${webhookName} method ${webhook.method} url ${webhook.httpUrl}`);
|
|
68
|
+
fetch(webhook.httpUrl, webhook.method)
|
|
69
|
+
.then(() => {
|
|
70
|
+
this.log.notice(`Webhook test ${webhookName} successful!`);
|
|
71
|
+
})
|
|
72
|
+
.catch((err) => {
|
|
73
|
+
this.log.error(`Webhook test ${webhookName} failed: ${err instanceof Error ? err.message : err}`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
56
80
|
for (const webhookName in this.webhooks) {
|
|
57
81
|
if (Object.prototype.hasOwnProperty.call(this.webhooks, webhookName)) {
|
|
58
82
|
const webhook = this.webhooks[webhookName];
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-webhooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "matterbridge-webhooks",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.4",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"node-ansi-logger": "^3.0.1",
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-webhooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Matterbridge webhooks plugin",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
+
"homepage": "https://www.npmjs.com/package/matterbridge-webhooks",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"main": "dist/index.js",
|
|
9
10
|
"repository": {
|