Skip to content

Instantly share code, notes, and snippets.

@ItgLvb
Last active December 15, 2021 08:44
Show Gist options
  • Select an option

  • Save ItgLvb/282665c23fbf4dbd7964a6beae364513 to your computer and use it in GitHub Desktop.

Select an option

Save ItgLvb/282665c23fbf4dbd7964a6beae364513 to your computer and use it in GitHub Desktop.
отправка уведомлений из Youtrack
const telegram = require('./telegram-bot');
const params = {
token: "your_token",
parse_mode: "Markdown"
};
let bot = new telegram.Telegram(params);
//You can get userId via @myidbot
bot.sendMessage("subject" + '\n' + "body", "userId");
var http = require('@jetbrains/youtrack-scripting-api/http');
function Telegram(token, parse_mode) {
var me = this;
if (typeof token === 'object') {
me.token = token.token;
me.parse_mode = token.parse_mode;
} else {
me.token = token;
me.parse_mode = parse_mode;
}
this.sendMessage = function ( message, to) {
var params = {
chat_id: to,
text: message,
disable_web_page_preview: true,
disable_notification: false
},
data,
response,
connection = new http.Connection('https://api.telegram.org'),
url = '/bot' + me.token + '/sendMessage';
if (me.parse_mode !== null) {
params.parse_mode = me.parse_mode;
}
connection.addHeader('Content-Type', 'application/json');
data = JSON.stringify(params);
// console.log(data);
response = connection.postSync(url, [], data);
if (response.code !== 200) {
console.log(response);
}
};
}
exports.Telegram = Telegram;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment