Skip to content

Commit

Permalink
Add textCommand to alexa-remote-routine node
Browse files Browse the repository at this point in the history
Co-authored-by: mbalduccini
  • Loading branch information
bbindreiter committed Jun 7, 2021
1 parent df88bd3 commit ab48b11
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nodes/alexa-remote-routine.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ <h3><strong>Info</strong></h3>
<p><strong>Speak At Volume</strong> or <strong>Volume</strong> with the <em>Add</em> mode can only change the volume
if the echo has recently been active playing music!</p>
</li>
<li>
<p><strong>Text Command</strong> allows for sending anything you would otherwise say to Alexa (more details <a href="https://github.com/thorsten-gehrig/alexa-remote-control">here</a>)</p>
</li>
<li>
<p>With the <strong>Custom</strong> option, you can feed in a routine node as js object for completely dynamic
routines. The objects can look like this:</p>
Expand Down Expand Up @@ -886,6 +889,7 @@ <h3><strong>References</strong></h3>
const options = [
['speak', '&#xf04b; Speak'], // play
['speakAtVolume', '&#xf0fe; Speak At Volume'],
['textCommand', '&#xf0e7; Text Command'], // bolt
['wait', '&#xf017; Wait'], // clock-o
['stop', '&#xf04d; Stop'], // stop
['prompt', '&#xf27a; Prompt'], // commenting
Expand Down Expand Up @@ -1028,6 +1032,11 @@ <h3><strong>References</strong></h3>
return () => ({ type: type.arSelect('value') });
}
groups.right.speakAtVolume = groups.right.speak;
groups.right.textCommand = function(data) {
data = template(data, { text: { type: 'str', value: 'Hello from Alexa Remote!'}});
const input = arTypedInput(data.text, ['str']).appendTo(this);
return () => ({ text: input.arTypedInput('data') });
}
groups.right.wait = function(data) {
data = template(data, { time: { type: 'num', value: '1' }});
const type = arTypedInput(data.time, ['num']).appendTo(this);
Expand Down Expand Up @@ -1246,6 +1255,7 @@ <h3><strong>References</strong></h3>
groups.bottom.prompt = common.bottom.group.deviceList(false);
groups.bottom.phrase = common.bottom.group.deviceList(false);
groups.bottom.sound = common.bottom.group.deviceList(false);
groups.bottom.textCommand = common.bottom.group.deviceList(false);
groups.bottom.volume = function(data) {
data = template(data, { mode: { type: 'str', value: 'set' }, devices: undefined });
const mode = arTypedInputOrSelect(data.mode || 'set', ['set', 'add']);
Expand Down
36 changes: 36 additions & 0 deletions nodes/alexa-remote-routine.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,42 @@ module.exports = function (RED) {
});
}
}
case 'textCommand': {
if (!Array.isArray(node.payload.devices)) {
const single = node.payload.devices || node.payload.device;
node.payload.devices = single ? [single] : [];
}
checkPayload({ text: '' });
const devices = findAll(node.payload.devices);

if (devices.length === 0) return undefined;
if (devices.length === 1) return {
'@type': 'com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode',
type: 'Alexa.TextCommand',
skillId: 'amzn1.ask.1p.tellalexa',
operationPayload: {
deviceType: devices[0].deviceType,
deviceSerialNumber: devices[0].serialNumber,
locale: locale,
customerId: devices[0].deviceOwnerCustomerId,
text: node.payload.text
}
};

return await nativizeNode({
type: 'node',
payload: {
type: 'parallel',
children: devices.map(device => ({
type: 'textCommand',
payload: {
text: node.payload.text,
device: device,
}
}))
}
});
}
case 'stop': {
if (!Array.isArray(node.payload.devices)) node.payload.devices = [node.payload.devices || node.payload.device];
checkPayload({ devices: [] });
Expand Down

0 comments on commit ab48b11

Please sign in to comment.