-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
70 lines (65 loc) · 1.76 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const TelegramBot = require('node-telegram-bot-api');
const ogs = require('open-graph-scraper');
const firebase = require('firebase');
// Bot config
const token = '';
const bot = new TelegramBot(token, {polling: true});
// Init Firebase
const app = firebase.initializeApp({
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
});
const ref = firebase.database().ref();
const sitesRef = ref.child("sites");
let siteUrl;
// Reply to /bookmark
bot.onText(/\/bookmark (.+)/, (msg, match) => {
siteUrl = match[1];
bot.sendMessage(msg.chat.id,'Got it, in which category?', {
reply_markup: {
inline_keyboard: [[
{
text: 'Development',
callback_data: 'development'
},{
text: 'Music',
callback_data: 'music'
},{
text: 'Cute monkeys',
callback_data: 'cute-monkeys'
}
]]
}
});
});
// Callback query
bot.on("callback_query", (callbackQuery) => {
const message = callbackQuery.message;
// Scrap OG date
ogs({'url': siteUrl}, function (error, results) {
if(results.success) {
// Push to Firebase
sitesRef.push().set({
name: results.data.ogSiteName,
title: results.data.ogTitle,
description: results.data.ogDescription,
url: siteUrl,
thumbnail: results.data.ogImage.url,
category: callbackQuery.data
});
// Reply
bot.sendMessage(message.chat.id,'Added \"' + results.data.ogTitle +'\" to category \"' + callbackQuery.data + '\"!');
} else {
// Push to Firebase
sitesRef.push().set({
url: siteUrl
});
// Reply
bot.sendMessage(message.chat.id,'Added new website, but there was no OG data!');
}
});
});