Skip to content

Commit 6dfb2d4

Browse files
committed
feat: implement dynamic configuration, user rate limiting, and Gemini AI integration
1 parent 99a64da commit 6dfb2d4

14 files changed

Lines changed: 964 additions & 48 deletions

.env.example

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Server Configuration
2+
PORT=3001
3+
NODE_ENV=development
4+
5+
# MongoDB
6+
MONGO_URI=mongodb://localhost:27017/learnverse-telegram-bot
7+
8+
# Telegram Bot
9+
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
10+
BOT_USERNAME=your_bot_username
11+
TELEGRAM_BOT_BASE_URL=http://localhost:3001
12+
13+
# Learnverse API
14+
# The API base URL is used for:
15+
# - Fetching study materials
16+
# - Feature flags configuration (GET /api/v1/config/telegram)
17+
LEARNVERSE_BASE_URL=https://learnverse.example.com
18+
LEARNVERSE_API_BASE_URL=https://api.learnverse.example.com
19+
20+
# Google Gemini AI (for query detection)
21+
# Get your API key from: https://makersuite.google.com/app/apikey
22+
GEMINI_API_KEY=your_gemini_api_key_here

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
"nodemon": "^3.1.11"
1717
},
1818
"dependencies": {
19+
"@google/generative-ai": "^0.21.0",
1920
"axios": "^1.13.2",
21+
"bottleneck": "^2.19.5",
2022
"cors": "^2.8.5",
2123
"dotenv": "^17.2.3",
2224
"express": "^5.2.1",
2325
"mongoose": "^9.0.1",
26+
"node-cache": "^5.1.2",
2427
"pino": "^10.1.0",
2528
"pino-pretty": "^13.1.3",
2629
"telegraf": "^4.16.3"

pnpm-lock.yaml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const LEARNVERSE_BASE_URL = process.env.LEARNVERSE_BASE_URL;
1111
const LEARNVERSE_API_BASE_URL = process.env.LEARNVERSE_API_BASE_URL;
1212
const NODE_ENV = process.env.NODE_ENV || "development";
1313
const TELEGRAM_BOT_BASE_URL = process.env.TELEGRAM_BOT_BASE_URL;
14+
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
1415

1516
export {
1617
PORT,
@@ -21,4 +22,5 @@ export {
2122
LEARNVERSE_API_BASE_URL,
2223
NODE_ENV,
2324
TELEGRAM_BOT_BASE_URL,
25+
GEMINI_API_KEY,
2426
};

src/handlers/command-handlers.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ export const startCommandHandler = async (ctx) => {
77
console.log("User:", ctx.from.username || ctx.from.id);
88

99
const welcomeMessage =
10-
`🎓 *Welcome to Learnverse Bot!*\n\n` +
11-
`I can help you access:\n` +
12-
`• 📁 Files & Study Materials\n` +
13-
`• 📚 Syllabuses & PDFs\n` +
14-
`• 📝 Notes & Resources\n\n` +
15-
`Use /search to find links to files, syllabuses & notes!\n` +
16-
`Use /help to see all available commands.`;
10+
`Meow! I'm Luna 🐱\n\n` +
11+
`I help students find study materials - notes, PYQs, syllabuses, you name it.\n` +
12+
`Everything's organized and ready for you.\n\n` +
13+
`Try /search to get started, or /help if you need guidance.\n\n` +
14+
`Happy studying!`;
1715

1816
await ctx.reply(welcomeMessage, {
1917
parse_mode: "Markdown",
2018
...Markup.inlineKeyboard([
21-
[Markup.button.url("📢 Join Telegram Group", TELEGRAM_GROUP_LINK)],
19+
[Markup.button.url("Join Study Group", TELEGRAM_GROUP_LINK)],
2220
]),
2321
});
2422
console.log("Start command executed successfully");
@@ -29,18 +27,18 @@ export const helpCommandHandler = async (ctx) => {
2927
console.log("User:", ctx.from.username || ctx.from.id);
3028

3129
const helpMessage =
32-
`🤖 *Learnverse Bot Help*\n\n` +
33-
`I am here to help you access study materials, notes, and syllabuses easily.\n\n` +
34-
`*Available Commands:*\n` +
35-
`/search - 🔍 Find file, syllabus & notes links\n` +
36-
`/help - ℹ️ Show this help message\n` +
37-
`/start - 🔄 Restart the bot session\n\n` +
38-
`_Select /search to browse materials by Branch > Year > Subject_`;
30+
`Luna here! 🐱\n\n` +
31+
`I've organized all your study materials - just tell me what you need.\n\n` +
32+
`*Commands:*\n` +
33+
`/search - Browse materials by branch, year, and subject\n` +
34+
`/help - Show this message\n` +
35+
`/start - Start over\n\n` +
36+
`Pro tip: Use /search and I'll guide you through everything step by step. `;
3937

4038
await ctx.reply(helpMessage, {
4139
parse_mode: "Markdown",
4240
...Markup.inlineKeyboard([
43-
[Markup.button.url("📢 Join Telegram Group", TELEGRAM_GROUP_LINK)],
41+
[Markup.button.url("Join Study Group", TELEGRAM_GROUP_LINK)],
4442
]),
4543
});
4644
console.log("Help command executed successfully");

0 commit comments

Comments
 (0)