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

时间:2017-08-23 23:30:35

标签: node.js aws-lambda aws-api-gateway actions-on-google

我想在我的Lambda函数中使用action-on-google包和ApiAiApp类,它是从API网关调用的。所有的管道工作正常,我可以返回一个手动构造的响应,但我真的更喜欢在我的Node.js Lambda函数中使用ApiAiApp对象。

我也可以使用Firebase来支持该功能。

请原谅我对这种发展的无知,但没有任何寻找方式似乎能为我提供所需的解决方案。

Firebase上的切入点是

iex()> list
[%{"attributes" => %{"first_name" => "Timmy 96", "last_name" => 
"Assistant"},
"id" => "bca58c53-7c6e-4281-9bc8-0c4616a30051",
"relationships" => %{"avatar" => %{"data" => %{"id" => "011300fd-ca98-
42b4-\n9561-f1cdc93d2d25",
     "type" => "pictures"}}}, "type" => "users"}]

iex()> [map] = list
[%{"attributes" => %{"first_name" => "Timmy 96", "last_name" => 
"Assistant"},
"id" => "bca58c53-7c6e-4281-9bc8-0c4616a30051",
"relationships" => %{"avatar" => %{"data" => %{"id" => "011300fd-ca98-
42b4-\n9561-f1cdc93d2d25",
     "type" => "pictures"}}}, "type" => "users"}]


iex()> get_in map, ["attributes", "first_name"]
"Timmy 96"
iex()> get_in map, ["attributes", "last_name"]
"Assistant"
iex()> get_in map, ["relationships", "avatar", "data", "id"]
"011300fd-ca98-42b4-\n9561-f1cdc93d2d25"

我可以将请求+响应传递给ApiAiApp构造函数,所有内容都很好

在Lambda中,它是

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

如何将事件转换为请求+响应,以便在lambda函数中调用相同的ApiAppApp构造函数?

TL:DR - 我如何在Lambda函数中调用action-on-google ApiAiApp构造函数?

1 个答案:

答案 0 :(得分:0)

似乎您可以使用awslabs/aws-serverless-express来创建ApiAiApp期望的类似Express的请求/响应对象。

呃,这看起来并不像我刚开始时那么有用。似乎更像是你想做一些类似于类似Express的结果/响应的事情。我看到了一些模块(lykmapipo/mock-express-response)。

您可以设置API-Gateway集成方式,以显示here,它会为您提供请求。然后你的羊羔看起来像这样:

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,它永远漂浮在你的船上。不可否认,我对APIAiApp一无所知或在Lambda中运行Express,我的羔羊都是API的东西,而不是面向用户。