-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
139 lines (110 loc) · 3.01 KB
/
bot.js
File metadata and controls
139 lines (110 loc) · 3.01 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const TelegramBot = require('node-telegram-bot-api');
require('dotenv').config();
const token = process.env.TELEGRAM_BOT_TOKEN;
const webAppUrl = process.env.WEB_APP_URL;
if (!token) {
console.error('TELEGRAM_BOT_TOKEN is not set in environment variables');
process.exit(1);
}
// Create a bot instance
const bot = new TelegramBot(token, { polling: true });
// Start command
bot.onText(/\/start/, (msg) => {
const chatId = msg.chat.id;
const firstName = msg.from.first_name || 'there';
const welcomeMessage = `
Welcome to CAPT Garuda Lounge Booking Bot, ${firstName}! 🏢
This bot helps you book time slots at the CAPT Garuda Lounge.
Click the button below to open the booking app:
`;
const options = {
reply_markup: {
inline_keyboard: [
[
{
text: '📅 Book a Slot',
web_app: { url: webAppUrl }
}
],
[
{
text: '📖 Help',
callback_data: 'help'
}
]
]
}
};
bot.sendMessage(chatId, welcomeMessage, options);
});
// Help command
bot.onText(/\/help/, (msg) => {
const chatId = msg.chat.id;
const helpMessage = `
📖 *Help - CAPT Garuda Lounge Booking*
*How to book:*
1. Click "Book a Slot" button
2. Select a date from the calendar
3. Choose an available time slot
4. Add any notes (optional)
5. Confirm your booking
*Features:*
• View available time slots in real-time
• Manage your bookings
• Cancel bookings if needed
• Mobile-friendly interface
*Commands:*
/start - Start the bot
/book - Open booking app
/help - Show this help message
Need assistance? Contact the lounge administrator.
`;
bot.sendMessage(chatId, helpMessage, { parse_mode: 'Markdown' });
});
// Book command
bot.onText(/\/book/, (msg) => {
const chatId = msg.chat.id;
const options = {
reply_markup: {
inline_keyboard: [
[
{
text: '📅 Open Booking App',
web_app: { url: webAppUrl }
}
]
]
}
};
bot.sendMessage(chatId, 'Click the button below to open the booking app:', options);
});
// Handle callback queries
bot.on('callback_query', (query) => {
const chatId = query.message.chat.id;
if (query.data === 'help') {
const helpMessage = `
📖 *Help - CAPT Garuda Lounge Booking*
*How to book:*
1. Click "Book a Slot" button
2. Select a date from the calendar
3. Choose an available time slot
4. Add any notes (optional)
5. Confirm your booking
*Features:*
• View available time slots in real-time
• Manage your bookings
• Cancel bookings if needed
• Mobile-friendly interface
`;
bot.sendMessage(chatId, helpMessage, { parse_mode: 'Markdown' });
}
// Answer callback query to remove loading state
bot.answerCallbackQuery(query.id);
});
// Handle errors
bot.on('polling_error', (error) => {
console.error('Polling error:', error.code, error.response?.body);
});
console.log('Telegram bot is running...');
console.log('Web App URL:', webAppUrl);
module.exports = bot;