Created
February 13, 2023 16:09
-
-
Save tanishqsh/e04f50dda36fabdc01109301935229de to your computer and use it in GitHub Desktop.
Telegram <> Gumroad Sentinel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const fetch = require('node-fetch'); | |
const cors = require('cors'); | |
const bodyParser = require('body-parser'); | |
const TelegramBot = require('node-telegram-bot-api'); | |
const { response } = require('express'); | |
/** | |
* Requiring ENV file for variables | |
*/ | |
require('dotenv').config(); | |
/** | |
* Get the mandatory keys to access various platforms | |
*/ | |
// Create a bot that uses 'polling' to fetch new updates | |
const bot = new TelegramBot(process.env.BOTID, { polling: true }); | |
const API_KEY = process.env.GUMROAD_API_KEY; | |
const SENDERID = process.env.GROUPID; | |
/** Initiating the express app */ | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.use( | |
bodyParser.urlencoded({ | |
extended: true, | |
}) | |
); | |
app.use(cors()); | |
/** | |
* This function uses the / method API to get the stats | |
*/ | |
async function getProducts() { | |
const products = await fetch(`https://api.gumroad.com/v2/products`, { | |
headers: { | |
Authorization: `Bearer ${API_KEY}`, | |
'Content-Type': 'application/json', | |
}, | |
method: 'GET', | |
}); | |
return await products.json(); | |
} | |
async function verifyLicense(content) { | |
const products = await fetch(`https://api.gumroad.com/v2/licenses/verify`, { | |
headers: { | |
Authorization: `Bearer ${API_KEY}`, | |
'Content-Type': 'application/json', | |
}, | |
method: 'POST', | |
body: JSON.stringify(content), | |
}); | |
return await products.json(); | |
} | |
/** | |
* Couple of assumptions | |
* 1. Every person needs to set their username, as the parameter is mandatory in user journey. | |
*/ | |
const users = [ | |
{ | |
first_name: '[username]', | |
userid: '[userid]', | |
}, | |
]; | |
// bot.on('message', (msg) => { | |
// console.log(msg); | |
// verifyLicense({ | |
// product_permalink: 'eBBQM', | |
// license_key: msg.text, | |
// }).then((response) => { | |
// // console.log(response); | |
// if (!response.success) { | |
// bot.sendMessage(msg.chat.id, 'Please paste the license key from Gumroad.'); | |
// } else { | |
// bot.sendMessage(msg.chat.id, 'Congratulations, your license is now verified. Join our group here: https://t.me/joinchat/[id]'); | |
// } | |
// }); | |
// }); | |
function getKeyByValue(object, value) { | |
return Object.keys(object).find((key) => object[key] === value); | |
} | |
app.get('/', (req, res) => { | |
// bot.kickChatMember(-455342070, 1528357489).then((rep) => { | |
// console.log(rep); | |
// res.send({ | |
// products, | |
// }); | |
// }); | |
}); | |
const port = process.env.PORT || 3000; | |
app.listen(port, () => { | |
console.log(`App Is Running On http://localhost:${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment