Skip to content

Instantly share code, notes, and snippets.

@appwiz
Last active October 15, 2018 05:15
Show Gist options
  • Save appwiz/32e81cf8b13167d00b8b9584c211513a to your computer and use it in GitHub Desktop.
Save appwiz/32e81cf8b13167d00b8b9584c211513a to your computer and use it in GitHub Desktop.
Voice Commands - NodejsApp
const { default: Amplify, API, graphqlOperation } = require('aws-amplify');
Amplify.configure({
'aws_appsync_region': 'us-west-2',
'aws_appsync_authenticationType': 'API_KEY',
'aws_appsync_graphqlEndpoint': '...',
'aws_appsync_apiKey': '...'
});
// POLYFILLS
global.WebSocket = require('ws');
const OnCommandSubscription = `
subscription onCreateColorCommand {
onCreateColorCommand {
__typename
id
color
timestamp
}
}`;
const exec = require('child_process').exec;
API.graphql(
graphqlOperation(OnCommandSubscription)
).map(({ value }) => value).subscribe({
next: (command) => {
console.log(command);
let action = command.data.onCreateColorCommand.color;
if (action === "blue") {
exec("git config --list", (err, stdout, stderr) => console.log(stdout));
} else if (action === "green") {
exec("ps auxww", (err, stdout, stderr) => console.log(stdout));
} else if (action === "yellow") {
exec("df -H", (err, stdout, stderr) => console.log(stdout));
} else {
console.log("unknown action: ", action);
}
},
error: console.error,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment