Skip to content

Commit

Permalink
- Add support for IFTTT, Mailgun (SMTP) and Matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Aschmann committed Jul 21, 2022
1 parent 38d3ac9 commit 2e30d70
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ Click Send SMS
Discord
Gitter
Google Chat
IFFFF
Line
Signal
Slack
SMTP
Mailgun
Matrix
Microsoft Teams
Telegram
Webhook
Expand Down Expand Up @@ -216,6 +219,22 @@ Please follow this document to setup a incoming webhook and get the URL: <a href

<hr>

## IFTTT

#### Parameters
```
required: {
iftttServiceKey: "",
eventName: "",
text: ""
},
optional: {}
```
#### Setup
Setup a webhook in IFTTT using this <a href='https://ifttt.com/maker_webhooks/settings' target='_blank'>URL</a>. Next create a new applet and note its name as this needs to be specified in the eventName parameter, use a "Webhook" as the "If" trigger. You can find the iftttServiceKey in Documentation from the <a href='https://ifttt.com/maker_webhooks' target='_blank'>webhooks page</a>.

<hr>

## Line

#### Parameters
Expand All @@ -230,6 +249,30 @@ Please follow this document to setup a incoming webhook and get the URL: <a href
#### Setup
Open <a href='https://developers.line.biz/console' target='_blank'>Developer Console</a>, create a provider. Open the new provider and create a new Messaging API channel. Complete the required fields and navigate to the new channel. On the Basic Settings screen, scroll to the bottom and note your Line User ID, use this in the required parameter field and where you will recieve your messages. To get a access token, select the "Message API" tab, and create a channel access token at the bottom of the screen.


<hr>

## Mailgun
```
required: {
smtpUsername: "",
smtpPassword: "",
smtpFrom: "",
smtpTo: "",
subject : "",
text: ""
},
optional: {
smtpCC: "",
smtpBCC: "",
html: "",
attachments: ""
}
```

#### Setup
Once you have your mailgun account setup, you can get your username and password from the SMTP page on your <a href='https://app.mailgun.com/app/sending/domains' target='_blank'>domain</a>.

<hr>

## SMTP
Expand Down Expand Up @@ -331,6 +374,23 @@ Create a bot using the @botfather channel. Take note of the Access Token. To get

<hr>

## Matrix

```
required: {
matrixHomeServerUrl: "",
matrixAccessToken: "",
matrixRoomId: "",
text: ""
},
optional: {}
```

#### Setup
In order to send notifications to Matrix, Reach requires the Homeserver Url, a access token and the room ID. In the <a href='https://element.io' target='_blank'>Element Webclient</a> you can get the Homeserver URL and Access Token from the "All Settings" menu and Help and About screen in the Advanced section. The room ID can be viewed in the Room settings, under the Advanced screen.

<hr>

## Microsoft Teams

```
Expand Down
36 changes: 36 additions & 0 deletions providers/ifttt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

const provider = require("./provider");
const axios = require("axios");

class Ifttt extends provider {

name = "ifttt";

parameters = {
required: {
iftttServiceKey: "",
eventName: "",
text: ""
},
optional: {}
};

async send(notification) {
try {
let data = {
"text": notification.required.text,
};
let config = {};

let iftttUrl = "https://maker.ifttt.com/trigger/" + notification.required.eventName + "/json/with/key/" + notification.required.iftttServiceKey;

await axios.post(iftttUrl, data, config);

return "Sent Successfully.";
} catch (err) {
return err;
}
}
}

module.exports = Ifttt;
60 changes: 60 additions & 0 deletions providers/mailgun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const provider = require("./provider");
const nodemailer = require('nodemailer');

class MailGun extends provider {

name = "mailgun";

parameters = {
required: {
smtpUsername: "",
smtpPassword: "",
smtpFrom: "",
smtpTo: "",
subject : "",
text: ""
},
optional: {
smtpCC: "",
smtpBCC: "",
html: "",
attachments: ""
}
};

async send(notification) {
try {
const config = {
host: "smtp.mailgun.org",
port: "587",
secure: false,
tls: {
rejectUnauthorized: false,
},
auth: {
user: notification.required.smtpUsername,
pass: notification.required.smtpPassword,
}
};

let transporter = nodemailer.createTransport(config);

await transporter.sendMail({
from: notification.required.smtpFrom,
cc: notification.optional.smtpCC,
bcc: notification.optional.smtpBCC,
to: notification.required.smtpTo,
subject: notification.required.subject,
text: notification.required.text,
html: notification.optional.html,
attachments: notification.optional.attachments
});

return "Message Sent";
} catch (err) {
return err;
}
}
}

module.exports = MailGun;
41 changes: 41 additions & 0 deletions providers/matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const provider = require("./provider");
const axios = require("axios");

class Matrix extends provider {

name = "matrix";

parameters = {
required: {
matrixHomeServerUrl: "",
matrixAccessToken: "",
matrixRoomId: "",
text: ""
},
optional: {}
};

async send(notification) {
try {
let serverUrl = notification.required.matrixHomeServerUrl + "/_matrix/client/r0/rooms/" + notification.required.matrixRoomId + "/send/m.room.message?access_token=" + notification.required.matrixAccessToken;
let config = {
headers: {
"Content-Type": "application/json"
}
};
let data = {
"msgtype": "m.text",
"body": notification.required.text
};


await axios.post(serverUrl, data, config);

return "Sent Successfully.";
} catch (err) {
return err;
}
}
}

module.exports = Matrix;
6 changes: 6 additions & 0 deletions reach.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const SendGrid = require("./providers/sendgrid");
const Webhook = require("./providers/webhook");
const Bark = require("./providers/bark");
const Gitter = require("./providers/gitter");
const Ifttt = require("./providers/ifttt");
const Mailgun = require("./providers/mailgun");
const Matrix = require("./providers/matrix");

class Reach {
providers = {};
Expand All @@ -33,6 +36,9 @@ class Reach {
this.providers["sendgrid"] = new SendGrid();
this.providers["bark"] = new Bark();
this.providers["gitter"] = new Gitter();
this.providers["ifttt"] = new Ifttt();
this.providers["mailgun"] = new Mailgun();
this.providers["matrix"] = new Matrix();
}

static async send(notification) {
Expand Down

0 comments on commit 2e30d70

Please sign in to comment.