Link to home
Start Free TrialLog in
Avatar of Daniel Williams
Daniel Williams

asked on

Trying to grab intent from Amazon Alexa

Hello!

I'm new to building an Amazon Alexa skill and the course I'm taking seems to be a bit outdated. In the course, it says to use event.request.intent to get the intent of the user. However, I'm getting an undefined error. Should I be using something else to get the intent?

exports.handler = function(event, context) {
    console.log(event.request.intent);   
}

Open in new window


Produces this error
TypeError: Cannot read property 'intent' of undefined
Screen-Shot-2018-11-09-at-2.07.39-PM.png
Avatar of leakim971
leakim971
Flag of Guadeloupe image

the error say "event.request" is null

most of this call run asynchronously and you program end before being able to read the value
we need to see more code tp help you
Avatar of Daniel Williams
Daniel Williams

ASKER

There's really not much to it inside of the Alexa skill. If I comment out the console.log() statement, it works okay and I get the statement "Tractors are big, green, and cool. I need to know if there's a different way to get the request intent.

exports.handler = function(event, context) {
    //console.log(event.request.intent);   
    
    context.done(null, {
       "version": "1.0",
       "response": {
           "outputSpeech": {
               "type": "PlainText",
               "text": "Tractors are big, green, and cool."
           }
       }
    });
}

Open in new window

Look at the entire event object then.

Try changing line 2 to
console.log(event);

Open in new window

It could be that they are no longer sending the intent back in the payload.
Event request intent is probably a json object, I'm not sure that would console log properly. IIRC you may need to stringify it:
https://developer.amazon.com/blogs/alexa/post/37da1dc8-08a1-4a65-a964-762517f3ddd7/why-console-log-is-your-friend
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.