jovo-plugin-error-email
Version:
Jovo plugin to send out emails if an error occurs.
59 lines • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const aws = require("aws-sdk");
const nodemailer = require("nodemailer");
const pug = require("pug");
class EmailErrorPlugin {
constructor() {
this.config = {
fromEmail: '',
toEmail: '',
subject: 'An error has occured',
awsConfig: {
accessKeyId: '',
secretAccessKey: '',
region: '',
apiVersion: '2010-12-01'
}
};
this.transporter = undefined;
}
install(app) {
app.middleware('fail').use(this.log.bind(this));
this.transporter = nodemailer.createTransport({
SES: new aws.SES(this.config.awsConfig)
});
}
uninstall(app) {
}
log(handleRequest) {
const data = this.createLog(handleRequest);
this.sendMail(data);
}
createLog(handleRequest) {
if (!handleRequest.jovo) {
return;
}
const data = {
stackTrace: handleRequest.error.stack,
userId: handleRequest.jovo.$user.getId(),
timestamp: handleRequest.jovo.$request.getTimestamp(),
locale: handleRequest.jovo.$request.getLocale(),
platform: handleRequest.jovo.constructor.name,
state: handleRequest.jovo.getState() ? handleRequest.jovo.getState() : '-',
intent: handleRequest.jovo.$request.getIntentName()
};
return data;
}
sendMail(data) {
let html = pug.renderFile(`${__dirname}/email.pug`, data);
this.transporter.sendMail({
from: this.config.fromEmail,
to: this.config.toEmail,
subject: this.config.subject,
html
});
}
}
exports.EmailErrorPlugin = EmailErrorPlugin;
//# sourceMappingURL=EmailErrorPlugin.js.map