Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mailgun Integration #93

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ You will find further information on the [schnack page](https://schnack.cool/).
* slack
* rss
* sendmail
* mailgun

### Who is behind Schnack?

Expand Down
6 changes: 6 additions & 0 deletions config.tpl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/push/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -111,4 +112,3 @@ function init(app, db, awaiting_moderation) {
module.exports = {
init
};

37 changes: 37 additions & 0 deletions src/push/mailgun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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.error(err);
});
});
}