From 8918641336059e30cc845ceda71f3184ed8c16cb Mon Sep 17 00:00:00 2001 From: Pierre Brisorgueil Date: Wed, 22 Apr 2020 11:29:41 +0200 Subject: [PATCH] =?UTF-8?q?feat(helpers):=20init=20mail=20alert=20template?= =?UTF-8?q?=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/templates/api-failed-alert.html | 18 ++++++++++++++++++ lib/helpers/montaineRequest.js | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 config/templates/api-failed-alert.html diff --git a/config/templates/api-failed-alert.html b/config/templates/api-failed-alert.html new file mode 100644 index 000000000..7fac35096 --- /dev/null +++ b/config/templates/api-failed-alert.html @@ -0,0 +1,18 @@ + + + + + + + + +

Dear Mr, Mrs,

+

You have configured to be alerted on this mail if api call to {{apiTitle}} fails.

+
{{result}}
+
+

The {{appName}} Support Team.

+
+ Please do not reply to this email, you can contact us here {{appContact}}. + + + \ No newline at end of file diff --git a/lib/helpers/montaineRequest.js b/lib/helpers/montaineRequest.js index cc887db1a..ff54415bf 100644 --- a/lib/helpers/montaineRequest.js +++ b/lib/helpers/montaineRequest.js @@ -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')); @@ -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