Skip to content

Commit 8abef70

Browse files
committed
feat: Add self-ping helper, root endpoint, and bot base URL config to keep the bot alive.
1 parent 4d6821d commit 8abef70

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { bot } from "./services/telegraf.js";
44

55
const app = express();
66

7+
app.get("/", (req, res) => {
8+
res.send("Hello World!");
9+
});
10+
711
app.use(cors());
812
app.use(express.json());
913

src/config/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const BOT_USERNAME = process.env.BOT_USERNAME;
1010
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";
13+
const TELEGRAM_BOT_BASE_URL = process.env.TELEGRAM_BOT_BASE_URL;
1314

1415
export {
1516
PORT,
@@ -19,4 +20,5 @@ export {
1920
LEARNVERSE_BASE_URL,
2021
LEARNVERSE_API_BASE_URL,
2122
NODE_ENV,
23+
TELEGRAM_BOT_BASE_URL,
2224
};

src/helpers/self-ping.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NODE_ENV, TELEGRAM_BOT_BASE_URL } from "../config/config";
2+
3+
export function startSelfPing() {
4+
if (NODE_ENV !== "production") return;
5+
6+
setInterval(async () => {
7+
try {
8+
const res = await fetch(TELEGRAM_BOT_BASE_URL);
9+
console.log(`[KeepAlive] Pinged self: ${res.status}`);
10+
} catch (err) {
11+
console.error("[KeepAlive] Ping failed:", err);
12+
}
13+
}, 1000 * 60 * 10);
14+
}

0 commit comments

Comments
 (0)