使用无服务器创建 dialogflow v2 项目

creating dialogflow v2 project with serverless

尝试 运行 新的 AWS/Serverless/Dialogflow 项目时遇到问题。我确信这很简单,我只是没有看到。

步骤

为了完整起见,这里是我的serverless.yml。 (我手动创建了 API 网关,因为无服务器创建了 lambda-proxy,我没有查看其他配置。)

service:
  name: test-lambda

# Add the serverless-webpack plugin
plugins:
  - serverless-webpack

provider:
  name: aws
  runtime: nodejs6.10

functions:
  fulfillment:
    handler: src/handler.fulfillment
    # events:
    #   - http:
    #       method: get
    #       path: hello

错误

项目编译和部署成功,但是当调用 lambda 时,我不断收到

(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot convert undefined or null to object

P.S。示例源选择使用猫!

终于有时间回到这个问题并遇到这个 git issue

本质上dialogflow实例需要被lambda封装。

exports.fulfillment = function(event, context, callback) {
  app.handler(event, {})
    .then((res) => {
      if (res.status != 200) {
        callback(null, {
          "fulfillmentText": `I got status code: ${res.status}`
        });
      } else {
        callback(null, res.body);
      }
    }).catch((e) => {
      callback(null, {
        "fulfillmentText": `There was an error\n${e}`
      });
    });
};