node-red-contrib-alexa-remote2-applestrudel
Version:
node-red nodes for interacting with alexa
284 lines (278 loc) • 11.2 kB
HTML
<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>