Skip to content

Instantly share code, notes, and snippets.

@junichim junichim/README.md
Last active Feb 21, 2019

Embed
What would you like to do?
exports.handler = function(context, event, callback) {
//let twiml = new Twilio.twiml.VoiceResponse();
//// twiml.say("Hello World");
//callback(null, twiml);
if ('completed' != event.RecordingStatus) {
console.log('failed tel recorded');
console.log('tel sid: ' + event.CallSid);
console.log('status: ' + event.RecordingStatus);
console.log('from: ' + event.From);
console.log('errCode: ' + event.ErrorCode);
console.log('errMessage: ' + event.ErrorMessage);
callback(null, 'no tel recorded');
return;
}
sendEmail(event.RecordingUrl).then(function(info) {
console.log('success: ' + info);
callback(null, 'email success');
}).catch(function(err){
console.log('failed: ' + err);
callback(null, 'email failed');
});
function sendEmail(url) {
console.log("url: " + url);
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
host: 'SMTP サーバー名',
port: 587,
secure: false,
auth: {
user: 'ユーザー名',
pass: 'パスワード'
},
tls: {
rejectUnauthorized: false
}
});
var message = {
from: '発信者のメールアドレス',
to: '宛先メールアドレス',
subject: 'Tel received from ' + event.From,
text: 'Tel received from ' + event.From,
attachments: [{
filename: 'record.wav',
path: url
}]
};
console.log("finish preparation to send mail");
return new Promise(function(resolve, reject) {
transporter.sendMail(message, function(error, info) {
if (error) {
console.log('error: ' + error);
reject(error);
} else {
console.log('email sent, message id: ' + info.messageId);
resolve(info);
}
});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.