{"size": 747, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "denexapp/gitlab-telegram-bot", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "index.js", "max_issues_repo_name": "denexapp/gitlab-telegram-bot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "denexapp/gitlab-telegram-bot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9, "max_line_length": 110, "alphanum_fraction": 0.6586345382}
const Koa = require('koa');
const TelegramBot = require('node-telegram-bot-api');
const bodyParser = require('koa-bodyparser');

const { gitlabToken, telegramToken, chatId, PORT } = process.env;

const bot = new TelegramBot(telegramToken, { polling: true });

bot.on('message', msg => {
  bot.sendMessage(
    msg.chat.id,
    "There's been an error processing your request. Details can be found at this page: https://bit.ly/2O74ow6"
  );
});

const app = new Koa();
app.use(bodyParser({ enableTypes: ['json'] }));

app.use(async ctx => {
  ctx.body = '';

  if (ctx.headers['x-gitlab-token'] === gitlabToken) {
    const { body } = ctx.request;
    text = JSON.stringify(body);
    await bot.sendMessage(chatId, text);
  }
});

app.listen(PORT);
