question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS Lambda Response throwing error in dialogflow when using v2

See original GitHub issue

I am returning what looks like the correct response from the AWS lambda to dialogflow but its throwing an error in dialogflow. The FULFILLMENT RESPONSE tab shows the following

  "statusCode": 200,
  "body": {
    "payload": {
      "google": {
        "expectUserResponse": true,
        "richResponse": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "AWS LAMBDA says hi"
              }
            }
          ]
        },
        "userStorage": "{\"data\":{}}"
      }
    },
    "outputContexts": [
      {
        "name": "projects/<someid>/agent/sessions/<someId>/contexts/_actions_on_google",
        "lifespanCount": 99,
        "parameters": {
          "data": "{}"
        }
      }
    ]
  }
}

but it shows an error in the FULFILLMENT STATUS tab

Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: statusCode in message google.cloud.dialogflow.v2.WebhookResponse.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
hoklai1997commented, Jun 19, 2018

I got it working:

const {
    dialogflow,
    BasicCard,
    BrowseCarousel,
    BrowseCarouselItem,
    Button,
    Carousel,
    Image,
    LinkOutSuggestion,
    List,
    MediaObject,
    Suggestions,
    SimpleResponse,
    Table,
} = require('actions-on-google');
 
const app = dialogflow() 
 
app.intent('test', (conv, params) => {
    conv.ask(new SimpleResponse({
        speech: "WORKING!!!",
        text: "GOT IT WORKING YOU HANDSOME BASTARD"
    }))
});
 
app.fallback((conv) => {
    conv.ask(new SimpleResponse({
        speech: "I'm sorry, I didn't catch that",
        text: "I'm sorry, I didn't catch that"
    }));
}); 
 
exports.handler = function(event, context, callback) {
    app.handler(event, {}).then((res) => {
        if (res.status != 200) {
            callback(null, {"fulfillmentText": `I got status code: ${res.status}`});
        } else {
            callback(null, res.body);
        }
    }).catch((e) => {
    callback(null, {"fulfillmentText": `There was an error\n${e}`});
    });
}; 

The fulfillmentText callbacks are my error logs here

Just so you know, since I’m using SimpleResponse, the dialogflow test window doesn’t display anything when it runs succesfully. You can either go into the Diagnostic Info to take a look, or open up the simulator and it should be working. Good Luck!

1reaction
rahul71commented, Jun 15, 2018

@hoklai1997 if you use my code above it almost works…as in runs the code but does not return correctly. I did have to add the following body mapping template in the Integration Request of the API gateway. The response seems to be sent back except dialogflow does not recognize it and throws the statusCode error. Just doing something wrong and as much as I like hacking this thing the documentation for lambda is not very good (yet).

Request Body Passthrough: When there are no templates defined (recommended) Content-Type: application/json and when you click on the application/json I have the following template

##  This template will pass through all parameters including path, querystring, header, stage variables, and context through to the integration endpoint via the body/payload
#set($allParams = $input.params())
{
"body" : $input.json('$'),
 "headers": {
        #foreach($param in $input.params().header.keySet())
        "$param": "$util.escapeJavaScript($input.params().header.get($param))"
        #if($foreach.hasNext),#end
        #end
    },
"params" : {
#foreach($type in $allParams.keySet())
    #set($params = $allParams.get($type))
"$type" : {
    #foreach($paramName in $params.keySet())
    "$paramName" : "$util.escapeJavaScript($params.get($paramName))"
        #if($foreach.hasNext),#end
    #end
}
    #if($foreach.hasNext),#end
#end
},
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
    #if($foreach.hasNext),#end
#end
},
"context" : {
    "account-id" : "$context.identity.accountId",
    "api-id" : "$context.apiId",
    "api-key" : "$context.identity.apiKey",
    "authorizer-principal-id" : "$context.authorizer.principalId",
    "caller" : "$context.identity.caller",
    "cognito-authentication-provider" : "$context.identity.cognitoAuthenticationProvider",
    "cognito-authentication-type" : "$context.identity.cognitoAuthenticationType",
    "cognito-identity-id" : "$context.identity.cognitoIdentityId",
    "cognito-identity-pool-id" : "$context.identity.cognitoIdentityPoolId",
    "http-method" : "$context.httpMethod",
    "stage" : "$context.stage",
    "source-ip" : "$context.identity.sourceIp",
    "user" : "$context.identity.user",
    "user-agent" : "$context.identity.userAgent",
    "user-arn" : "$context.identity.userArn",
    "request-id" : "$context.requestId",
    "resource-id" : "$context.resourceId",
    "resource-path" : "$context.resourcePath"
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webhook error on getting response from dialogflow web hook ...
The expected behaviour is to get the response in the AoG simulator but I'm getting error instead. Any help would be much appreciated....
Read more >
Handle Lambda errors in API Gateway - AWS Documentation
If there is no match, API Gateway returns the error as a default response or throws an invalid configuration exception if no default...
Read more >
Workflow Monitoring -Dialog Flow and AWS Lambda
In this tutorial, we going to connect Google Assistant to Amazon AWS through Dialog Flow. The goal is to make a program that...
Read more >
Third-Party Bots — Bot Conversation Errors
This error is thrown if the response of the AI Vendor does not contain any messages and the provided actions are not supported...
Read more >
Dialogflow | Programmatic Ponderings
Using the Training tab in the Dialogflow console, we can train our model by ... Google Cloud Functions are analogous to Amazon's AWS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found