将感谢您的帮助。我有2个诺言,但是如果另一个诺言拒绝,我不希望一个诺言得以兑现。由于某种原因,即使语音呼叫承诺错误或电子邮件承诺错误,其他承诺仍在运行。
const aws = require('aws-sdk');
const ses = new aws.SES({region: 'us-west-2'});
const pinpointsmsvoice = new aws.PinpointSMSVoice({region: 'us-west-2'});
exports.handler = (event, context, callback) => {
const parsed = JSON.parse(event.data)
const foodArray = parsed.food
const callParams = {
Content: {
SSMLMessage: {
LanguageCode : "en-US",
Text : "<speak>Hello Restaurant. You have a new online order from. " + parsed.user.firstName + ". Please check your email and enter the order into the P O S system. Thank you. Goodbye.</speak>",
VoiceId: "Salli"
}
},
OriginationPhoneNumber: "[+1111111111]",
DestinationPhoneNumber: "<+incorrect number inputted here>"
};
const email = ()=> {
let buffer = ''
for (let i = 0; i<foodArray.length; i++) {
buffer += `<p> ${i+1}. ${foodArray[i].name} <br></br> quantity: ${foodArray[i].quantity} <br></br> special instructions: ${foodArray[i].instructions || "none"} <br></br> if sold out: ${foodArray[i].soldOut}`
}
let customer = `<br><br> <br></br> Customer: ${parsed.user.firstName} ${parsed.user.lastName},<br/> phone number: ${parsed.user.phoneNumber},<br/> email: ${parsed.user.email}`
const params = {
Destination: {
ToAddresses: ["someone@gmail.com"]
},
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: "<html><body><h1>Hello CP</h1> <h4>You have a new online order.</h4>" + buffer + customer + "</body></html>"
},
Text: {
Charset: "UTF-8",
Data: ""
}
},
Subject: { Data: `New Online Order from ${parsed.user.firstName} ${parsed.user.lastName}`
}
},
Source: "<incorrect email inputted here>"
};
return params
}
const sendPromise = ses.sendEmail(email()).promise();
const callPromise = pinpointsmsvoice.sendVoiceMessage(callParams).promise()
Promise.all([sendPromise, callPromise]).then(function(values) {
callback(null, values);
}).catch(function(values) {callback(null,values)});
感谢您对此的新帮助