would appreciate the help.
(将不胜感激。)
I have 2 promises, but i do not want one promise to run if the other promise rejects.(我有2个诺言,但是如果另一个诺言拒绝,我不希望一个诺言得以兑现。)
for some reason, even when the voice call promise is erroring, or the email promise is erroring, the other promise is still running.(由于某种原因,即使语音呼叫承诺错误或电子邮件承诺错误,其他承诺仍在运行。)
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: ["[email protected]"]
},
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)});
thanks for the help im new at this
(谢谢你的帮助)
ask by Jonathan Mau translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…