-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·110 lines (98 loc) · 2.56 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// DOMUSTO
import config from "../../config";
import DomustoPlugin from "../../domusto/DomustoPlugin";
// INTERFACES
import { Domusto } from "../../domusto/DomustoTypes";
// PLUGIN SPECIFIC
import axios from "axios";
/**
* Pushover plugin for DOMUSTO
* @author Bas van Dijk
* @version 0.0.1
*
* @class DomustoPushover
* @extends {DomustoPlugin}
*/
class DomustoPushover extends DomustoPlugin {
private PushoverInstances = [];
/**
* Creates an instance of DomustoPushover.
* @param {any} Plugin configuration as defined in the config.js file
* @memberof DomustoPushover
*/
constructor(pluginConfiguration: Domusto.PluginConfiguration) {
super({
plugin: "Pushover executer",
author: "Bas van Dijk",
category: Domusto.PluginCategories.push,
version: "0.0.1",
website: "http://domusto.com",
});
this.pluginConfiguration = pluginConfiguration;
const isConfigurationValid = this.validateConfigurationAttributes(
pluginConfiguration.settings,
[
{
attribute: "apiToken",
type: "string",
},
{
attribute: "userKey",
type: "string",
},
]
);
if (isConfigurationValid) {
this.console.header(
`${pluginConfiguration.id} plugin ready for sending / receiving data`
);
}
}
/**
* Executed when a signal is received for this plugin
*
* @param {Domusto.Signal} signal
* @memberof DomustoPushover
*/
onSignalReceivedForPlugin(signal: Domusto.Signal) {
switch (signal.deviceId) {
case "note":
this.sendNoteToAll(signal.data["title"], signal.data["message"]);
break;
case "link":
case "file":
default:
this.console.error("No Pushover action defined for ", signal.deviceId);
break;
}
}
/**
* Push message to all subscribed api keys
*
* @param {string} title Message title
* @param {string} message Message content
* @memberof DomustoPushover
*/
sendNoteToAll(title: string, message: string) {
const url = "https://api.pushover.net/1/messages.json";
const data = {
token: this.pluginConfiguration.settings.apiToken,
user: this.pluginConfiguration.settings.userKey,
title,
message,
priority: 2,
retry: 30,
expire: 1,
};
axios
.post(url, data)
.then((res) => {
console.log(`Status: ${res.status}`);
console.log("Student Info: ", res.data);
})
.catch((err) => {
console.error(err);
});
}
}
export default DomustoPushover;