This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
89 lines (74 loc) · 2 KB
/
main.js
File metadata and controls
89 lines (74 loc) · 2 KB
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
const TelegramBot = require("node-telegram-bot-api");
const botway = require("botway.js");
const request = require("request");
const options = {
polling: true,
};
const bot = new TelegramBot(botway.GetToken(), options);
// Matches /photo
bot.onText(/\/photo/, function onPhotoText(msg) {
// From file path
const photo = request(
"https://raw.githubusercontent.com/botwayorg/telegram-nodejs/main/bot.gif"
);
bot.sendPhoto(msg.chat.id, photo, {
caption: "I'm a bot!",
});
});
// Matches /crypto
bot.onText(/\/crypto/, function onFavoriteCryptoText(msg) {
const opts = {
reply_to_message_id: msg.message_id,
reply_markup: JSON.stringify({
keyboard: [
["BTC", "ETH", "LTC"],
["EOS", "XRP", "SOL"],
],
}),
};
bot.sendMessage(msg.chat.id, "What is your favorite crypto currency?", opts);
});
// Matches /audio
bot.onText(/\/audio/, function onAudioText(msg) {
// From HTTP request
const url = "https://upload.wikimedia.org/wikipedia/commons/c/c8/Example.ogg";
const audio = request(url);
bot.sendAudio(msg.chat.id, audio);
});
// Matches /echo [whatever]
bot.onText(/\/echo (.+)/, function onEchoText(msg, match) {
const resp = match[1];
bot.sendMessage(msg.chat.id, resp);
});
// Matches /editable
bot.onText(/\/editable/, function onEditableText(msg) {
const opts = {
reply_markup: {
inline_keyboard: [
[
{
text: "Edit Text",
// we shall check for this value when we listen
// for "callback_query"
callback_data: "edit",
},
],
],
},
};
bot.sendMessage(msg.from.id, "Original Text", opts);
});
// Handle callback queries
bot.on("callback_query", function onCallbackQuery(callbackQuery) {
const action = callbackQuery.data;
const msg = callbackQuery.message;
const opts = {
chat_id: msg.chat.id,
message_id: msg.message_id,
};
let text;
if (action === "edit") {
text = "Edited Text";
}
bot.editMessageText(text, opts);
});