forked from node-red/node-red-nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
57-pushbullet.html
281 lines (264 loc) · 11.9 KB
/
57-pushbullet.html
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!-- PUSHBULLET CONFIG -->
<script type="text/html" data-template-name="pushbullet-config">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-apikey"><i class="fa fa-lock"></i> API-key</label>
<input type="password" id="node-config-input-apikey">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('pushbullet-config', {
category: 'config',
color: "rgb(218, 196, 180)",
defaults: {
name: {value: ""}
},
credentials: {
apikey: {type: "password"}
},
label: function() {
return this.name || "Pushbullet config";
}
});
</script>
<!-- PUSHBULLET OUT -->
<script type="text/html" data-template-name="pushbullet">
<div class="form-row">
<label for="node-input-config"><i class="fa fa-user"></i> Config</label>
<input type="text" id="node-input-config">
</div>
<div class="form-row">
<label for="node-input-deviceid"><i class="fa fa-mobile"></i> Device ID</label>
<select id="node-input-deviceid">
<option value="">All</option>
<option value="_msg_">- set from msg.deviceid -</option>
</select>
</div>
<div class="form-row">
<label for="node-input-chan"><i class="fa fa-random"></i> Channel</label>
<input type="text" id="node-input-chan" placeholder="channel name">
</div>
<div class="form-row">
<label for="node-input-pushtype"><i class="fa fa-dot-circle-o"></i> Type</label>
<select id="node-input-pushtype">
<optgroup label="Push types">
<option value="address">Address</option>
<option value="file">File</option>
<option value="link">Link</option>
<option value="list">List</option>
<option value="note">Note</option>
<option value="">- set from msg.pushtype -</option>
</optgroup>
<optgroup label="Actions">
<option value="delete">Delete push</option>
<option value="dismissal">Dismiss push</option>
<option value="updatelist">Update list</option>
</optgroup>
</select>
</div>
<div class="form-row">
<label for="node-input-title"><i class="fa fa-random"></i> Title</label>
<input type="text" id="node-input-title" placeholder="Node-RED">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="pushbullet">
<p>Uses PushBullet to push <code>msg.payload</code> to a device that has the PushBullet app installed.</p>
<p>Optionally uses <code>msg.topic</code> to set the title, if not already set in the properties.</p>
<p>Optionally uses <code>msg.pushtype</code> to set the type of the push, if not already set in the properties.</p>
<p>Optionally uses <code>msg.deviceid</code> to set the device ID, if not already set in the properties.</p>
<p>You can also push to any channels that you own either configured or via <code>msg.channel</code>.</p>
<p>The node can also <i>dismiss</i> and <i>delete</i> and <i>update</i> items in a pushed list. In this case <code>msg.data.iden</code> must be set to a valid push id, if <code>msg</code> originates from the Pushbullet input node this value is already set.</p>
<p>The old method of storing your credentials in the pushkey.js file in the directory above /node-red is deprecated.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('pushbullet',{
category: 'mobile-outpit',
defaults: {
config: {type: "pushbullet-config", required: true},
pushtype: {value:"note"},
title: {value:""},
chan: {value:"" },
name: {value:""}
},
credentials: {
deviceid: {value: ""},
pushkey: {value: ""}
},
color:"#a7c9a0",
inputs:1,
outputs:0,
icon: "bullet.png",
align: "right",
label: function() {
var self = this;
function getName(deviceid) {
if(!self.devicename && deviceid && self.config) {
$.getJSON('pushbullet/'+self.config+'/devices', function(data) {
for(var i=0; i<data.length; i++) {
if(data[i].iden === deviceid) {
self.devicename = data[i].nickname;
self.dirty = true;
RED.view.redraw();
return;
}
}
});
}
}
try {
getName(this.credentials.deviceid);
}
catch(err) {
$.getJSON('credentials/pushbullet/'+this.id, function(data) {
getName(data.deviceid);
});
}
return this.name||this.devicename||this.title||"pushbullet";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditsave: function() {
this.devicename = undefined;
},
oneditprepare: function() {
var node = this, ddConfig = $('#node-input-config'), ddDevice = $('#node-input-deviceid'), ddPushtype = $('#node-input-pushtype');
function updateDeviceList() {
if(!ddConfig.val()) {
ddDevice.children().remove();
ddDevice.append('<option value="">All</option>');
ddDevice.append('<option value="_msg_">- set from msg.deviceid -</option>');
var currentDevice;
if(node.credentials) {
currentDevice = node.credentials.deviceid;
}
if(currentDevice && currentDevice !== "_msg_") {
ddDevice.append('<option value="'+currentDevice+'">'+currentDevice+'</option>');
ddDevice.val(currentDevice);
}
}
else {
var config = RED.nodes.node(ddConfig.val()),
url = 'pushbullet/'+ddConfig.val()+'/devices';
if(config && config.credentials && config.credentials.apikey) {
url += '?apikey='+config.credentials.apikey;
}
$.getJSON(url, function(data) {
ddDevice.children().remove();
ddDevice.append('<option value="">All</option>');
ddDevice.append('<option value="_msg_">- set from msg.deviceid -</option>');
var currentDevice, addCurrent = true;
if(node.credentials) {
currentDevice = node.credentials.deviceid;
}
for(var i=0; i<data.length; i++) {
var dev = data[i];
ddDevice.append('<option value="'+dev.iden+'">'+dev.nickname+' ('+dev.kind+')</option>');
if(dev.iden === currentDevice) {
addCurrent = false;
}
}
if(currentDevice) {
if(addCurrent && currentDevice !== "_msg_") {
ddDevice.append('<option value="'+currentDevice+'">'+currentDevice+'</option>');
}
ddDevice.val(currentDevice);
}
});
}
}
}
});
</script>
<!-- PUSHBULLET IN -->
<script type="text/html" data-template-name="pushbullet in">
<div class="form-row">
<label for="node-input-config"><i class="fa fa-user"></i> Config</label>
<input type="text" id="node-input-config" placeholder="Node-RED">
</div>
<div class="form-row">
<label for="node-input-filters"><i class="fa fa-mobile"></i> Device filter</label>
<select id="node-input-filters" style="width: 60%;" multiple="multiple"></select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips">
<i class="fa fa-mobile"></i> Device filter list is multi-selectable. No selections means no filtering, i.e. all pushes are emitted.
</div>
</script>
<script type="text/html" data-help-name="pushbullet in">
<p>Receives Pushbullets from all devices. Messages contain the following data:</p>
<p><code>msg.pushtype</code>: type of message</p>
<p><code>msg.topic</code>: topic information from the push</p>
<p><code>msg.payload</code>: main content of the push</p>
<p><code>msg.data</code>: original object from the pushbullet API containing e.g. sender, receiver and message ids.</p>
<p>Pushes of type <i>link</i> and <i>file</i> will also have <code>msg.message</code> containing the message associated with the push.</p>
<p>For further details of see <a href="https://docs.pushbullet.com/stream/">Pushbullet Stream API</a> and <a href="https://docs.pushbullet.com/v2/pushes/">Pushbullet Push API</a>.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('pushbullet in',{
category: 'mobile-input',
defaults: {
config: {type: "pushbullet-config", required: true},
name: {value:""}
},
credentials: {
filters: {value: []}
},
color:"#a7c9a0",
inputs:0,
outputs:1,
icon: "bullet.png",
label: function() {
return this.name||"pushbullet";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var node = this, ddConfig = $('#node-input-config'), ddDevice = $('#node-input-filters');
function updateDeviceList() {
var config = RED.nodes.node(ddConfig.val()),
url = 'pushbullet/'+ddConfig.val()+'/devices';
if(config && config.credentials && config.credentials.apikey) {
url += '?apikey='+config.credentials.apikey;
}
$.getJSON(url, function(data) {
var currentDevices = [], addDevices = [];
if(node.credentials && node.credentials.filters) {
currentDevices = node.credentials.filters;
addDevices = node.credentials.filters.splice();
}
var idx;
ddDevice.children().remove();
for(var i=0; i<data.length; i++) {
var dev = data[i];
ddDevice.append('<option value="'+dev.iden+'">'+dev.nickname+' ('+dev.kind+')</option>');
idx = addDevices.indexOf(dev.iden);
if (idx > -1) {
addDevices.splice(idx, 1);
}
}
for(var j=0;j<addDevices.length;j++) {
ddDevice.append('<option value="'+addDevices[j]+'">'+addDevices[j]+'</option>');
}
ddDevice.val(currentDevices);
});
}
ddConfig.change(function() {
if(ddConfig.val() && ddConfig.val() !== "_ADD_") {
updateDeviceList();
}
});
}
});
</script>