简体   繁体   English

AWS + API网关+ Lambda + Node.js在Google上的操作ApiAiApp

[英]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. 我想在通过API网关调用的Lambda函数中使用Google动作包和ApiAiApp类。 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. 所有管道都可以正常工作,并且我可以返回手动构建的响应,但是我真的更喜欢在Node.js Lambda函数中使用ApiAiApp对象。

I can also get it working fine using Firebase to host the function. 我还可以使用Firebase托管该功能,使其正常运行。

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 Firebase的入口点是

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

and I can just pass the request + response to the ApiAiApp constructor and all is sweet 我可以将请求+响应传递给ApiAiApp构造函数,一切都很好

Where as in Lambda it is 就像在Lambda一样

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? 我如何将事件转换为请求+响应,以便在lambda函数中调用相同的ApiAppApp构造函数?

TL:DR - How can I call the actions-on-google ApiAiApp constructor in a Lambda function? TL:DR-如何在Lambda函数中调用Google Actions-on-Google ApiAiApp构造函数?

Seems like you could use awslabs/aws-serverless-express to create the Express-like request/response objects that ApiAiApp expects. 似乎您可以使用awslabs / aws-serverless-express创建ApiAiApp期望的类似Express的请求/响应对象。

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. 似乎您更想做类似Express Express的结果/响应之类的事情。 I see some modules for this ( lykmapipo/mock-express-response ). 我看到了一些模块( lykmapipo / mock-express-response )。

You could setup your API-Gateway integration how they show here , which gives you the request. 您可以设置API-Gateway集成在此处的显示方式,从而向您发出请求。 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. Idk,无论哪种方式都会漂浮您的船。 Admittedly I don't know anything about APIAiApp or running Express in Lambda, my lambs are all API stuff and not user facing. 诚然,我对APIAiApp或在Lambda中运行Express一无所知,我的羔羊都是API的东西,而不是面向用户的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google行动上项目实现在Node.js中实现isRequestFromAssistant - Implementing isRequestFromAssistant in Node.js on actions-on-google project fulfillment AWS Lambda 与 API 网关和 Node.js 返回 HTTP 50 - AWS Lambda with API gateway and Node.js returning HTTP 502 AWS API 网关与 Lambda HTTP GET 请求(Node.js)502 错误网关 - AWS API Gateway with Lambda HTTP GET Request (Node.js) 502 Bad Gateway 如何使用 actions-on-google node.js 库处理插槽填充 - how to handle slot filling using actions-on-google node.js library 使用 node.js 从 AWS Lambda 将自定义错误传回 AWS API Gateway - Passing custom errors back to AWS API Gateway from AWS Lambda using node.js 将Node.js API与AWS Lambda混合 - Mixing Node.js API with AWS Lambda AWS Lambda/API 网关 - 传递 ID 以使用 node.js 在 mysql 中删除一行 - AWS Lambda/API Gateway - Pass an ID to delete a row in mysql with node.js 如何从AWS Lambda Node.js 8.10异步函数向AWS API网关返回net.socket数据? - How to return net.socket data from AWS Lambda Node.js 8.10 async function to AWS API gateway? 使用API​​网关反应调用Node.js PUT Lambda函数 - React calling a Node.js PUT Lambda function with API Gateway 如何解析AWS Lambda(node.js)中通过AWS Api网关上传的数据的内容类型? - How to parse the Content-type of the data being uploaded through aws Api gateway in aws Lambda (node.js)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM