mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
Enhance SendNotification to include custom message for Telegram notifications
This commit is contained in:
parent
d982a69f4d
commit
d51422e2a4
@ -62,7 +62,7 @@ func processPendingTests() {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
providerType := NotificationType(test.ProviderType)
|
providerType := NotificationType(test.ProviderType)
|
||||||
err := SendNotification(providerType, test.ProviderConfig, test)
|
err := SendNotification(providerType, test.ProviderConfig, test, "Test Notification from CoreControl")
|
||||||
|
|
||||||
if updateErr := updateTestStatus(test.ID, err == nil); updateErr != nil {
|
if updateErr := updateTestStatus(test.ID, err == nil); updateErr != nil {
|
||||||
log.Printf("Error updating test status: %v", updateErr)
|
log.Printf("Error updating test status: %v", updateErr)
|
||||||
@ -77,10 +77,10 @@ func processPendingTests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendNotification(providerType NotificationType, config json.RawMessage, test NotificationTest) error {
|
func SendNotification(providerType NotificationType, config json.RawMessage, test NotificationTest, message string) error {
|
||||||
switch providerType {
|
switch providerType {
|
||||||
case Telegram:
|
case Telegram:
|
||||||
return sendTelegramNotification(config, test)
|
return sendTelegramNotification(config, test, message)
|
||||||
case Ntfy:
|
case Ntfy:
|
||||||
return sendNtfyNotification(config, test)
|
return sendNtfyNotification(config, test)
|
||||||
case SMTP:
|
case SMTP:
|
||||||
@ -90,7 +90,7 @@ func SendNotification(providerType NotificationType, config json.RawMessage, tes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendTelegramNotification(config json.RawMessage, test NotificationTest) error {
|
func sendTelegramNotification(config json.RawMessage, test NotificationTest, message string) error {
|
||||||
var cfg struct {
|
var cfg struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
ChatID string `json:"chat_id"`
|
ChatID string `json:"chat_id"`
|
||||||
@ -101,7 +101,7 @@ func sendTelegramNotification(config json.RawMessage, test NotificationTest) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiUrl := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s",
|
apiUrl := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s",
|
||||||
cfg.Token, cfg.ChatID, "Test Notification")
|
cfg.Token, cfg.ChatID, message)
|
||||||
|
|
||||||
resp, err := http.Get(apiUrl)
|
resp, err := http.Get(apiUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user