-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (29 loc) · 905 Bytes
/
server.js
File metadata and controls
35 lines (29 loc) · 905 Bytes
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
// server.js
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const axios = require("axios");
const app = express();
const PORT = process.env.PORT || 3000;
const TELEGRAM_TOKEN = process.env.TELEGRAM_TOKEN;
app.use(cors());
app.use(express.json());
app.post("/send", async (req, res) => {
const { chat_id, text } = req.body;
if (!chat_id || !text) {
return res.status(400).json({ error: "chat_id et text requis" });
}
try {
const telegramResp = await axios.post(
`https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage`,
{ chat_id, text }
);
res.json(telegramResp.data);
} catch (err) {
console.error(err.response?.data || err.message);
res.status(500).json({ error: "Échec", details: err.response?.data });
}
});
app.listen(PORT, () => {
console.log(`Proxy prêt sur http://localhost:${PORT}`);
});