This repository was archived by the owner on Feb 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (32 loc) · 1.25 KB
/
app.js
File metadata and controls
40 lines (32 loc) · 1.25 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
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
const app = express();
const port = 3030; // Port where the server will listen
// Replace 'YOUR_BOT_TOKEN' with your actual bot token
const telegramBotToken = process.env.TELEGRAM_TOKEN;
const telegramApiUrl = `https://api.telegram.org/${telegramBotToken}`;
app.use(bodyParser.json()); // Middleware to parse JSON bodies
// Endpoint for Telegram webhook
app.post('/', (req, res) => {
const message = req.body.message || req.body.edited_message;
if (message) {
console.log('Received Message:', message);
// Responding to Telegram to acknowledge receipt of the message
res.status(200).send();
} else {
res.status(400).send('No message received');
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
// Set the webhook URL
const webhookUrl = process.env.NGROCK_URL; // Replace with your public URL
axios.post(`${telegramApiUrl}/setWebhook`, { url: webhookUrl })
.then(response => {
console.log('Webhook set successfully:', response.data);
})
.catch(error => {
console.error('Error setting webhook:', error);
});
});