Create Video Skill and Lambda
Step 7: Interpret and React to Alexa Directives (VSK FTV)
- Types of Video Skill Directives
- Expectations for Reacting to Directives
- Best Practices for Coding Your Lambda Function
- Uploading the Finalized Lambda
- Next Steps
Types of Video Skill Directives
When Alexa hears voice commands from users, Alexa uses natural language processing to interpret the command and convert it into a directive sent to your Lambda function. (You won't receive the actual words users say, as these words are considered private to the user). The directives for video skills fall into several categories:
||Sent when users ask Alexa to play specific video content.|
||Sent when users ask Alexa to search for video content.|
||Sent when users request to play, stop, and navigate playback for video content.|
||Sent when users request to fast-forward (or skip) or rewind to a specific duration.|
||Sent when users request to change the channel|
||Sent when users request to start or stop recordings.|
||Sent when users request to search, cancel, or delete recordings.|
||Sent when users request to scroll right or left, page up or down, or select the item in focus.|
Each directive category can have multiple directive headers that are sent. If you look in the sample Lambda code in Step 1.3: Create the Lambda Function for Your Video Skill, you'll see these directive headers in the code. For example:
The nuances of implementing and responding to each of the above four directives are detailed in the following sections, along with information about certification and prerequisites for the directives.
index.js file from the
sample-nodejs-vsk-with-adm project again (as explained in Step 6.1: Create a Lambda Deployment Package). In this file, you will see placeholders for custom logic that you must write yourself. For example, you'll see inline comments such as these:
// Partner-specific logic to handle the the directives goes here // Code for sending directive from the lambda to the app goes here
In every place you see these notes about the need for partner-specific logic, write the logic to handle these directives. The recommended approach is to take directives received by your Lambda function (from the Video Skill API) and send these directives to your app via ADM. Any further processing can occur within your app.
index.jsfile in this
sample-nodejs-vsk-with-admapp has the payload responses corresponding to these APIs that are relevant.
For additional information, see the Alexa Client Library's Javadoc.
Expectations for Reacting to Directives
The various directives your Lambda can receive, and your expected responses and actions around those directives are detailed in Interpreting and Reacting to Directives.
Note that your app might not implement every capability within the Video Skill API. For example, changing channels might not be relevant if your app does not have channels.
Best Practices for Coding Your Lambda Function
As you update the code, note the following:
Dynamically Passing in the Registration ID: In the
sendMessageToDevice(message, context)function fetches an access token before sending a message to your app via ADM. Your app instance gets referenced through a hard-coded ADM Registration ID. In production, you should read ADM Registration IDs from directives and dynamically route messages to the correct app rather than hardcoding the ADM Registration ID into the Lambda code as shown in this file.
Responses Back to Alexa: Responses back to Alexa should not be modified, only code to process/send directives. Also note that you should send directives from your Lambda function to your app, but you should not try to send messages from your app back to the Lambda function. Success responses from your Lambda function are only meant to indicate that the message was received by Lambda, not the app.
Uploading the Finalized Lambda
After you finish writing the logic to handle the directives specified in the previous section, repeat the steps in Step 6.2: Upload the Lambda Package into AWS Lambda above to build a zip package using Node. Then upload it into your Lambda in AWS. Make sure you test and validate any code before using it in production.
Congratulations! You are now finished setting up your video skill and Lambda function. Go to the next step: Step 8: Auto-pair and Finalize Your Skill.