-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot-datePicker.ts
37 lines (31 loc) · 1008 Bytes
/
bot-datePicker.ts
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
import Calendar from "telegram-inline-calendar";
import { Telegraf, Context } from "telegraf";
import dotenv from "dotenv";
dotenv.config();
const TOKEN: string = process.env.BOT_TOKEN || "";
const bot: Telegraf = new Telegraf(TOKEN);
const calendar: Calendar = new Calendar(bot, {
date_format: "DD-MM-YYYY",
language: "en",
bot_api: "telegraf",
});
bot.start((ctx: Context) => calendar.startNavCalendar(ctx.message));
bot.on("callback_query", (ctx: Context) => {
if (ctx.callbackQuery && ctx.callbackQuery.message) {
if (
ctx.callbackQuery.message.message_id ===
calendar.chats.get(ctx.callbackQuery.message.chat.id)
) {
const res = calendar.clickButtonCalendar(ctx.callbackQuery);
if (res !== -1) {
bot.telegram.sendMessage(
ctx.callbackQuery.message.chat.id,
"You selected: " + res
);
}
}
}
});
bot.launch();
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));