-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 includeThreadID
- 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"` // Новый параметр |
There was a problem hiding this comment.
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.
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.
//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() | ||
// |
There was a problem hiding this comment.
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.
//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.
// Если указан threadID, добавляем его как параметр запроса | ||
if threadID != "" { | ||
apiUrl += fmt.Sprintf("?message_thread_id=%s", threadID) | ||
} | ||
|
||
resp, err := http.Post( | ||
apiUrl, | ||
"application/json", | ||
body, |
There was a problem hiding this comment.
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.
// Если указан 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.
@fiftin so, can you add this functionality and publish an updated public image, please? |
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.