I'm trying to build a backend webhook for the Google Assistant that reads records from DynamoDB.
This is my code:
// Handle the Dialogflow intent named 'trip name'.
// The intent collects a parameter named 'tripName'.
app.intent('trip name', (conv, {tripName}) => {
const dynamoDb = IS_OFFLINE === true ?
new AWS.DynamoDB.DocumentClient({
region: 'ap-south-1',
// endpoint: 'http://127.0.0.1:8080',
}) :
new AWS.DynamoDB.DocumentClient({
region: 'ap-south-1',
// endpoint: 'http://127.0.0.1:8080',
});
const params = {
TableName: ACTIVITIES_TABLE
Key: {
'name':tripName
}
};
// conv.close('error retrieving!'); THIS WORKS
dynamoDb.get(params, (error, result) => {
// conv.close('error retrieving!'); THIS DOES NOT
if (error) {
conv.close('error retrieving!');
}
else {
conv.close(JSON.stringify(result, null, 2));
}
});
});
If I were to use conv
from outside the DynamoDB function it works, but from inside it does not and return this error:
2019-08-03T03:56:22.521Z ** ERROR Error: No response has been set. Is this being used in an async call that was not returned as a promise to the intent handler?
It made me conclude that maybe I'm not allowed to access an arrow function argument from another nested arrow function?
I'm using Actions on Google Client Library.