<commit_before>const express = require('express');
const compression = require('compression');
const app = require('express')();
const bodyParser = require('body-parser');
const http = require('http').Server(app);
const io = require('socket.io')(http);
const request = require('request');

app.use(express.static('dist', {index: 'demo.html'}));
app.use(compression());
app.use(bodyParser.json());

function sendTelegramMessage(chatId, text) {
    console.log("[chat-" + chatId + "] " + text);
    request
        .post('https://api.telegram.org/bot' + process.env.TELEGRAM_TOKEN + '/sendMessage')
        .form({
            "chat_id": chatId,
            "text": text,
            "parse_mode": "Markdown"
        });
}

app.post('/hook', function(req, res){
    const chatId = req.body.message.chat.id;
    const name = req.body.message.chat.first_name || "admin";
    const text = req.body.message.text || "";
    const reply = req.body.message.reply_to_message;

    if (text.startsWith("/start")) {
        sendTelegramMessage(chatId,
            "*Welcome to Intergram* \n" +
            "Your unique chat id is `" + chatId + "`\n" +
            "Use it to link between the embedded chat and this telegram chat");
    } else if (reply){
        let replyText = reply.text || "";
        let userId = replyText.split(':')[0];
        io.emit(chatId + "-" + userId, name + ": " + text);
    } else {
        io.emit(chatId, name + ": " + text);
    }

    res.statusCode = 200;
    res.end();
});

io.on('connection', function(client){

    client.on('register', function(registerMsg){
        let userId = registerMsg.userId;
        let chatId = registerMsg.chatId;
        let messageReceived = false;

        client.on('message', function(msg) {
            messageReceived = true;<commit_msg>simple group and channel support<commit_after>const express = require('express');
const compression = require('compression');
const app = require('express')();
const bodyParser = require('body-parser');
const http = require('http').Server(app);
const io = require('socket.io')(http);
const request = require('request');

app.use(express.static('dist', {index: 'demo.html'}));
app.use(compression());
app.use(bodyParser.json());

function sendTelegramMessage(chatId, text) {
    console.log("[chat-" + chatId + "] " + text);
    request
        .post('https://api.telegram.org/bot' + process.env.TELEGRAM_TOKEN + '/sendMessage')
        .form({
            "chat_id": chatId,
            "text": text,
            "parse_mode": "Markdown"
        });
}

app.post('/hook', function(req, res){
    try {
        const message = req.body.message || req.body.channel_post;
        const chatId = message.chat.id;
        const name = message.chat.first_name || message.chat.title || "admin";
        const text = message.text || "";
        const reply = message.reply_to_message;

        if (text.startsWith("/start")) {
            sendTelegramMessage(chatId,
                "*Welcome to Intergram* \n" +
                "Your unique chat id is `" + chatId + "`\n" +
                "Use it to link between the embedded chat and this telegram chat");
        } else if (reply) {
            let replyText = reply.text || "";
            let userId = replyText.split(':')[0];
            io.emit(chatId + "-" + userId, name + ": " + text);
        } else if (text){
            io.emit(chatId, name + ": " + text);
        }

    } catch (e) {
        console.log("hook error", e);
    }
    res.statusCode = 200;
    res.end();
});

io.on('connection', function(client){

    client.on('register', function(registerMsg){
        let userId = registerMsg.userId;
        let chatId = registerMsg.chatId;
        let messageReceived = false;

        client.on('message', function(msg) {
            messageReceived = true;
{'fraction_non_alphanumeric': 0.16352694924123495, 'fraction_numerical': 0.0020931449502878076, 'mean_word_length': 2.6202651515151514, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1809873', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1144, 'n_words': 260}