1

我想在 AWS Lambda 中为我的 Google Assistant 设置我的完整功能。我正在使用actions-on-googlenpm 包。要创建一个ApiAiApp({req,res}我需要一个 http 请求和响应对象。

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

exports.handler = function(event, context, callback) {
    const apiAiApp = new ApiAiApp({req:<REQUEST>, res:<RESPONSE>});
}

我如何翻译event, context, callback<REQUEST>and <RESPONSE>

(我不相信我需要这里的上下文)

4

1 回答 1

1

我遇到了同样的问题,最后我通过项目“claudia.js”解决了这个问题,该项目提供了一些代码来生成一个简单的代理,允许在 AWS Lambda 上托管快速应用程序。 https://github.com/claudiajs/example-projects/tree/master/express-app-lambda

https://claudiajs.com/tutorials/serverless-express.html

提示:您最终会得到两个“应用程序”,例如,如果您使用 Dialogflow 中的完整填充中的 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
于 2017-11-04T00:32:21.710 回答