Skip to content

Commit d18a02f

Browse files
authored
Add files via upload
1 parent ad74d2b commit d18a02f

File tree

4 files changed

+188
-0
lines changed

4 files changed

+188
-0
lines changed

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
worker: node main.js

app.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "BonkMeet",
3+
"description": "A self hosted telegram bot for attending Google Meet sessions on bahalf of you.",
4+
"repository": "https://github.com/bunnykek/BonkMeet",
5+
"logo": "https://imgur.com/UsUog2Z.png",
6+
"keywords": [
7+
"telegram",
8+
"telegram-bot",
9+
"gmeet",
10+
"google-meet",
11+
"gmeet-bot",
12+
"google-meet-bot",
13+
"gmeet-telegram-bot"
14+
],
15+
"env": {
16+
"bot_token": {
17+
"description": "Get your bot's token from https://telegram.me/BotFather ",
18+
"value": "XXXXXXXXXX:YYYYYYYYYYYYYYYYYYYYYYYYY"
19+
},
20+
"cookie": {
21+
"description": "cookie.json contents.",
22+
"value": ""
23+
}
24+
},
25+
"buildpacks": [
26+
{
27+
"url": "jontewks/puppeteer"
28+
},
29+
{
30+
"url": "heroku/nodejs"
31+
}
32+
]
33+
}

