我遇到了同样的问题,最后我通过项目“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