Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added textCommand #181

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- **3.10.5**
- added *textCommand* -- see https://github.com/thorsten-gehrig/alexa-remote-control
- **3.10.4**
- update dependency alexa-remote2 to 3.3.1
- **3.10.3**
Expand Down
16 changes: 15 additions & 1 deletion 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,15 @@ <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') });
//data = template(data, { type: 'regular' });
//const type = arSelect(data.type, ['regular', ['ssml', 'SSML'], 'announcement']).appendTo(this);
//channel.type = type;
//return () => ({ type: type.arSelect('value') });
}
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 @@ -1242,6 +1255,7 @@ <h3><strong>References</strong></h3>
devices: devices.arTypedInputOrInputList('data'),
});
}
groups.bottom.textCommand = common.bottom.group.deviceList(false);
groups.bottom.stop = common.bottom.group.deviceList(true);
groups.bottom.prompt = common.bottom.group.deviceList(false);
groups.bottom.phrase = common.bottom.group.deviceList(false);
Expand Down Expand Up @@ -1450,4 +1464,4 @@ <h3><strong>References</strong></h3>
console.log('saved', this.routineNode);
},
});
</script>
</script>
38 changes: 37 additions & 1 deletion 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 Expand Up @@ -663,4 +699,4 @@ module.exports = function (RED) {
});
}
RED.nodes.registerType("alexa-remote-routine", AlexaRemoteRoutine);
};
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-alexa-remote2",
"version": "3.10.4",
"version": "3.10.5",
"author": {
"name": "586837r",
"email": "[email protected]"
Expand Down