-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathindex.js
62 lines (54 loc) · 1.83 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
async function main() {
const { Telegraf, Markup } = require("telegraf");
const { getDetails } = require("./api");
const { sendFile } = require("./utils");
const express = require("express");
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.start(async (ctx) => {
try {
ctx.reply(
`Hi ${ctx.message.from.first_name},\n\nI can Download Files from Terabox.\n\nMade with ❤️ by @botcodes123\n\nSend any terabox link to download.`,
Markup.inlineKeyboard([
Markup.button.url(" Channel", "https://t.me/botcodes123"),
Markup.button.url("Report bug", "https://t.me/Armanidrisi_bot"),
]),
);
} catch (e) {
console.error(e);
}
});
bot.on("message", async (ctx) => {
if (ctx.message && ctx.message.text) {
const messageText = ctx.message.text;
if (
messageText.includes("terabox.com") ||
messageText.includes("teraboxapp.com")
) {
//const parts = messageText.split("/");
//const linkID = parts[parts.length - 1];
// ctx.reply(linkID)
const details = await getDetails(messageText);
if (details && details.direct_link) {
try {
ctx.reply(`Sending Files Please Wait.!!`);
sendFile(details.direct_link, ctx);
} catch (e) {
console.error(e); // Log the error for debugging
}
} else {
ctx.reply('Something went wrong 🙃');
}
console.log(details);
} else {
ctx.reply("Please send a valid Terabox link.");
}
} else {
//ctx.reply("No message text found.");
}
});
const app = express();
// Set the bot API endpoint
app.use(await bot.createWebhook({ domain: process.env.WEBHOOK_URL }));
app.listen(process.env.PORT || 3000, () => console.log("Server Started"));
}
main();