Skip to content

Commit 8989e84

Browse files
committed
feat: add IS_TEST_BOT configuration and update version command response
1 parent 0291d1a commit 8989e84

5 files changed

Lines changed: 36 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Create a `.env` file in the project root with the following variables:
6767
| NOTION_API_KEY | Notion API key |
6868
| NOTION_DATABASE_ID | Notion database ID |
6969
| ADMIN_CHAT_ID | Telegram chat ID for admin group notifications |
70+
| IS_TEST_BOT | Set to true to append "- test" to the version reply |
7071

7172
## Bot Commands
7273

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
jest.resetModules();
2-
3-
jest.doMock("../../../../package.json", () => ({ version: "1.2.3" }));
4-
jest.doMock("../../../../bot/config", () => ({ ALLOWED_GROUPS: [999] }));
5-
6-
const versionModule = require("../../../../bot/handlers/commands/version");
1+
const loadModule = (configOverrides = {}) => {
2+
jest.resetModules();
3+
jest.doMock("../../../../package.json", () => ({ version: "1.2.3" }));
4+
jest.doMock("../../../../bot/config", () => ({
5+
ALLOWED_GROUPS: [999],
6+
IS_TEST_BOT: false,
7+
...configOverrides,
8+
}));
9+
return require("../../../../bot/handlers/commands/version");
10+
};
711

812
test("version replies in group when allowed", () => {
913
const replies = [];
@@ -12,8 +16,21 @@ test("version replies in group when allowed", () => {
1216
reply: (text) => replies.push(text),
1317
};
1418
const bot = { command: (name, fn) => fn(ctx) };
19+
const versionModule = loadModule();
20+
versionModule(bot);
21+
expect(replies[0]).toBe("🤖 Bot version: 1.2.3");
22+
});
23+
24+
test("version replies with test suffix when bot is flagged as test", () => {
25+
const replies = [];
26+
const ctx = {
27+
chat: { type: "group", id: 999 },
28+
reply: (text) => replies.push(text),
29+
};
30+
const bot = { command: (name, fn) => fn(ctx) };
31+
const versionModule = loadModule({ IS_TEST_BOT: true });
1532
versionModule(bot);
16-
expect(replies[0]).toMatch(/Bot version: 1.2.3/);
33+
expect(replies[0]).toBe("🤖 Bot version: 1.2.3 - test");
1734
});
1835

1936
test("version does not reply for private chat", () => {
@@ -23,6 +40,7 @@ test("version does not reply for private chat", () => {
2340
reply: (text) => replies.push(text),
2441
};
2542
const bot = { command: (name, fn) => fn(ctx) };
43+
const versionModule = loadModule();
2644
versionModule(bot);
2745
expect(replies.length).toBe(0);
2846
});

bot/config/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const config = {
55
PORT: process.env.PORT || 3000,
66
PERPLEXITY_API_KEY: process.env.PERPLEXITY_API_KEY,
77
ENCRYPTION_KEY: process.env.ENCRYPTION_KEY,
8+
IS_TEST_BOT:
9+
typeof process.env.IS_TEST_BOT === "string" &&
10+
process.env.IS_TEST_BOT.toLowerCase() === "true",
811
USERNAME_SPECIAL_FN: process.env.USERNAME_SPECIAL_FN,
912
ALLOWED_GROUPS: (process.env.ALLOWED_GROUPS || "")
1013
.split(",")

bot/handlers/commands/version.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const { version } = require("../../../package.json");
2-
const { ALLOWED_GROUPS } = require("../../config");
2+
const { ALLOWED_GROUPS, IS_TEST_BOT } = require("../../config");
33

44
module.exports = (bot) => {
55
bot.command("version", (ctx) => {
66
if (
77
ctx.chat.type !== "private" &&
88
ALLOWED_GROUPS.includes(ctx.chat.id)
99
) {
10-
ctx.reply(`🤖 Bot version: ${version}`);
10+
const versionLabel = IS_TEST_BOT ? `${version} - test` : version;
11+
ctx.reply(`🤖 Bot version: ${versionLabel}`);
1112
}
1213
});
1314
};

bot/services/perplexity.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ async function sendToPerplexity(input, photoUrls) {
99
const timeout = setTimeout(() => controller.abort(), 90000);
1010

1111
try {
12+
console.log("photoUrls>>", photoUrls);
13+
1214
const options = {
1315
...createOptions.createOptions(
1416
PERPLEXITY_API_KEY,
@@ -23,6 +25,8 @@ async function sendToPerplexity(input, photoUrls) {
2325
options
2426
);
2527

28+
// console.log(options);
29+
2630
if (!res.ok) {
2731
const status = res.status;
2832
const body = await res.text();

0 commit comments

Comments
 (0)