diff --git a/SendTelegramNotification/task.js b/SendTelegramNotification/task.js
index 7c33542..f1f8775 100644
--- a/SendTelegramNotification/task.js
+++ b/SendTelegramNotification/task.js
@@ -2,7 +2,7 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
@@ -13,13 +13,12 @@ const Telegram = require('telegraf/telegram');
const Telegraf = require('telegraf');
const tgtools = require('./tgtools');
-
-if (tl.getBoolInput('getChatId',false)) {
+if (tl.getBoolInput('getChatId', false)) {
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
console.log("You now can get chat IDs from your chats: \n - Use /chat command to get the ID \n - Then /stop to finish the task \n\n *If something goes wrong - clear chat history*");
- const bot = new Telegraf(tl.getInput('botToken', true),{
+ const bot = new Telegraf(tl.getInput('botToken', true), {
telegram: tgtools.getProxyCfg()
});
bot.command('/chat', (ctx) => ctx.reply(ctx.chat));
@@ -34,62 +33,66 @@ if (tl.getBoolInput('getChatId',false)) {
run();
}
else {
-function run() {
- return __awaiter(this, void 0, void 0, function* () {
- try {
- var token = tl.getInput('botToken',true);
- var chats = tl.getDelimitedInput('chats',',',false);
- var body = "";
-
- if (tl.getBoolInput("taskStatus",false)) {
- switch (tl.getVariable("Agent.JobStatus")) {
- case "Succeeded":
- body += "\n✅ Task Succeeded"
- break;
- case "Failed":
- body += "\n⛔️ Task Failed"
- break;
- case "SucceededWithIssues":
- body += "\n⚠️ Task has some Issues"
- break;
- default:
- break;
- }
- }
- if (tl.getBoolInput('buildNumber', false)) {
- body += "\n#Build-" + tl.getVariable("Build.BuildNumber")+"";
- } else if (tl.getBoolInput('releaseName', false)) {
- body += "\n#" + tl.getVariable("Release.ReleaseName")+"";
- }
- if (tl.getInput('message', false) !== null) {
- var message = tl.getInput('message', false);
- body += "\n" + message;
- }
- if (tl.getBoolInput('buildQueuedBy', false)) {
- var buildQueuedBy = tl.getVariable("Build.QueuedBy");
- body += "\nBuild queued by: " + buildQueuedBy;
- }
- if (tl.getBoolInput('releaseRequestedFor', false)) {
- var releaseRequestedFor = tl.getVariable("Release.RequestedFor");
- body += "\nRelease queued by: " + releaseRequestedFor;
- }
- if (tl.getBoolInput('teamUrl', false)) {
- var teamLink = tl.getVariable("System.TeamFoundationCollectionUri");
- var project = tl.getVariable("System.TeamProject");
- body += "\nProject URL: " + tgtools.tglinkbuilder(teamLink+project, project);
- }
+ function run() {
+ return __awaiter(this, void 0, void 0, function* () {
+ try {
+ var token = tl.getInput('botToken', true);
+ var chats = tl.getDelimitedInput('chats', ',', false);
+ var messageThreadId = tl.getInput('messageThreadId', false);
+ var body = "";
+ if (tl.getBoolInput("taskStatus", false)) {
+ switch (tl.getVariable("Agent.JobStatus")) {
+ case "Succeeded":
+ body += "\n✅ Task Succeeded"
+ break;
+ case "Failed":
+ body += "\n⛔️ Task Failed"
+ break;
+ case "SucceededWithIssues":
+ body += "\n⚠️ Task has some Issues"
+ break;
+ default:
+ break;
+ }
+ }
+ if (tl.getBoolInput('buildNumber', false)) {
+ body += "\n#Build-" + tl.getVariable("Build.BuildNumber") + "";
+ } else if (tl.getBoolInput('releaseName', false)) {
+ body += "\n#" + tl.getVariable("Release.ReleaseName") + "";
+ }
+ if (tl.getInput('message', false) !== null) {
+ var message = tl.getInput('message', false);
+ body += "\n" + message;
+ }
+ if (tl.getBoolInput('buildQueuedBy', false)) {
+ var buildQueuedBy = tl.getVariable("Build.QueuedBy");
+ body += "\nBuild queued by: " + buildQueuedBy;
+ }
+ if (tl.getBoolInput('releaseRequestedFor', false)) {
+ var releaseRequestedFor = tl.getVariable("Release.RequestedFor");
+ body += "\nRelease queued by: " + releaseRequestedFor;
+ }
+ if (tl.getBoolInput('teamUrl', false)) {
+ var teamLink = tl.getVariable("System.TeamFoundationCollectionUri");
+ var project = tl.getVariable("System.TeamProject");
+ body += "\nProject URL: " + tgtools.tglinkbuilder(teamLink + project, project);
+ }
- const telegram = new Telegram(token, tgtools.getProxyCfg());
- chats.forEach(chat => {
- telegram.sendMessage(chat,body, {parse_mode: 'HTML'});
- });
- console.log('Message sent!');
- }
- catch (err) {
- tl.setResult(tl.TaskResult.Failed, err.message);
- }
- });
+ const telegram = new Telegram(token, tgtools.getProxyCfg());
+ chats.forEach(chat => {
+ const options = { parse_mode: 'HTML' };
+ if (messageThreadId) {
+ options.message_thread_id = messageThreadId;
+ }
+ telegram.sendMessage(chat, body, options);
+ });
+ console.log('Message sent!');
+ }
+ catch (err) {
+ tl.setResult(tl.TaskResult.Failed, err.message);
+ }
+ });
+ }
+ run();
}
-run();
-}
\ No newline at end of file
diff --git a/SendTelegramNotification/task.json b/SendTelegramNotification/task.json
index 54cde1e..4d7125e 100644
--- a/SendTelegramNotification/task.json
+++ b/SendTelegramNotification/task.json
@@ -59,6 +59,16 @@
"helpMarkDown": "Target chat id's to notify (use comma as a delimiter). [More information about chat id] ()",
"visibleRule":"getChatId = false"
},
+ {
+ "name": "messageThreadId",
+ "type": "string",
+ "label": "Message Thread ID",
+ "defaultValue": "",
+ "required": false,
+ "groupName": "botConfig",
+ "helpMarkDown": "Target message thread id to notify (use comma as a delimiter). [More information about message thread id] ()",
+ "visibleRule":"getChatId = false"
+ },
{
"name": "useProxy",
"type": "boolean",
@@ -177,4 +187,4 @@
"argumentFormat": ""
}
}
-}
\ No newline at end of file
+}
diff --git a/readme.md b/readme.md
index d752d96..1fecdf7 100644
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,3 @@
-
# Telegram Notifications for Azure Pipelines

Telegram Notification task uses [Telegraf - Telegram Bot Framework for Node.js](https://github.com/telegraf/telegraf) and allows you to send customizable notifications to your Telegram chats and groups.
@@ -74,3 +73,22 @@ There are some basic predefined features both for build and release tasks.
*NOTE: USE EITHER RELEASE OR BUILD RELATED OPTIONS DEPENDING ON YOUR PROCESS*

+
+## Sending Messages to Specific Topics within Supergroups
+
+To send messages to a specific topic within a supergroup, you need to specify both `chat_id` and `message_thread_id`. The `message_thread_id` parameter allows you to target a specific thread within a supergroup.
+
+### Example Configuration
+
+Here is an example of how to configure the task to send messages to a specific topic within a supergroup:
+
+```json
+{
+ "botToken": "YOUR_BOT_TOKEN",
+ "chats": "-123456678",
+ "messageThreadId": "123456789",
+ "message": "This is a message to a specific topic within a supergroup."
+}
+```
+
+In this example, replace `YOUR_BOT_TOKEN` with your actual bot token, `-123456678` with the chat ID of the supergroup, and `123456789` with the message thread ID of the specific topic within the supergroup.