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

add plugin notify-mailgun #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions packages/notify-mailgun/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The Lil License v1

Copyright (c) 2021 Gregor Aisch, Moritz Klack & g-div

Permission is hereby granted by the authors of this software, to any person,
to use the software for any purpose, free of charge, including the rights to
run, read, copy, change, distribute and sell it, and including usage rights to
any patents the authors may hold on it, subject to the following conditions:

This license, or a link to its text, must be included with all copies of the
software and any derivative works.

Any modification to the software submitted to the authors may be incorporated
into the software under the terms of this license.

The software is provided "as is", without warranty of any kind, including but
not limited to the warranties of title, fitness, merchantability and non-
infringement. The authors have no obligation to provide support or updates for
the software, and may not be held liable for any damages, claims or other
liability arising from its use.
30 changes: 30 additions & 0 deletions packages/notify-mailgun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# notify-mailgun

If you configure the plugin `notify-mailgun` *schnack* will use [mailgun](https://www.mailgun.com/) to send an email to you every time a comment is awaiting your approval.

## Usage

Add a `plugins.notify-sendmail` section to your Schnack config file `schnack.json`:

```json
{
"plugins": {
"notify-mailgun": {
"api_key": "xxxxx",
"domain": "example.com",
"to": "your-email@example.com",
"from": "schnack@blog.example.com"
}
}
}
```

Then run

```
npm init schnack
```

## Credits

This integration was contributed by [@leviwheatcroft](https://github.com/leviwheatcroft)
34 changes: 34 additions & 0 deletions packages/notify-mailgun/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const mailgun = require('mailgun-js');

module.exports = ({ config, host, app, events }) => {
return {
notify({ page_url }) {
const client = mailgun({
apiKey: config.api_key,
domain: config.domain
});

events.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} <${config.from}>`;
const to = `Schnack Admin <${config.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);
});
});
}
};
};
Loading