jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.67k stars 310 forks source link

Error: 'userData' as NULL when using DynamoDB config #161

Closed availit closed 6 years ago

availit commented 6 years ago

I'm submitting a...

Expected Behavior

DynamoDB connection to update table with userData

Current Behavior

I receive the error log on the launch request of my Alexa app. It throws again on the request timeout. The local DB file works for testing.

When including the database object in config settings of app.js the error pops up when calling a launch request

db: {
        type: 'dynamodb',
        tableName: 'NewTable'
    }

Error log

TypeError: Cannot read property 'userData' of null
    at platform.jovo.db.loadObject (C:\~\node_modules\jovo-framework\lib\user.js:39:33)
    at DynamoDb.checkResourceNotFound (C:\~\node_modules\jovo-framework\lib\integrations\db\dynamoDb.js:328:13)
    at Response.<anonymous> (C:\~\node_modules\jovo-framework\lib\integrations\db\dynamoDb.js:209:22)

Your Environment

jankoenig commented 6 years ago

Hi @availit. Thanks, we're taking a look at this

aswetlow commented 6 years ago

Hey @availit ! How did you create your table?

Could you please log the error after line 34 in /node_modules/jovo-framework/lib/user.js

...
this.platform.jovo.db().loadObject((error, data) => {
console.log(error);
...
availit commented 6 years ago

Hi @aswetlow! I was trying to create my table by giving it a name in the config and having jovo create it for me, at least that's what @jankoenig had mentioned to me is possible. The local DB file works great btw..

Here is the error I got to log after making a launch request:

ConfigError: Missing region in config
    at Request.VALIDATE_REGION (C:\Users\~\node_modules\aws-sdk\lib\event_listeners.js:91:45)
    at Request.callListeners (C:\Users\~\node_modules\aws-sdk\lib\sequential_executor.js:105:20)
    at callNextListener (C:\Users\~\node_modules\aws-sdk\lib\sequential_executor.js:95:12)
    at C:\Users\~\node_modules\aws-sdk\lib\event_listeners.js:85:9
    at finish (C:\Users\~\node_modules\aws-sdk\lib\config.js:320:7)
    at C:\Users\~\node_modules\aws-sdk\lib\config.js:338:9
    at SharedIniFileCredentials.get (C:\Users\~\node_modules\aws-sdk\lib\credentials.js:126:7)
    at getAsyncCredentials (C:\Users\~\node_modules\aws-sdk\lib\config.js:332:24)
    at Config.getCredentials (C:\Users\~\node_modules\aws-sdk\lib\config.js:352:9)
    at Request.VALIDATE_CREDENTIALS (C:\Users\~\node_modules\aws-sdk\lib\event_listeners.js:80:26)
  message: 'Missing region in config',
  code: 'ConfigError',
  time: 2018-05-29T15:35:40.998Z
jankoenig commented 6 years ago

Hi @availit, are you sure you're running it on Lambda? The paths (C:\Users\~\node_modules\aws-sdk\lib\event_listeners.js:91:45) indicate that you're running it on your computer.

If you're running it on your computer, you need to add the AWS credentials, like this:

let awsConfig = {
    accessKeyId: 'yourAccessKeyId',
    secretAccessKey: 'yourSecretAccessKey', 
    region:  'yourRegion',
};

// Using the constructor
const config = {
    db: {
        type: 'dynamodb',
        tableName: 'TableName',
        awsConfig: awsConfig,
    },
    // Other configurations
};

Take a look here https://www.jovo.tech/framework/docs/databases#dynamodb-for-apps-not-hosted-on-aws-lambda

availit commented 6 years ago

Hey @jankoenig oops sorry about that, I meant to test it on AWS.. let me try again.

jankoenig commented 6 years ago

OK, make sure to switch the endpoint of your Skill to the Lambda ARN then instead of the Jovo Webhook URL

availit commented 6 years ago

Okay I just tested it on AWS and it's not creating a table. No matter what I ask or say to my skill it just hits the Unhandled function until I comment out the DB config in the app.js file. I can't find the log inside AWS for the user.js @aswetlow mentioned earlier? Sorry I'm a noob at aws lambda

jankoenig commented 6 years ago

You can find them in Cloudwatch https://console.aws.amazon.com/cloudwatch

availit commented 6 years ago

I cannot find any errors from that user.js file.. Although the user object is getting logged and I can't find anything in my code that's doing it :/

AlexaUser {
platform: 
AlexaSkill {
domain: null,
_events:
{}
,
_eventsCount: 0,
_maxListeners: undefined,
jovo: 
Jovo {
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
app: [Object],
config: [Object],
responseSent: true,
routing: [Object],
handler: [Object],
event: [Object],
context: [Object],
callback: [Function: callback],
response: [Function: callback],
requestObj: [Object],
type: 'lambda',
platform: [Circular],
userObj: [Circular],
speech: [Object],
reprompt: [Object],
inputs:
{}
},
request: 
LaunchRequest {
version: '1.0',
session: [Object],
context: [Object],
request: [Object] },
response: AlexaResponse { responseObj: [Object] },
nlu: AlexaNLU { request: [Object] } },
config: 
{ lastUsedAt: true,
sessionsCount: true,
createdAt: true,
requestHistorySize: 0,
devices: false },
metaData:
{}
,
data:
{}
,
isNew: false,
alexaList: AlexaList { permissionToken: undefined },
alexaDeviceAddress: 
AlexaDeviceAddress {
permissionToken: undefined,
deviceId: 'amzn1.ask.device.AHHZ47YLXCETCL5KLSTA6SPO5JE2RA47JMSQ4OQKY4H73PWHVYAKFRODPDDYUKPYWZXI7BAVE5LMU753CNW2VLLDKCIGMJJ6VQG7JLUEAS3ZAB53WZFIMNE666643TNPH3TPVN2IINMZSZUBUEMXSQJYRHUQ',
apiEndpoint: 'https://api.amazonalexa.com' } }
availit commented 6 years ago

Another interesting thing, I thought it was going to Unhandled but it just goes to the LAUNCH intent no matter what I say..

The Request:

{
    "type": "IntentRequest",
    "requestId": "amzn1.echo-api.request.e6517939-caa8-42c4-be83-920a14326244",
    "timestamp": "2018-05-29T16:50:42Z",
    "locale": "en-US",
    "intent": {
        "name": "SelectLocationIntent",
        "confirmationStatus": "NONE",
        "slots": {
            "store": {
                "name": "store",
                "value": "pla",
                "resolutions": {
                    "resolutionsPerAuthority": [
                        {
                            "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.cda18187-d800-4c43-b382-c080898dba79.centerCode",
                            "status": {
                                "code": "ER_SUCCESS_MATCH"
                            },
                            "values": [
                                {
                                    "value": {
                                        "name": "PLA",
                                        "id": "a9ae8dcc04ef529de1153d5731c4d65c"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "confirmationStatus": "NONE"
            }
        }
    },
    "dialogState": "STARTED"
}

The Response:

2018-05-29T16:50:42.258Z    6c64ddc7-6360-11e8-bb62-0980c87d606c
{
    "version": "1.0",
    "response": {
        "shouldEndSession": false,
        "outputSpeech": {
            "type": "SSML",
            "ssml": "<speak>hello! welcome! what would you like to do?</speak>"
        },
        "reprompt": {
            "outputSpeech": {
                "type": "SSML",
                "ssml": "<speak>please say a command.</speak>"
            }
        }
    },
    "sessionAttributes": {}
}
jankoenig commented 6 years ago

We added some additional info here: https://www.jovo.tech/guides/add-dynamodb-database Let us know if your issue "persists" (pun intended)