-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.js
64 lines (54 loc) · 2.84 KB
/
configure.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
const axios = require("axios");
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const BOT_TOKEN = "7061384825:AAFcsbmJS-btv35JILJyriZcSfQPQtz-Umg";
const question = (question) =>
new Promise((resolve) => rl.question(question, resolve));
function exitError(error) {
console.error(`Error! ${error}`);
process.exit(1);
}
const banner = `
████████╗██╗ ██╗ █████╗ ████████╗███████╗███╗ ███╗██████╗ ██╗ █████╗ ████████╗███████╗
╚══██╔══╝██║ ██║██╔══██╗ ╚══██╔══╝██╔════╝████╗ ████║██╔══██╗██║ ██╔══██╗╚══██╔══╝██╔════╝
██║ ██║ █╗ ██║███████║ ██║ █████╗ ██╔████╔██║██████╔╝██║ ███████║ ██║ █████╗
██║ ██║███╗██║██╔══██║ ██║ ██╔══╝ ██║╚██╔╝██║██╔═══╝ ██║ ██╔══██║ ██║ ██╔══╝
██║ ╚███╔███╔╝██║ ██║ ██║ ███████╗██║ ╚═╝ ██║██║ ███████╗██║ ██║ ██║ ███████╗
╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝
`;
console.log(banner);
let botUsername;
(async () => {
const accessToken = BOT_TOKEN;
if (!accessToken?.length > 0) exitError("Token is required");
const url = await question("Enter your webapp http url: ");
if (!url?.length > 0) exitError("URL is required");
const getBot = await axios
.get(`https://api.telegram.org/bot${accessToken}/getMe`)
.catch(exitError);
//
botUsername = getBot.data.result.username;
console.log(`\n\nSetting bot ${botUsername} webapp url to ${url}`);
const resp = await axios
.post(`https://api.telegram.org/bot${accessToken}/setChatMenuButton`, {
menu_button: {
type: "web_app",
text: "Launch Webapp",
web_app: {
url: url,
},
},
})
.catch(exitError);
if (resp.status === 200) {
console.log(
`\nYou're all set! Visit https://t.me/${botUsername} to interact with your bot`
);
process.exit();
} else {
exitError(`\nSomething went wrong! ${resp.error}`);
}
})();