Skip to content

Please add the functionality to send alerts to Telegram threads. #3115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

DevOpsSim
Copy link

@DevOpsSim DevOpsSim commented Jun 30, 2025

Could you please add functionality to send alerts to Telegram - not just to the group chat, but to specific group topics as well? If that's possible, of course.

@DevOpsSim DevOpsSim changed the title Добавлен функционал отправки алертов в telegram treads Added functionality to send alerts to Telegram threads. Jul 1, 2025
@DevOpsSim DevOpsSim changed the title Added functionality to send alerts to Telegram threads. Please add the functionality to send alerts to Telegram threads. Jul 1, 2025
@fiftin fiftin requested a review from Copilot July 11, 2025 11:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for sending Telegram alerts directly into specific group topics (threads) in addition to the existing group chat functionality.

  • Introduce a new TelegramThreadID config field
  • Extend the Telegram alert template and alertChat struct to include ThreadID
  • Update sendTelegramAlert to read the thread ID and adjust the API call accordingly

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
util/config.go Add TelegramThreadID config parameter
services/tasks/templates/telegram.tmpl Conditionally include message_thread_id in JSON
services/tasks/alert.go Read thread ID in sendTelegramAlert, update API URL, and retain old commented implementation
Comments suppressed due to low confidence (2)

services/tasks/alert.go:198

  • New thread ID functionality should be covered by unit or integration tests to ensure alerts route correctly to specific Telegram topics.
    threadID := util.Config.TelegramThreadID // Новый параметр конфига

services/tasks/alert.go:198

  • This line uses spaces for indentation, but the surrounding file uses tabs; aligning with gofmt conventions will keep formatting consistent.
    threadID := util.Config.TelegramThreadID // Новый параметр конфига

@@ -261,6 +261,7 @@ type ConfigType struct {
TelegramAlert bool `json:"telegram_alert,omitempty" env:"SEMAPHORE_TELEGRAM_ALERT"`
TelegramChat string `json:"telegram_chat,omitempty" env:"SEMAPHORE_TELEGRAM_CHAT"`
TelegramToken string `json:"telegram_token,omitempty" env:"SEMAPHORE_TELEGRAM_TOKEN"`
TelegramThreadID string `json:"telegram_thread_id" env:"SEMAPHORE_TELEGRAM_THREAD_ID"` // Новый параметр
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding omitempty to the json:"telegram_thread_id" tag to keep this optional field consistent with other config values and prevent serializing empty strings.

Suggested change
TelegramThreadID string `json:"telegram_thread_id" env:"SEMAPHORE_TELEGRAM_THREAD_ID"` // Новый параметр
TelegramThreadID string `json:"telegram_thread_id,omitempty" env:"SEMAPHORE_TELEGRAM_THREAD_ID"` // Новый параметр

Copilot uses AI. Check for mistakes.

Comment on lines +114 to +134
//func (t *TaskRunner) sendTelegramAlert() {
// if !util.Config.TelegramAlert || !t.alert {
// return
// }
//
// if t.Template.SuppressSuccessAlerts && t.Task.Status == task_logger.TaskSuccessStatus {
// return
// }
//
// chatID := util.Config.TelegramChat
// if t.alertChat != nil && *t.alertChat != "" {
// chatID = *t.alertChat
// }
//
// if chatID == "" {
// return
// }
//
// body := bytes.NewBufferString("")
// author, version := t.alertInfos()
//
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the large commented-out block of the old sendTelegramAlert implementation to reduce dead code and improve readability.

Suggested change
//func (t *TaskRunner) sendTelegramAlert() {
// if !util.Config.TelegramAlert || !t.alert {
// return
// }
//
// if t.Template.SuppressSuccessAlerts && t.Task.Status == task_logger.TaskSuccessStatus {
// return
// }
//
// chatID := util.Config.TelegramChat
// if t.alertChat != nil && *t.alertChat != "" {
// chatID = *t.alertChat
// }
//
// if chatID == "" {
// return
// }
//
// body := bytes.NewBufferString("")
// author, version := t.alertInfos()
//
// Removed commented-out block of the old `sendTelegramAlert` implementation to reduce dead code and improve readability.

Copilot uses AI. Check for mistakes.

Comment on lines +253 to +261
// Если указан threadID, добавляем его как параметр запроса
if threadID != "" {
apiUrl += fmt.Sprintf("?message_thread_id=%s", threadID)
}

resp, err := http.Post(
apiUrl,
"application/json",
body,
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appending message_thread_id as a query parameter duplicates the JSON payload and may not be supported by the Telegram API; it would be more reliable to include this field only in the JSON body generated by the template.

Suggested change
// Если указан threadID, добавляем его как параметр запроса
if threadID != "" {
apiUrl += fmt.Sprintf("?message_thread_id=%s", threadID)
}
resp, err := http.Post(
apiUrl,
"application/json",
body,
// Include threadID in the JSON payload if specified
if threadID != "" {
alert["message_thread_id"] = threadID
}
resp, err := http.Post(
apiUrl,
"application/json",
bytes.NewBuffer(body.Bytes()),

Copilot uses AI. Check for mistakes.

@P3TP0
Copy link

P3TP0 commented Jul 14, 2025

@fiftin so, can you add this functionality and publish an updated public image, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants