Skip to content

Create node.js #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const express = require('express');
const axios = require('axios');
const bodyParser = require('body-parser');

const app = express();
const port = 3000;

app.use(bodyParser.json());

app.post('/webhook', (req, res) => {
const event = req.headers['x-github-event'];

if (event === 'project') {
const project = req.body.project;
const message = `New project added: ${project.name}\nDescription: ${project.body}`;

const telegramToken = '7049099132:AAFp_1wARz3TS23I3qpE9x5ScbLIVUKHy-w';
const chatId = '@shishifanyi_bot';
const telegramUrl = `https://api.telegram.org/bot${telegramToken}/sendMessage`;

axios.post(telegramUrl, {
chat_id: chatId,
text: message
}).then(response => {
console.log('Message sent to Telegram:', response.data);
}).catch(error => {
console.error('Error sending message to Telegram:', error);
});
}

res.status(200).end();
});

app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});