main.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
const puppeteer = require('puppeteer');
2+
const TelegramBot = require('node-telegram-bot-api');
3+
var fs = require('fs');
4+
5+
const logo =
6+
`\n
7+
/$$$$$$$ /$$ /$$ /$$ /$$ /$$
8+
| $$__ $$ | $$ | $$ | $$$ /$$$ | $$
9+
| $$ \\ $$ /$$$$$$ /$$$$$$$ | $$ /$$| $$ | $$$$ /$$$$ /$$$$$$ /$$$$$$ /$$$$$$
10+
| $$$$$$$ /$$__ $$| $$__ $$| $$ /$$/| $$ | $$ $$/$$ $$ /$$__ $$ /$$__ $$|_ $$_/
11+
| $$__ $$| $$ \\ $$| $$ \\ $$| $$$$$$/ |__/ | $$ $$$| $$| $$$$$$$$| $$$$$$$$ | $$
12+
| $$ \\ $$| $$ | $$| $$ | $$| $$_ $$ | $$\\ $ | $$| $$_____/| $$_____/ | $$ /$$
13+
| $$$$$$$/| $$$$$$/| $$ | $$| $$ \\ $$ /$$ | $$ \\/ | $$| $$$$$$$| $$$$$$$ | $$$$/
14+
|_______/ \\______/ |__/ |__/|__/ \\__/|__/ |__/ |__/ \\_______/ \\_______/ \\___/
15+
bot for attending your Gmeet sessions --by bunny \n`
16+
console.log(logo);
17+
console.log('Send /help to the bot...');
18+
19+
const token = process.env.bot_token;
20+
const Cookie = JSON.parse(process.env.cookie);
21+
22+
async function main() {
23+
24+
const browser = await puppeteer.launch({
25+
headless: true,
26+
ignoreDefaultArgs: ['--enable-automation'],
27+
args: ['--start-maximized'],
28+
defaultViewport: { width: 1920, height: 1080 }
29+
});
30+
const context = browser.defaultBrowserContext();
31+
await context.overridePermissions('https://meet.google.com', []);
32+
const page = await browser.newPage();
33+
await page.setDefaultNavigationTimeout(0);
34+
await page.setCookie(...Cookie);
35+
36+
// Create a bot that uses 'polling' to fetch new updates
37+
const bot = new TelegramBot(token, { polling: true });
38+
39+
bot.on("polling_error", console.log);
40+
41+
// Matches "/echo [whatever]"
42+
bot.onText(/\/join (.+)/, async (msg, match) => {
43+
const chatId = msg.chat.id;
44+
const resp = match[1]; // the captured "whatever"
45+
const classCode = resp.match(/\w+-\w+-\w+/)[0];
46+
console.log('Classroom link : ', `https://meet.google.com/${classCode}`);
47+
await page.goto(`https://meet.google.com/${classCode}`);
48+
bot.sendMessage(chatId, 'Please wait...', { reply_to_message_id: msg.message_id })
49+
50+
let [button] = await page.$x("//button[contains(., 'Dismiss')]");
51+
if (button) {
52+
await button.click();
53+
}
54+
55+
[button] = await page.$x("//button[contains(., 'Return to home screen')]");
56+
if (button) {
57+
bot.sendMessage(chatId, 'Check your meeting code.\nMake sure that you have used the correct meet url.', { reply_to_message_id: msg.message_id })
58+
}
59+
60+
else {
61+
62+
63+
xpath = '//*[@id="yDmH0d"]/c-wiz/div/div/div[9]/div[3]/div/div/div[3]/div/div/div[2]/div/div[2]/div/div[1]/div[1]/span/span'
64+
await page.waitForXPath(xpath)
65+
await page.waitForTimeout(1000)
66+
elements = await page.$x(xpath)
67+
await elements[0].click()
68+
await page.keyboard.press('Tab')
69+
await page.keyboard.press('Tab')
70+
await page.keyboard.press('Tab')
71+
await page.keyboard.press('Tab')
72+
await page.waitForTimeout(5000)
73+
await page.screenshot({ path: 'example.png' });
74+
let stream = await fs.createReadStream('./example.png');
75+
bot.sendMessage(chatId, 'Requested/joined the class!', { reply_to_message_id: msg.message_id })
76+
bot.sendPhoto(chatId, stream);
77+
}
78+
});
79+
80+
bot.on('message', async (msg) => {
81+
const chatId = msg.chat.id;
82+
if (msg.text == '\/status') {
83+
console.log(msg.text);
84+
await page.screenshot({ path: 'example.png' });
85+
let stream = await fs.createReadStream('./example.png');
86+
bot.sendPhoto(chatId, stream);
87+
}
88+
else if (msg.text == '\/leave') {
89+
console.log(msg.text);
90+
let xpath = '//*[@id="ow3"]/div[1]/div/div[9]/div[3]/div[10]/div[2]/div/div[7]/span/button'
91+
await page.waitForTimeout(1000)
92+
let elements = await page.$x(xpath)
93+
if (elements.length != 0) {
94+
await elements[0].click()
95+
console.log('meet left');
96+
await page.waitForTimeout(2000)
97+
bot.sendMessage(chatId, 'Left the meet!', { reply_to_message_id: msg.message_id })
98+
await page.screenshot({ path: 'example.png' });
99+
let stream = await fs.createReadStream('./example.png');
100+
bot.sendPhoto(chatId, stream);
101+
}
102+
else {
103+
bot.sendMessage(chatId, 'You are not attending any gmeet session currently', { reply_to_message_id: msg.message_id })
104+
}
105+
}
106+
107+
else if (msg.text == '\/help') {
108+
let help = `List of available commands:
109+
/join {gmeet_link}
110+
/status (shows the ongoing meet current status)
111+
/leave (leaves the current gmeet session)
112+
/help`
113+
bot.sendMessage(chatId, help, { reply_to_message_id: msg.message_id })
114+
}
115+
116+
else if (msg.text == '\/start') {
117+
bot.sendMessage(chatId, 'Yo! send /help', { reply_to_message_id: msg.message_id })
118+
}
119+
});
120+
}
121+
122+
main()

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "bonkmeet",
3+
"version": "1.0.0",
4+
"description": "A self hosted telegram bot for attending Google Meet in bahalf of you.",
5+
"main": "main.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/bunnykek/BonkMeet.git"
12+
},
13+
"keywords": [
14+
"telegram",
15+
"telegram-bot",
16+
"gmeet",
17+
"google-meet",
18+
"gmeet-bot",
19+
"google-meet-bot",
20+
"gmeet-telegram-bot"
21+
],
22+
"author": "bunny",
23+
"license": "ISC",
24+
"bugs": {
25+
"url": "https://github.com/bunnykek/BonkMeet/issues"
26+
},
27+
"homepage": "https://github.com/bunnykek/BonkMeet#readme",
28+
"dependencies": {
29+
"node-telegram-bot-api": "^0.56.0",
30+
"puppeteer": "^13.5.1"
31+
}
32+
}

0 commit comments

Comments
 (0)