From 15570a430e9fba8f794d3a7e22ba97c17b9254c9 Mon Sep 17 00:00:00 2001 From: jzvi12 Date: Thu, 24 Nov 2022 00:04:14 -0500 Subject: [PATCH] initial commit --- .env_sample | 7 +++++ .gitignore | 8 ++++++ favicon.ico | Bin 0 -> 240830 bytes getNewToken.js | 38 +++++++++++++++++++++++++++ index.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 36 +++++++++++++++++++++++++ watch_request.js | 29 ++++++++++++++++++++ 7 files changed, 185 insertions(+) create mode 100644 .env_sample create mode 100644 .gitignore create mode 100644 favicon.ico create mode 100644 getNewToken.js create mode 100644 index.js create mode 100644 package.json create mode 100644 watch_request.js diff --git a/.env_sample b/.env_sample new file mode 100644 index 0000000..0f56130 --- /dev/null +++ b/.env_sample @@ -0,0 +1,7 @@ +EMAIL=test@gmail.com +CLIENT_ID=xxxxxxxxxxxxxx.apps.googleusercontent.com +CLIENT_SECRET=xxxxxxxxxxxxxx +TOPIC_URL=projects//topics/MyPush +SUBSCRIPTION_URL=projects//subscriptions/MyPush-sub +EMAIL_LABEL=UNREAD +WEBHOOK_URL=https://discord.com/api/webhooks/get/yours diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0810116 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +credentials.json +token.json +gmailpush_history.json +.env +*.sh +node_modules +logs +backup diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..bee75fa39dff945305269f44126a4d1a8d58c808 GIT binary patch literal 240830 zcmeI52bdhiweLp=Ouoi8wjUQ?!?XQtuKoCYogW_pZPE&f4CaDOu)!vnYiz(^kQQlI z+9(N$j6fJ6a+1gxk%a*vat5KayV{(0XLcvg)cc?6?%AH%ndu4Lllrv2ziM`BdZznS z{Z5^#uC8`Crs1EX(}DjFc090ly5k!ThvN{4-rfY!`*OQ>x{~t$5exL!S33q8W;-aA zYM8YP(r-g^p(~*~p_ic#pv}-0R{A#RsIA)a#r*PI=nMSLN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+ auth.getToken(authCode, (err, token) => { + if (err) { + return console.log('Error retrieving access token', err); + } + + console.log('Token:'); + console.log(token); + }); + }); +} + +getToken(); diff --git a/index.js b/index.js new file mode 100644 index 0000000..2bf5bc8 --- /dev/null +++ b/index.js @@ -0,0 +1,67 @@ +require("dotenv").config(); +const jsonToken = require("./token.json"); +const Gmailpush = require("gmailpush"); +const express = require("express"); +const app = express(); +const { WebhookClient } = require("discord.js"); +const webhook = new WebhookClient({ url: process.env.WEBHOOK_URL }); + +// Initialize with OAuth2 config and Pub/Sub topic +const gmailpush = new Gmailpush({ + clientId: process.env.CLIENT_ID, + clientSecret: process.env.CLIENT_SECRET, + pubsubTopic: process.env.TOPIC_URL, +}); + +const users = [ + { + email: process.env.EMAIL, + token: { + access_token: jsonToken.access_token, + refresh_token: jsonToken.refresh_token, + scope: jsonToken.scope, + token_type: jsonToken.token_type, + expiry_date: jsonToken.expiry_date, + }, + }, +]; + +app.post( + // Use URL set as Pub/Sub Subscription endpoint + "/pubsub", + express.json(), + async (req, res) => { + res.sendStatus(200); + const email = gmailpush.getEmailAddress(req.body); + const token = users.find((user) => user.email === email).token; + + const { subject } = await gmailpush + .getNewMessage({ + notification: req.body, + token, + }) + .then((message) => { + if (message === null) { + return {}; + } + if (!message.labelIds.includes(process.env.EMAIL_LABEL)) { + return {}; + } + return message; + }); + if (subject) { + webhook + .send({ content: subject }) + .then((message) => console.log(`Sent message: ${message.content}`)) + .catch(console.error); + } else { + console.log( + "Not sending message: Email Subject does not match label ID." + ); + } + } +); + +app.listen(3002, () => { + console.log("Server listening on port 3002..."); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..5d0b161 --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "name": "gmail-push-to-discord", + "version": "1.0.0", + "description": "Get real-time Gmail push notifications to your Discord channel!", + "keywords": [ + "gmail", + "discord", + "bot", + "api", + "webhook" + ], + "homepage": "https://github.com/jzvi12/gmail-push-to-discord", + "repository": { + "type": "git", + "url": "https://github.com/jzvi12/gmail-push-to-discord.git" + }, + "main": "index.js", + "scripts": { + "start": "node ./index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "bugs": "https://github.com/jzvi12/gmail-push-to-discord/issues", + "author": "jzvi12", + "license": "MIT", + "dependencies": { + "@google-cloud/pubsub": "^3.2.1", + "discord.js": "^14.6.0", + "dotenv": "^16.0.3", + "express": "^4.18.2", + "gmailpush": "^1.0.5", + "googleapis": "^61.0.0" + }, + "engines": { + "node": ">=10" + } +} diff --git a/watch_request.js b/watch_request.js new file mode 100644 index 0000000..f0ff334 --- /dev/null +++ b/watch_request.js @@ -0,0 +1,29 @@ +require('dotenv').config(); +const jsonToken = require('./token.json'); +const {google} = require('googleapis'); + +const auth = new google.auth.OAuth2(process.env.CLIENT_ID, process.env.CLIENT_SECRET); + +auth.setCredentials({ + access_token: jsonToken.access_token, + refresh_token: jsonToken.refresh_token, + scope: jsonToken.scope, + token_type: jsonToken.token_type, + expiry_date: jsonToken.expiry_date +}); + +const gmail = google.gmail({ + version: 'v1', + auth, +}); + +gmail.users + .watch({ + userId: process.env.EMAIL, + requestBody: { + labelIds: [process.env.EMAIL_LABEL], + topicName: process.env.TOPIC_URL, + }, + }) + .then((result) => console.log(result)) + .catch((err) => console.log(err));