-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.js
127 lines (122 loc) · 2.57 KB
/
functions.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var reply_messages = require("./sites_info");
var conf = require("./secrets.json");
// var messages = reply_messages.messages;
var info = reply_messages.info;
var request = require("request");
var telegram_url =
"https://api.telegram.org/bot" + conf.spider_query_token + "/";
var info = reply_messages.info;
var messages = reply_messages.messages;
var query = reply_messages.query;
function send_greeting_sites(message) {
let keyboard = {
keyboard: [
[
{
text: info.mess.text
},
{ text: info.od.text }
],
[
{
text: info.scient.text
},
{
text: info.hostel.text
}
],
[
{
text: info.sportsfete.text
},
{
text: info.spider.text
}
],
[
{
text: info.general.text
}
]
]
};
data = {
chat_id: message.from.id,
text: "Hello, " + message.from.first_name + "!\n" + messages.start,
reply_markup: JSON.stringify(keyboard)
};
// send_message("sendMessage", message.from.id, data, res);
return data;
}
function send_query_type(message) {
let keyboard = {
keyboard: [
[
{
text: query.complaint.text
}
],
[
{
text: query.feature.text
}
],
[
{
text: query.feedback.text
}
]
]
};
data = {
text: messages.query,
chat_id: message.from.id,
reply_markup: JSON.stringify(keyboard)
};
return data;
}
function select_site(site_name) {
for (let site in info) {
if (info[site].text == site_name) return info[site].callback_data;
}
return null;
}
function select_query_type(query_string) {
for (let query_type in query) {
if (query[query_type].text === query_string) return query[query_type].text;
}
return null;
}
function send_final_question(message, user_map_dict) {
data = {
text: messages.reply + user_map_dict["site"] + " ?",
chat_id: message.from.id,
reply_markup: {
remove_keyboard: true
}
};
return data;
}
function handleStart(user_state_map, message) {
user_state_map[message.from.id] = {};
data = send_greeting_sites(message);
return data;
}
async function send_message(url, data) {
data.parse_mode = "HTML";
request.post(telegram_url + url, {
json: data,
function(error, response, body) {
return response.statusCode;
}
});
}
module.exports = {
send_greeting_sites,
send_message,
send_query_type,
select_site,
handleStart,
select_query_type,
send_final_question
};