From 506cab5a6bc9781bcf988c1d6f00bc8d38231203 Mon Sep 17 00:00:00 2001 From: Levi Wheatcroft <547896+leviwheatcroft@users.noreply.github.com> Date: Sat, 2 Feb 2019 10:17:49 +0800 Subject: [PATCH 1/3] added push for mailgun --- config.tpl.json | 6 ++++++ package.json | 1 + src/push/index.js | 2 +- src/push/mailgun.js | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/push/mailgun.js diff --git a/config.tpl.json b/config.tpl.json index 4fe9785..65898df 100644 --- a/config.tpl.json +++ b/config.tpl.json @@ -41,6 +41,12 @@ }, "slack": { "webhook_url": "xxxxx" + }, + "mailgun": { + "api_key": "xxxxx", + "domain": "xxxxx", + "from": "xxxxx", + "to": "xxxxx" } }, "date_format": "MMMM DD, YYYY - h:mm a" diff --git a/package.json b/package.json index 973a430..2fe714a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "express": "^4.16.4", "express-session": "^1.15.6", "lodash.countby": "^4.6", + "mailgun-js": "^0.22.0", "marked": "^0.3.19", "moment": "^2.22.2", "nconf": "^0.10.0", diff --git a/src/push/index.js b/src/push/index.js index 33e436e..9219d4a 100644 --- a/src/push/index.js +++ b/src/push/index.js @@ -5,6 +5,7 @@ const Pushover = require('pushover-notifications'); const queries = require('../db/queries'); const slack = require('./slack'); const sendmail = require('./sendmail'); +const mailgun = require('./mailgun'); const { send_file, send_string, @@ -111,4 +112,3 @@ function init(app, db, awaiting_moderation) { module.exports = { init }; - diff --git a/src/push/mailgun.js b/src/push/mailgun.js new file mode 100644 index 0000000..c57c61a --- /dev/null +++ b/src/push/mailgun.js @@ -0,0 +1,38 @@ +const mailgun = require('mailgun-js'); +const config = require('../config'); +const schnackEvents = require('../events'); + +const notify = config.get('notify'); + + + +if (notify.mailgun) { + const client = mailgun({ + apiKey: notify.mailgun.api_key, + domain: notify.mailgun.domain + }) + schnackEvents.on('new-comment', (event) => { + const postUrl = config.get('page_url').replace('%SLUG%', event.slug); + const user = event.user.display_name || event.user.name; + const from = `${user} <${notify.mailgun.from}>` + const to = `Schnack Admin <${notify.mailgun.to}>` + const subject = `New comment: ${postUrl}`; + const text = + ` + New comment on your post ${postUrl} + + Author: ${user} + + ${event.comment} + + You can see all comments on this post here: + ${postUrl}#comments + + Permalink: ${postUrl}#comment-${event.id} + `.split(/\n/).join('\r\n').trim(); + client.messages().send({ from, to, subject, text }, function (err, body) { + console.log(err); + console.log(body); + }); + }); +} From ee90c7802d53d23679197fd1aaad98a92471c888 Mon Sep 17 00:00:00 2001 From: Levi Wheatcroft <547896+leviwheatcroft@users.noreply.github.com> Date: Sat, 2 Feb 2019 10:20:43 +0800 Subject: [PATCH 2/3] add mailgun to notify providers --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 15a9e5e..f05387c 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ You will find further information on the [schnack page](https://schnack.cool/). * slack * rss * sendmail +* mailgun ### Who is behind Schnack? From fa0740dd6f2fa69b742bcd8d389a99c4a199237b Mon Sep 17 00:00:00 2001 From: Levi Wheatcroft <547896+leviwheatcroft@users.noreply.github.com> Date: Sat, 2 Feb 2019 12:05:55 +0800 Subject: [PATCH 3/3] remove console.log spam --- src/push/mailgun.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/push/mailgun.js b/src/push/mailgun.js index c57c61a..be82327 100644 --- a/src/push/mailgun.js +++ b/src/push/mailgun.js @@ -31,8 +31,7 @@ if (notify.mailgun) { Permalink: ${postUrl}#comment-${event.id} `.split(/\n/).join('\r\n').trim(); client.messages().send({ from, to, subject, text }, function (err, body) { - console.log(err); - console.log(body); + console.error(err); }); }); }