Aws lambda 在AWS Lambda上运行ApiAi节点应用程序

Aws lambda 在AWS Lambda上运行ApiAi节点应用程序,aws-lambda,actions-on-google,google-assistant-sdk,api-ai,dialogflow-es,Aws Lambda,Actions On Google,Google Assistant Sdk,Api Ai,Dialogflow Es,我想在AWS Lambda为我的谷歌助手设置我的完整胶片。 我正在使用google上的操作npm包。 要创建apaiapp({req,res},我需要一个http请求和响应对象 但是,lambda回调提供了一组不同的参数: exports.handler = function(event, context, callback) { const apiAiApp = new ApiAiApp({req:<REQUEST>, res:<RESPONSE>}); }

我想在AWS Lambda为我的谷歌助手设置我的完整胶片。 我正在使用google上的
操作
npm包。 要创建
apaiapp({req,res}
,我需要一个http请求和响应对象

但是,lambda回调提供了一组不同的参数:

exports.handler = function(event, context, callback) {
    const apiAiApp = new ApiAiApp({req:<REQUEST>, res:<RESPONSE>});
}
exports.handler=函数(事件、上下文、回调){
const apaiapp=新的apaiapp({req:,res:});
}
如何将
事件、上下文、回调
转换为


(我不认为我需要这里的上下文)

我也面临同样的问题,最后我通过“claudia.js”项目解决了它,该项目提供了一些代码来生成一个简单的代理,允许在AWS Lambda上托管express应用程序。

提示:您最终会得到两个“应用程序”,例如,如果您使用Dialogflow中fullfillment中的firebase示例,则需要重命名一个,以避免冲突

'use strict';

const googleAssistantRequest = 'google'; // Constant to identify Google Assistant requests
const express = require('express');
const app = express(); 
const DialogflowApp = require('actions-on-google').DialogflowApp; // Google Assistant helper library
const bodyParser = require('body-parser');
var endpoint = "..."; // name of AWS endpoint aka as "Resource path" in API Gateway Trigger setup

...

const urlencodedParser = bodyParser.json({ extended: false });
app.post('/'+ endpoint, urlencodedParser,  (request, response) => {
    console.log('Request headers: ' + JSON.stringify(request.headers));
    console.log('Request body: ' + JSON.stringify(request.body));

    // An action is a string used to identify what needs to be done in fulfillment
    let action = request.body.result.action; // https://dialogflow.com/docs/actions-and-parameters


    ...

    const appDialogFlow = new DialogflowApp({request: request, response: response});

    // Create handlers for Dialogflow actions as well as a 'default' handler
    const actionHandlers = {
        ...
    };

    ...
    // If undefined or unknown action use the default handler
    if (!actionHandlers[action]) {
        action = 'default';
    }

    // Run the proper handler function to handle the request from Dialogflow
    actionHandlers[action]();

    ... some helper functions, etc ...

});

//app.listen(3000) // <-- comment this line out from your app 
module.exports = app;  // <-- link to the proxy that is created viy claudia.js
“严格使用”;
const googleAssistantRequest='google';//标识google助手请求的常量
const express=require('express');
常量app=express();
const DialogflowApp=require('actions-on-google')。DialogflowApp;//谷歌助手助手库
const bodyParser=require('body-parser');
var endpoint=“…”;//API网关触发器设置中作为“资源路径”的AWS端点的名称
...
const urlencodedParser=bodyParser.json({extended:false});
app.post(“/”+端点,urlencodedParser,(请求,响应)=>{
log('Request headers:'+JSON.stringify(Request.headers));
log('Request body:'+JSON.stringify(Request.body));
//action是一个字符串,用于标识在实现过程中需要执行的操作
let action=request.body.result.action;//https://dialogflow.com/docs/actions-and-parameters
...
const-appDialogFlow=new-DialogflowApp({request:request,response:response});
//创建Dialogflow操作的处理程序以及“默认”处理程序
const actionHandlers={
...
};
...
//如果未定义或未知操作,请使用默认处理程序
如果(!actionHandlers[action]){
动作='默认';
}
//运行适当的处理程序函数来处理来自Dialogflow的请求
动作处理程序[动作]();
…一些辅助函数等。。。
});

//app.listen(3000)//AoG客户端库使用
express
Node.JS对象。要使用Lambda,您可能需要找到一些翻译指南。