Skip to content

Commit

Permalink
feat(helpers): init mail alert template ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Apr 22, 2020
1 parent de1c7a1 commit 8918641
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions config/templates/api-failed-alert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
<title></title>
</head>

<body>
<p>Dear Mr, Mrs,</p>
<p> You have configured to be alerted on this mail if api call to <b>{{apiTitle}}</b> fails.</p>
<pre style='background: #f5f2f0; color:#72972c; padding: 15px; border-radius: 7px;'>{{result}}</pre>
<br />
<p>The {{appName}} Support Team.</p>
<br/>
<i style='color:#9b9b9b'>Please do not reply to this email, you can contact us here {{appContact}}.</i>
</body>

</html>
19 changes: 19 additions & 0 deletions lib/helpers/montaineRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const jwt = require('jsonwebtoken');
const path = require('path');
const _ = require('lodash');

const mails = require(path.resolve('./lib/helpers/mails'));
const model = require(path.resolve('./lib/middlewares/model'));
const config = require(path.resolve('./config'));
const AppError = require(path.resolve('./lib/helpers/AppError'));
Expand Down Expand Up @@ -74,6 +75,24 @@ exports.request = async (api, params) => {
}
};

/**
* @desc send mail alert
* @param {Object} data - scraping result
* @return {Object} mail status
*/
exports.sendMailAlert = (data, api) => mails.sendMail({
template: 'api-failed-alert',
from: config.mailer.from,
to: api.alert,
subject: `Montaine Api Failed : ${api.title}`,
params: {
result: JSON.stringify(data, null, 2),
apiTitle: api.title,
appName: config.app.title,
appContact: config.app.appContact,
},
});

/**
* @desc setScrapHistory
* @param {Object} data - scraping result
Expand Down

0 comments on commit 8918641

Please sign in to comment.