forked from harelsarag7/Wolt-s-Reminder---Telegram-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
36 lines (32 loc) · 1.17 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const TelegramBot = require('node-telegram-bot-api');
const fetch = require('node-fetch');
const token = '6010124037:AAG9MTD6RIIIqnzXgFU8jS0AUAQsrl1gudA';
const bot = new TelegramBot(token, { polling: true });
bot.on('message', msg => {
const linkRegex = /https:\/\/restaurant-api\.wolt\.com\/v3\/venues\/slug\/\w+/;
const link = msg.text
console.log(msg);
console.log(link);
if (link) {
const chatId = msg.chat.id;
const intervalId = setInterval(() => {
fetch(link)
.then(res => res.json())
.then(data => {
console.log(data);
// const deliveryEnabled = data.results[0].delivery_specs.delivery_enabled;
// if (deliveryEnabled) {
// bot.sendMessage(chatId, 'The restaurant is open for delivery!');
// clearInterval(intervalId);
// } else {
// bot.sendMessage(chatId, 'The restaurant is closed for delivery. Checking again...');
// }
})
.catch(error => {
bot.sendMessage(chatId, 'Error checking delivery status. Please try again later.');
clearInterval(intervalId);
console.log(error);
});
}, 10000);
}
});