Plugins allow you to modify how the StateMachineSkill handles an alexa event. When a plugin is registered it will use the different hooks in your skill to add functionality. If you have several skills with similar behavior then your answer is to create a plugin.
After instantiating a StateMachineSkill you can register plugins on it. Built in plugins can be accessed through Voxa.plugins
'use strict';
const Voxa = require('voxa');
const Model = require('./model');
const views = require('./views'):
const variables = require('./variables');
const skill = new Voxa({ Model, variables, views });
Voxa.plugins.replaceIntent(skill);
Stores the state transitions for every alexa event in an array.
const alexa = require('alexa-statemachine');
alexa.plugins.stateFlow.register(skill)
skill.onBeforeReplySent((alexaEvent) => {
console.log(alexaEvent.flow.join(' > ')); // entry > firstState > secondState > die
});
It allows you to rename an intent name based on a regular expression. By default it will match /(.*)OnlyIntent$/
and replace it with $1Intent
.
const skill = new Voxa({ Model, variables, views });
Voxa.plugins.replaceIntent(skill, { regex: /(.*)OnlyIntent$/, replace: '$1Intent' });
Voxa.plugins.replaceIntent(skill, { regex: /^VeryLong(.*)/, replace: 'Long$1' });
A good practice is to isolate an utterance into another intent if it contains a single slot. By creating the OnlyIntent, Alexa will prioritize this intent if the user says only a value from that slot.
Let's explain with the following scenario. You need the user to provide a zipcode. You would have an intent called ZipCodeIntent
. But you still have to manage if the user only says a zipcode without any other words. So that's when we create an OnlyIntent. Let's call it ZipCodeOnlyIntent
.
Our utterance file will be like this:
ZipCodeIntent here is my {ZipCodeSlot}
ZipCodeIntent my zip is {ZipCodeSlot}
...
ZipCodeOnlyIntent {ZipCodeSlot}
But now we have two states which are basically the same. Replace Intent plugin will rename all incoming requests intents from ZipCodeOnlyIntent
to ZipCodeIntent
.
It logs a CloudWatch metric when the skill catches an error or success execution.
const AWS = require('aws-sdk');
const skill = new Voxa({ Model, variables, views });
const cloudWatch = new AWS.CloudWatch({});
const eventMetric = {
MetricName: 'Caught Error', // Name of your metric
Namespace: 'SkillName' // Name of your skill
};
Voxa.plugins.cloudwatch(skill, cloudWatch, eventMetric);
It accepts an adapter to autoload info into the model object coming in every alexa request.
const skill = new Voxa({ Model, variables, views });
Voxa.plugins.autoLoad(skill, { adapter });