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 Discord Integration #7

Open
wants to merge 1 commit 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
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

* Email alert notification (with [SendGrid](https://sendgrid.com/))

* Slack alert notification
* Slack alert notification

* Discord alert notification

* Daily email to confirm that the app is working

Expand Down Expand Up @@ -62,17 +64,30 @@ The App request the `urlToCheck` every `checkingFrequency` and if any of the `el

4.1 Activate the [WebHooks in your WorkSpace](https://api.slack.com/incoming-webhooks) and get the corresponding 'WebHook URL'

4.2 In *server.js*, set the 'WebHook URL' in `SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX';`
4.2 In *server.js*, set the 'WebHook URL' in `SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX';`

5. **Discord** Integration

5.1 First you need to create a webhook in a text channel. We're assuming you have both `Manage Channel` and `Manage Webhooks` permissions!

- Go in a channel properties (Alternatively, Server Settings, Webhooks works too)
- Click **Webhooks**
- Click **Create Webhook**
- Type in a name (this is for local reference, it's overriden by the incoming hook data)
- Copy the **Webhook URL** (you can use the Copy button)
- Click **Save**

5.2 In *server.js*, set the 'WebHook URL' in `DISCORD_WEBHOOK_URL = 'https://discordapp.com/api/webhooks/xxxxxxxxxxxxxxxxxxxx/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';`

5. **SendGrid** Email Integration
6. **SendGrid** Email Integration

5.1 Create a [SendGrid Free Account](https://sendgrid.com/pricing/)
6.1 Create a [SendGrid Free Account](https://sendgrid.com/pricing/)

5.2 Create and get an [API KEY with Full Access](https://app.sendgrid.com/settings/api_keys)
6.2 Create and get an [API KEY with Full Access](https://app.sendgrid.com/settings/api_keys)

5.3 In *server.js*, set the *'API KEYS'* in `SENDGRID_APY_KEY = 'AA.AAAA_AAAAAAAAAAAAA.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';`
6.3 In *server.js*, set the *'API KEYS'* in `SENDGRID_APY_KEY = 'AA.AAAA_AAAAAAAAAAAAA.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';`

5.4 In *server.js*, set the sender email in the *emailFrom* variable. Code: `emailFrom = "aaa@aaa.com";`
6.4 In *server.js*, set the sender email in the *emailFrom* variable. Code: `emailFrom = "aaa@aaa.com";`

Now, to avoid falling into the "SPAM" folder there are two options:

Expand All @@ -84,7 +99,7 @@ The App request the `urlToCheck` every `checkingFrequency` and if any of the `el

b) Put any email address in the `emailFrom` variable and add it to the *white list* in the receiver email client.

5.5 In *server.js*, set the *emailsToAlert* array. Code: `emailsToAlert = ["emailOneToSend@theAlert.com", "emailTwoToSend@theAlert.com"];`
6.5 In *server.js*, set the *emailsToAlert* array. Code: `emailsToAlert = ["emailOneToSend@theAlert.com", "emailTwoToSend@theAlert.com"];`

<br />

Expand Down
91 changes: 68 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"ejs": "^2.6.1",
"express": "^4.17.1",
"request": "^2.88.0",
"slack-notify": "^0.1.7"
"slack-notify": "^0.1.7",
"discord-webhook-node": "^1.1.8"
},
"devDependencies": {
"nodemon": "^1.19.1"
Expand Down
10 changes: 10 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const checkingFrequency = 5 * 60000; //first number represent the checkingFreque
const SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX';
const slack = require('slack-notify')(SLACK_WEBHOOK_URL);

//Discord Integration
const DISCORD_WEBHOOK_URL = 'https://discordapp.com/api/webhooks/xxxxxxxxxxxxxxxxxxxx/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const {Webhook} = require('discord-webhook-node');
const discord = new Webhook(DISCORD_WEBHOOK_URL);

//SendGrid Email Integration
const SENDGRID_APY_KEY = 'AA.AAAA_AAAAAAAAAAAAA.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
const sgMail = require('@sendgrid/mail');
Expand Down Expand Up @@ -59,6 +64,11 @@ const intervalId = setInterval(function () {
}
});

// Discord Information Message
discord.info(`**Alert**`, `Change Detected!`, `🔥🔥🔥 Change detected in ${urlToCheck} 🔥🔥🔥 `)
.then(() => console.log('Message received in Discord!'))
.catch(err => console.log(`Discord API error: ${err.message}`));

// Email Alert Notification
const msg = {
to: emailsToAlert,
Expand Down