AWS Lambda:当 Lex Chatbot 发布到 Slack 时,SES 不工作

AWS Lambda: SES not working when Lex Chatbot is published to Slack

AWS SESLex 测试聊天机器人一起使用,但在使用 Slack 应用程序发布聊天机器人后,它不起作用(不触发电子邮件服务)。但是 Lambda 函数似乎没有任何问题,因为我正在松弛地恢复响应文本。而且我认为没有办法检查 slack 造成问题的原因。

Lambda 函数:

var aws = require('aws-sdk');
var ses = new aws.SES({
  region: 'us-east-1'
});

exports.handler = function(event, context, callback) {

  var eParams = {
    Destination: {
      ToAddresses: [event.currentIntent.slots.Email]
    },
    Message: {
      Body: {
        Text: {
          Data: "Hi, How are you?"
        }
      },
      Subject: {
        Data: "Title"
      }
    },

    Source: "abc@gmail.com"
  };
  var email = ses.sendEmail(eParams, function(err, data) {
    if (err)
    else {

      context.succeed(event);

    }
  });

  callback(null, {
    "dialogAction": {
      "type": "ConfirmIntent",
      "fulfillmentState": "Fulfilled",
      "message": {
        "contentType": "PlainText",
        "content": "message to convey to the user, i.e. Are you sure you want a large pizza?"
      }
    }
  });
};

编辑 1:我认为问题是当我在 Slack.

上发布我的 Lex 机器人时,我没有得到 [event.currentIntent.slots.Email] 中的值

尝试按照以下步骤找出根本原因:

  1. 确保您已使用 this 分步教程正确配置了 Slack 机器人。

  2. 如果您的机器人在您的测试机器人(LEX 内部)中运行良好但在 Slack 上运行不正常,请确保您已经发布了最新版本 的机器人。

  3. 在您的 AWS Lambda 上尝试下面的代码,看看您在 return.

    中得到了什么

    callback(null, { "dialogAction": { "type": "ConfirmIntent", "fulfillmentState": "Fulfilled", "message": { "contentType": "PlainText", "content": "Echo: " + JSON.stringify(event.currentIntent.slots) <-- This } } });

希望对您有所帮助。

我有一个类似的问题,机器人在 lex 控制台中工作但在 slack 中不工作。虽然与电子邮件无关,但这是我发现的。

由于某种原因空会话属性 传递给 slack 时存储为 NULL。因此你不能向它添加变量。您希望它是 {} 所以如果它是 NULL 将它的值更改为 {}

if(intentRequest.sessionAttributes == null){ 
    intentRequest.sessionAttributes = {};
}

根据上面的评论,这就是让我的 slack bot 与我的测试 lex 聊天正在做的事情保持一致的原因:

session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}