Virtual Alexa
Interact with skills intuitively and programmatically.
Virtual Alexa allows for interacting with skills programmatically.
The core Virtual Alexa API provides several routines - the two most essential ones: * utter: Generates JSON as if the user said the given phrase * intend: Generates JSON as if the given intent was uttered
This library allows for easy testing of skills.
You can use it for:
- Unit-testing - ensuring individual routines work correctly
- Regression testing - ensuring the code as a whole works properly
npm install virtual-alexa --save-dev
Easy! Just add a line of code like so:
const va = require("virtual-alexa");
const alexa = va.VirtualAlexa.Builder()
.handler("index.handler") // Lambda function file and name
.intentSchemaFile("./speechAssets/IntentSchema.json") // Path to IntentSchema.json
.sampleUtterancesFile("./speechAssets/SampleUtterances.txt") // Path to SampleUtterances
.create();
alexa.utter("play").then((payload) => {
console.log("OutputSpeech: " + payload.response.outputSpeech.ssml);
// Prints out returned SSML, e.g., "<speak> Welcome to my Skill </speak>"
});
Here's a more in-depth example, in the form of a Jest unit test:
test("Plays once", (done) => {
alexa.utter("get started").then((payload) => {
expect(payload.response.outputSpeech.ssml).toContain("What is the search term for it");
return alexa.utter("incorrect guess");
}).then((payload) => {
expect(payload.response.outputSpeech.ssml).toContain("Nice try");
return alexa.utter("incorrect guess");
}).then((payload) => {
expect(payload.response.outputSpeech.ssml).toContain("That is not correct");
return alexa.utter("incorrect guess");
}).then((payload) => {
expect(payload.response.outputSpeech.ssml).toContain("Goodbye");
done();
});
});
That's all there is to getting started. Take a look here for a full example:
https://github.com/bespoken/giftionary/blob/master/test/index.test.js
And read all the docs here:
https://bespoken.github.io/virtual-alexa/api/
Easy, you can open an issue here, or find us on our Gitter.
We are also on the Alexa Slack channel - @jpkbst, @jperata, @chrisramon and @ankraiza.
We look forward to hearing from you!