简体   繁体   中英

AWS + API Gateway + Lambda + Node.js actions-on-google ApiAiApp

I would like to use the action-on-google package and the ApiAiApp class in my Lambda function that is called from an API Gateway. All the plumbing works fine and I can return a manually constructed response fine, but I would really prefer to use the ApiAiApp object in my Node.js Lambda function.

I can also get it working fine using Firebase to host the function.

Please forgive my ignorance on this type of development, but no manner of searching seems to give me the solution I need.

The entry point on Firebase is

exports.myTip = functions.https.onRequest((request, response) => {

and I can just pass the request + response to the ApiAiApp constructor and all is sweet

Where as in Lambda it is

exports.handler = function(event, context, callback)

How can I convert the event to a request + response in order to call the same ApiAppApp constructor in the lambda function?

TL:DR - How can I call the actions-on-google ApiAiApp constructor in a Lambda function?

Seems like you could use awslabs/aws-serverless-express to create the Express-like request/response objects that ApiAiApp expects.

Eh, that doesn't look as useful as I thought at first. Seems more like you'll want to do something like mocking Express-like result/response. I see some modules for this ( lykmapipo/mock-express-response ).

You could setup your API-Gateway integration how they show here , which gives you the request. Then your lamb might look something like this:

const MockExpressResponse = require('mock-express-response');
exports.handler = (event, context, callback) => {
  const response = new MockExpressResponse({
    request: event,
  });
  const app = new ApiAiApp({ request: event, response });
  // do stuff with app
  callback(null, response._getString());
};

Idk, which ever way floats your boat. Admittedly I don't know anything about APIAiApp or running Express in Lambda, my lambs are all API stuff and not user facing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM