Send message from YouTrack to Discord webhook on issue creation

YouTrack rule script that sends a message to Discrod webhook when issue is created.

const entities = require('@jetbrains/youtrack-scripting-api/entities');
const http = require('@jetbrains/youtrack-scripting-api/http');

exports.rule = entities.Issue.onChange({
    title: 'Sends message when new issue is created',
    guard: (ctx) => {
        const issue = ctx.issue;
        return issue.becomesReported;
    },
    action: (ctx) => {
        const issue = ctx.issue;
        const connection = new http.Connection('https://discord.webhook/url', null, 2000);
        connection.addHeader('Content-Type', 'application/json');

        connection.postSync('', null, JSON.stringify({ content: 'New issue is created' }));
    },
});
$ cd ..