gpt4 book ai didi

node.js - 亚马逊认知 : How to implement Post Confirmation Trigger which works only after SignupConfirmation not after ForgotPassword/ResetPassword Confirmation

转载 作者:行者123 更新时间:2023-12-05 09:34:52 28 4
gpt4 key购买 nike

有人可以告诉我,如何才能在注册的确认后后发送此邮件。无论是忘记密码/重设密码还是注册,此代码都会在每次确认后发送邮件。

var aws = require('aws-sdk');

var ses = new aws.SES();

exports.handler = (event, context, callback) => {
console.log(event);

if (event.request.userAttributes.email) {
sendEmail(event.request.userAttributes.email, "Congratulations " + event.userName + ", you have been confirmed: ", function(status) {

// Return to Amazon Cognito
callback(null, event);
});
} else {
// Nothing to do, the user's email ID is unknown
callback(null, event);
}
};

function sendEmail(to, body, completedCallback) {
var eParams = {
Destination: {
ToAddresses: [to]
},
Message: {
Body: {
Text: {
Data: body
}
},
Subject: {
Data: "Cognito Identity Provider registration completed"
}
},

// Replace source_email with your SES validated email address
Source: "<source_email>"
};

var email = ses.sendEmail(eParams, function(err, data){
if (err) {
console.log(err);
} else {
console.log("===EMAIL SENT===");
}
completedCallback('Email sent');
});
console.log("EMAIL CODE END");
};

最佳答案

您可以检查 event 对象的 triggerSource 属性。

注册后确认事件的触发源是 PostConfirmation_ConfirmSignUp

您的句柄函数将如下所示:

exports.handler = (event, context, callback) => {
console.log(event);

if (
event.request.userAttributes.email
&& event.triggerSource === "PostConfirmation_ConfirmSignUp") {
sendEmail(event.request.userAttributes.email, "Congratulations " + event.userName + ", you have been confirmed: ", function (status) {

// Return to Amazon Cognito
callback(null, event);
});
} else {
// Nothing to do, the user's email ID is unknown
callback(null, event);
}
};

引用:User Pool Lambda Trigger Sources

关于node.js - 亚马逊认知 : How to implement Post Confirmation Trigger which works only after SignupConfirmation not after ForgotPassword/ResetPassword Confirmation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66223072/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com