forked from cakebake/node-red-contrib-alexa-remote-cakebaked
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathalexa-remote-account.html
284 lines (278 loc) · 10.7 KB
/
alexa-remote-account.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
282
283
284
<script type="text/x-red" data-template-name="alexa-remote-account">
<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="Optional">
</div>
<hr>
<div class="form-row">
<label for=""> Auth Method</label>
<select id="node-config-input-authMethod" style="width: 70%;">
<option value="proxy">Proxy</option>
<option value="cookie">Cookie</option>
<option value="password">Email & Password (deprecated)</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-cookie"><i class="fa fa-coffee"></i> Cookie</label>
<input type="text" id="node-config-input-cookie" placeholder="Required">
</div>
<div class="form-row">
<label for="node-config-input-email"><i class="fa fa-user"></i> Email</label>
<input type="text" id="node-config-input-email" placeholder="Required">
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-key"></i> Password</label>
<input type="password" id="node-config-input-password" placeholder="Required">
</div>
<div class="form-row">
<label for="node-config-input-proxyOwnIp"><i class="fa fa-server"></i> This IP</label>
<input type="text" id="node-config-input-proxyOwnIp" placeholder="Required">
</div>
<div class="form-row">
<label for="node-config-input-proxyPort"><i class="fa fa-ship"></i> Port</label>
<input type="text" id="node-config-input-proxyPort" placeholder="Required">
</div>
<div class="form-row">
<label for="node-config-input-cookieFile"><i class="fa fa-file"></i> File Path</label>
<input type="text" id="node-config-input-cookieFile" placeholder="Optional">
</div>
<div class="form-row">
<label for="node-config-input-refreshInterval"><i class="fa fa-refresh"></i> Refresh</label>
<input type="text" id="node-config-input-refreshInterval" placeholder="Optional" style="width: 55%;">
<label for="node-config-input-refreshInterval" style="width: 15%; text-align: center;">days</label>
</div>
<hr>
<div class="form-row">
<label for="node-config-input-autoInit"><i class="fa fa-wrench"></i> Auto Init</label>
<select id="node-config-input-autoInit" style="width: 70%;">
<option value="on">On</option>
<option value="off">Off</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-usePushConnection"><i class="fa fa-rocket"></i> Events</label>
<select id="node-config-input-usePushConnection" style="width: 70%;">
<option value="on">On</option>
<option value="off">Off</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-autoQueryActivityOnTrigger"><i class="fa fa-rocket"></i> Auto Query Activities</label>
<select id="node-config-input-autoQueryActivityOnTrigger" style="width: 70%;">
<option value="on">On</option>
<option value="off">Off</option>
</select>
</div>
<p>Please enable Auto Query Activities only when you rely on device activity sent via Alexa Event node.</p>
<hr>
<div class="form-row">
<label for="node-config-input-alexaServiceHost"><i class="fa fa-amazon"></i> Service Host</label>
<input type="text" id="node-config-input-alexaServiceHost" placeholder="Required">
</div>
<div class="form-row">
<label for="node-config-input-pushDispatchHost"><i class="fa fa-amazon"></i> Push Dispatch Host</label>
<input type="text" id="node-config-input-pushDispatchHost" placeholder="Optional">
</div>
<div class="form-row">
<label for="node-config-input-amazonPage"><i class="fa fa-amazon"></i> Page</label>
<input type="text" id="node-config-input-amazonPage" placeholder="Required">
</div>
<div class="form-row">
<label for="node-config-input-acceptLanguage"><i class="fa fa-language"></i> Language</label>
<input type="text" id="node-config-input-acceptLanguage" placeholder="Optional">
</div>
<div class="form-row">
<label for="node-config-input-onKeywordInLanguage"><i class="fa fa-language"></i>"On" Keyword</label>
<input type="text" id="node-config-input-onKeywordInLanguage" placeholder="Optional">
</div>
<div class="form-row">
<label for="node-config-input-userAgent"><i class="fa fa-info-circle"></i> User Agent</label>
<input type="text" id="node-config-input-userAgent" placeholder="Optional">
</div>
</script>
<script type="text/x-red" data-help-name="alexa-remote-account">
<style>
table, th, td {
border-collapse: collapse;
border: 1px solid rgb(204, 204, 204);
padding: 4px 8px;
}
</style>
<p>Alexa Account configuration node.</p>
<hr>
<h3><strong>Settings</strong></h3>
<ul>
<li><strong>Auth Method</strong>
<ul>
<li><strong>Proxy</strong>
<ul>
<li>automatically captures your cookies using a proxy</li>
<li><strong>This Ip</strong> has to be the ip of the Node-RED server</li>
<li>enter a <strong>File Path</strong> to a text file (can be relative or absolute) to save the
authentication result to make following authentications automatic (for alternative ways to save
the authentication result see the <em>Alexa Init</em> node)</li>
<li><strong>Refresh</strong> is the cookie refresh interval in days</li>
</ul>
</li>
<li><strong>Cookie</strong>
<ul>
<li>login with manually entering your cookie</li>
<li><a href="get_cookie.md">How do i get my cookie?</a></li>
</ul>
</li>
<li><strong>Email & Password</strong>
<ul>
<li>deprecated, use proxy</li>
<li>works with node version 10 but not with node version 8!</li>
<li>will not work if Captcha or 2 Factor Authentication is needed</li>
</ul>
</li>
</ul>
</li>
<li><strong>Auto Init</strong>
<ul>
<li><em>on</em> to initialise the account everytime the node starts or has changed</li>
</ul>
</li>
<li><strong>Events</strong>
<ul>
<li><em>on</em> to enable events sent over WebSocket, required for Event node</li>
</ul>
</li>
<li><strong>Service Host, Page, Language</strong>
<ul>
<li>see <a href="#Setup">Setup</a></li>
</ul>
</li>
</ul>
<hr>
<h3><strong>Setup</strong></h3>
<ol>
<li>
<p>Drag an <strong>Alexa Routine</strong> node into your flow.</p>
</li>
<li>
<p>Create a new Account by pressing the edit button at the right side of the <em>Account</em> field.</p>
</li>
<li>
<p>Choose a <strong>Service Host</strong> and <strong>Page</strong> and <strong>Language</strong> depending on
your location. For example:</p>
<table>
<thead>
<tr>
<th></th>
<th>Service Host</th>
<th>Page</th>
<th>Language</th>
</tr>
</thead>
<tbody>
<tr>
<td>USA</td>
<td><a href="http://pitangui.amazon.com">pitangui.amazon.com</a></td>
<td><a href="http://amazon.com">amazon.com</a></td>
<td>en-US</td>
</tr>
<tr>
<td>UK</td>
<td><a href="http://alexa.amazon.co.uk">alexa.amazon.co.uk</a></td>
<td><a href="http://amazon.co.uk">amazon.co.uk</a></td>
<td>en-UK</td>
</tr>
<tr>
<td>GER</td>
<td><a href="http://layla.amazon.de">layla.amazon.de</a></td>
<td><a href="http://amazon.de">amazon.de</a></td>
<td>de-DE</td>
</tr>
</tbody>
</table>
</li>
<li>
<p>Set <strong>This IP</strong> to the ip of your Node-RED server</p>
</li>
<li>
<p>Enter a <strong>File Path</strong> to save the authentication result so following authentications will be
automatic.</p>
</li>
<li>
<p><em>Add</em> the new Account.</p>
</li>
<li>
<p>Deploy</p>
</li>
<li>
<p>Follow the url you see in the node status</p>
</li>
<li>
<p>Log in, wait until you see the node status <strong>ready</strong></p>
</li>
<li>
<p>Write "Hello World!" in the <em>Alexa Routine</em> node text field.</p>
</li>
<li>
<p>Select a device in the <em>Alexa Routine</em> node devices field.</p>
</li>
</ol>
<p>Now trigger the <em>Alexa Routine</em> Node with any message and your Alexa will say "Hello World!".
(Hopefully!)</p>
<hr>
<h3><strong>References</strong></h3>
<ul>
<li><a href="https://npmjs.com/package/node-red-contrib-alexa-remote2">npm</a> - the nodes npm repository</li>
<li><a href="https://github.com/586837r/node-red-contrib-alexa-remote2">GitHub</a> - the nodes GitHub repository
</li>
</ul>
</script>
<script type="text/javascript">
RED.nodes.registerType('alexa-remote-account', {
category: 'config',
credentials: {
cookie: { type: 'text' },
email: { type: 'text' },
password: { type: 'password' },
},
defaults: {
name: { required: false, value: '' },
authMethod: { required: true, value: 'proxy' },
proxyOwnIp: { required: true, value: 'localhost' },
proxyPort: { required: true, value: 3456, validate: x => 0 <= Number(x) && Number(x) <= 65535 },
cookieFile: { required: false, value: ''},
refreshInterval: { required: false, value: '3'},
alexaServiceHost: { required: true, value: 'pitangui.amazon.com' },
pushDispatchHost: { required: false, value: '' },
amazonPage: { required: true, value: 'amazon.com' },
acceptLanguage: { required: false, value: 'en-US' },
onKeywordInLanguage: { required: false, value: 'on' },
userAgent: { required: false, value: '' },
usePushConnection: { required: true, value: 'on' },
autoInit: { required: true, value: 'on' },
autoQueryActivityOnTrigger: { required: false, value: 'off' },
},
paletteLabel: 'Alexa Account',
label: function () {
return this.name || 'Alexa Account';
},
labelStyle: function () {
return this.name ? 'node_label_italic' : '';
},
oneditprepare: function () {
console.log('loaded', this);
const getInput = x => $(`#node-config-input-${x}`);
const getRow = x => getInput(x).parent();
let rowmap = {
proxy: [ getRow('proxyOwnIp'), getRow('proxyPort'), getRow('cookieFile'), getRow('refreshInterval') ],
cookie: [ getRow('cookie') ],
password: [ getRow('email'), getRow('password') ],
}
getInput('authMethod').change(event => {
Object.entries(rowmap).forEach(([k,v]) => {
k === event.target.value ? v.forEach(r => r.show()) : v.forEach(r => r.hide());
});
});
},
oneditsave: function() {
console.log('saved', this);
}
});
</script>