[英]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.