How to Integrate JetBrains YouTrack and Discord Webhooks
Since our team decided to move to Discord, we wanted to receive updates on our tasks’ states in one place. In this article we will discuss a way to setup YouTrack integration with Discord via custom Rules and Webhooks.
Discord Setup
Webhook
To create a Webhook for your server, go to Server Settings > Integrations > Webhooks > New Webhook. Give it a name, upload picture and choose a channel where new Webhook would send messages.
Copy Webhook URL and store it. Later on we will use it in our YouTrack rule to send messages.
YouTrack setup
Workflow
For purposes of this article we will create a new Workflow. Workflows are global in your space and are assigned to Projects separately. Go to Settings > Workflows, click New workflow and choose JavaScript Editor. Give it a name and a title.
Rules
Now to create our custom Rule. In the list of available Workflows click on newly created Workflow, in the right menu click Edit workflow and it will bring you to the Workflow editor.
Click On-change button to create a new Rule, give it a name. Click Save button and it will open new rule editor.
Configuring a rule
Let us write a Rule that will send message to our Discord Webhook when a new Issue is posted.
Start with giving a descriptive title for your Rule. Something like “Sends message when new issue is created” will do.
Now, import required packages: entities
and http
.
const entities = require(‘@jetbrains/youtrack-scripting-api/entities’);
const http = require(‘@jetbrains/youtrack-scripting-api/http’);
We want to send messages when new Issues are posted, not just when a new draft is created. To do so, we must write a simple guard:
const issue = ctx.issue;
return issue.becomesReported;
Now we need to write a simple action to send a message to our Webhook.
const connection = new http.Connection({webhookUrl}, null, 2000);
connection.addHeader(‘Content-Type’, ‘application/json’);
connection.postSync(‘’, null, JSON.stringify({ content: 'New issue is created' }));
Click Save in top-right corner or press Ctrl-S (Cmd-S) to save a rule.
Assigning Workflows to Projects
As I wrote earlier, Workflows are global in your space and are assigned to Projects separately. Go to Projects > {Your project}
> Workflows. Click Attach workflows and select our newly created Workflow from the list. In the right panel make sure “Our module” is active.
You have assigned a new Workflow to your project! Now, when a change applied to an Issue, YouTrack will go trough all of the Rules and perform described action if guard returns true.
Now go and try to create a new Isue!
Further reading
For Discord Webhooks, there is an unofficial Discord Webhooks Guide that greatly describes all of the rules, abilities and properties of Webhooks.
As for YouTrack, there is an official Developer Portal for YouTrack and Hub.
Final code snippet for a rule you can check out here.