Coder Social home page Coder Social logo

youtrack-telegram-bot's Introduction

YouTrack Telegram Bot

This application gets updates from YouTrack and publishes them into Telegram Channels.

Installation

Install NodeJS

For example, on ubuntu one can run following commands to install node.js:

sudo apt-get install -y build-essential
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install nodejs

Copy project into some dir, from now on we will refer it as appdir. Install dependencies.

cd /appdir
npm install

Set appropriate configurations in src/bot-config.json file.

Create last directory in appdir folder, make it writable by the application. It will contain last update time file for each project.

You can run application and check logs with the following commands:

npm start
tail -f /appdir/app.log

Or configure cron task to run bot on each minute like the following:

*/2 * * * * cd /appdir && /usr/bin/node ./src/app.js >> ./app.log 2>&1

It is also possible to run the bot via pm2 with cron_restart option. Sample configuration for pm2 may look like to the following:

{
  "name": "youtrack-bot",
  "script": "/appdir/src/app.js",
  "node_args": [
    "--harmony"
  ],
  "env": {
    "DEBUG": "youtrack:*",
    "DEBUG_DEPTH": 10,
    "DEBUG_COLORS": 0
  },
  "log_date_format": "YYYY-MM-DD HH:mm:ss Z",
  "out_file": "/appdir/logs/youtrack_bot.log",
  "error_file": "/appdir/logs/youtrack_bot_error.log",
  "exec_mode": "cluster",
  "instances": 1,
  "cron_restart": "*/2 * * * *"
}

Run command maybe something like this:

sudo pm2 start /appdir/src/app.json

Configuration

You can assign each project to own Telegram Channel via chatId.

If the channel is public, chatId may contain channel name, like @myPublicChannel.

If the channel is private, then make a channel public, send a test request to the channel from the browser like the following:

https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage?chat_id=@myTemporaryPublicChannel&text=test
https://api.telegram.org/bot258108210:BAFN7INaQc0MP1GlDe9SxCm-cjc0hz-zWdw/sendMessage?chat_id=@myTemporaryPublicChannel&text=test

After that you can make channel private again.

Response will contain the channel's numeric ID, like the following:

{
  "ok": true,
  "result": {
    "message_id": 2,
    "chat": {
      "id": -1001072411791,
      "title": "myTemporaryPublicChannel",
      "username": "myTemporaryPublicChannel",
      "type": "channel"
    },
    "date": 1472985422,
    "text": "test"
  }
}

In the above example -1001072411791 is the channel ID.

authType accepts oauth2.

Demo configuration is here:

{
	"youtrack": {
		"authType": "oauth2",
		"oauth2": {
			"url": "https://myorgatization.myjetbrains.com/hub/api/rest/oauth2/token",
			"clientServiceId": "7fec3de9-0040-43c9-bf3e-3c4a2250ba02",
			"clientServiceSecret": "73f1de76-9ece-4408-85d3-cf683a0a614e",
			"scope": "7fec3de9-0040-43c9-bf3e-3c4a2250ba02"
		}
	},
	"telegram": {
		"defaultToken": "258108210:BAFN7INaQc0MP1GlDe9SxCm-cjc0hz-zWdw",
		"projects": [
			{
				"token": "555108275:AAFN7INaQc0MP1GlAe9SxCm-cjc0hz-zAdw",
				"projectName": "PROJ1_ID_FROM_YOUTRACK",
				"chatId": "-1001072411791"
			},
			{
				"token": "111108275:AAFN7INaQc0MP1GlAe9SxCm-cjc0hz-zAdw",
				"projectName": "PROJ2_ID_FROM_YOUTRACK",
				"chatId": "-1001072411792"
			}
		]
	}
}

defaultToken - Telegram Token for all projects, that doesn't have own token.

projects.token - Telegram Token for the specific project.

projectName - project ID from YouTrack.

Additional Notes

Issue updates may be duplicated, if there is difference between Youtrack and Bot date time. Consider avoiding such problems with NTP or something like it.

youtrack-telegram-bot's People

Contributors

umidjons avatar

Watchers

Dmitriy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.