How to access intent slot values using handlerInput in ASK-SDK v2
See original GitHub issueI’m creating a basic calculator skill using ASK-SDK v2. I’m not sure how to get the slot values provided by the user into the Lambda code with the new version. I was able to make it work with the older version.
Conversation User: Open calculate Alexa: You can ask me to add, subtract, multiply and divide User: Add two and three Alexa: Sum of 2 and 3 is 5
Below is my IntentSchema
{
"interactionModel": {
"languageModel": {
"invocationName": "calculate",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "AddIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"Sum of {numA} and {numB}",
"add {numA} and {numB}"
]
},
{
"name": "SubIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"difference between {numA} and {numB}",
"subtract {numA} from {numB}"
]
},
{
"name": "ProductIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"multiply {numA} and {numB}",
"product of {numA} and {numB}"
]
},
{
"name": "DivideIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"divide {numB} by {numA}",
"divide {numA} by {numB}"
]
},
{
"name": "ExponentialIntent",
"slots": [
{
"name": "numA",
"type": "AMAZON.NUMBER"
},
{
"name": "numB",
"type": "AMAZON.NUMBER"
},
{
"name": "numC",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"{numA} raised to the power of {numB} by {numC}",
"{numA} raised to the power {numB}"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
}
],
"types": []
}
}
}
I’m adding the addintenthandler here. Please tell me if the approach I’m using to get the slot values from the intent is correct or if I should use sessionattributes
const AddIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AddIntent';
},
handle(handlerInput) {
var output1 = "";
var num1 = handlerInput.resuestEnvelope.request.intent.slots.numA.value;
var num2 = handlerInput.resuestEnvelope.request.intent.slots.numB.value;
if((num1)&&(num2)){
output1 = 'The sum of ' +num1+ ' and ' +num2+ ' is ' + (num1+num2);
}
else {
output1 = 'Enter valid number';
}
const speechText = output1;
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
Alexa responds with “Unable to process requested skill response” Any help is welcome
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to get custom intent slot values using handlerInput in ...
Update: there are now built-in functions in the SDK for this: Alexa.getSlotValue() (returns the string value) and getSlot() (returns Slot ...
Read more >Processing Request | Alexa Skills Kit - Amazon Developer
Use the Alexa Skills Kit SDK for Node.js (ASK SDK for Node.js) to process requests that your Alexa skill receives from Alexa.
Read more >Create A Custom Skill To Extract Values From A Slot In Alexa
In this article, I am going to demonstrate how to create a custom Alexa skill on Alexa Hosted node.js server to extract slot...
Read more >Core — Alexa Skills Kit SDK for Python 1.13.0 documentation
handler_input (HandlerInput) – Handler Input instance with Request Envelope containing Request. Returns: Boolean value that tells the dispatcher if the current ...
Read more >Alexa Skills cannot get my slot value to be spoken - Forums
This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK (v2). * Please visit https://alexa.design/cookbook for ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
it might also be because the value that Alexa is getting is ‘2’ and ‘3’ as strings. Use parseInt to convert to number and then add.
Hi @SahilS-Hexaware ,
Thanks for reaching out. The actual user utterance won’t be available in the Alexa request. When users say something to Alexa device, the user utterance will be sent to Alexa NLU service and it will be translated into corresponding user intent based on the skill’s interaction model. After NLU process, Alexa will then send the Alexa request to your skill lambda code, and Alexa request only contains the mapped intent info without the original user utterance. Here is the Alexa Request format.
So, currently there’s no approach for a skill to retrieve the user utterance. If you think it would really help developing a better skill, you could post this feature at Alexa forums and vote for it 😃 I’ve also found a similar request here: https://forums.developer.amazon.com/questions/95698/how-to-get-full-user-utterance.html
Thanks, Shen