-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (36 loc) · 1.21 KB
/
app.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
import express from "express";
import { Telegraf } from "telegraf";
import { message } from "telegraf/filters";
import { showMenu, closeMenu } from "./functions/menu.js";
import { getWeather } from "./functions/weather.js";
import { getCat } from "./functions/cat.js";
export const app = express();
app.get("/", (req, res) => {
res.send(
"Hello World!<br><br>The Bot <a href='https://t.me/TestBotTheCatBot'>@TestBotTheCatBot</a> is alive!!!"
);
});
app.use((req, res) => {
res.status(404).json({ message: "Not found" });
});
// =============== Bot ===============
const bot = new Telegraf(process.env.BOT_TOKEN, {});
bot.start((ctx) => ctx.reply('Welcome to the bot! To start, write: "menu"'));
bot.on(message, async (ctx) => {
const chatId = ctx.chat.id;
if (ctx.message.text == "menu") {
showMenu(bot, chatId);
} else if (ctx.message.location) {
let weather = await getWeather(ctx);
ctx.reply(weather);
} else if (ctx.message.text == "Get the cat") {
let cat = await getCat();
ctx.reply(cat);
} else {
closeMenu(bot, chatId);
}
});
https: bot.launch();
// Enable graceful stop
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));