【问题标题】:Running an ApiAi node app on AWS Lambda在 AWS Lambda 上运行 ApiAi 节点应用程序
【发布时间】:2017-10-31 16:24:56
【问题描述】:

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

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

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

如何将event, context, callback 翻译成&lt;REQUEST&gt;&lt;RESPONSE&gt;

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

【问题讨论】:

  • AoG 客户端库使用express Node.JS 对象。要使用 Lambda,您可能需要找到一些指南来进行翻译。

标签: aws-lambda actions-on-google google-assistant-sdk api-ai dialogflow-es


【解决方案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

【讨论】:

    猜你喜欢
    • 2019-01-22
    • 2021-04-07
    • 1970-01-01
    • 2022-12-29
    • 1970-01-01
    • 2015-08-08
    • 2018-08-02
    • 2016-05-14
    • 2018-03-04
    相关资源
    最近更新 更多