Problem with Webhook Notification Targets

rokr

New Member
Feb 26, 2025
3
0
1
Hello everybody,

I am a big fan of all the work around proxmox and have been using it for quite some while no in my personal home lab. The "new" option to use webhooks as a notification target had me interested and I started messing around with it. After the initial setup I was able to send a test notification via my telegram bot with the following HTTP/POST:
Code:
https://api.telegram.org/bot{{ secrets.BOT_TOKEN }}/sendMessage?chat_id={{ secrets.CHAT_ID }}&text=Message:{{ url-encode message }}
Received message is: Message:This is a test of the notification target 'TelegramAlerts'.
But I was not able to receive a notification when my backup jobs failed. Looking through the different places I configured my notification matchers to match everything and my backup job to use the notification system. (By the way it is a bit confusing that when the backup job is set to use the notification system and you view the Job Details of a backup job "Notification" is shown as "Always (No target configured)" even though it is matched by a notification matcher). Finally looking at the system log with
Code:
journalctl -f
I was able to confirm that the webhook is called but I get the following error.
Code:
could not notify via target `TelegramAlerts`: failed to build http request: invalid uri character
testing with a simpler webhook template without the message content
Code:
https://api.telegram.org/bot{{ secrets.BOT_TOKEN }}/sendMessage?chat_id={{ secrets.CHAT_ID }}&text=Failed
I finally got a notification for my failed backup job. It seems like the message produced by the backup job is not properly encoded by the url-encode macro or I might be using it wrong. Any pointers to fix this would be very appreciated.
Testing the webhook without the url-encode part as just
Code:
https://api.telegram.org/bot{{ secrets.BOT_TOKEN }}/sendMessage?chat_id={{ secrets.CHAT_ID }}&text=Message:{{ message }}
already gives the same error of an invalid uri character during the test notification.
 
Last edited:
https://api.telegram.org/bot{{ secrets.BOT_TOKEN }}/sendMessage?chat_id={{ secrets.CHAT_ID }}&text=Message:{{ url-encode message }}

Hmmm, I have zero experience with Telegram's WebHook API, but I think you might need to encode the ':' as well [1].

Does the following URL work for you?

https://api.telegram.org/bot{{ secrets.BOT_TOKEN }}/sendMessage?chat_id={{ secrets.CHAT_ID }}&text=Message%3A{{ url-encode message }}

[1] https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding
 
This results in an error during the Test notification
Code:
Could not test target: https://api.telegram.org/bot<masked>/sendMessage?chat_id=<masked>&amp;text=Message%3AThis%20is%20a%20test%20of%20the%20notification%20target%20%27TelegramAlerts%27.%0A: status code 400 (500)

Also my initial test with the test notification worked and I did not encode the ":"


I have found an alternative solution by moving the message data into a Json object which gets POSTed to the Telegram API
URL:
Code:
https://api.telegram.org/bot{{ secrets.BOT_TOKEN }}/sendMessage?chat_id={{ secrets.CHAT_ID }}
Headers:
Code:
Content-Type:application/json
Body:
Code:
{
"text":"Proxmox Notification:
Severity: {{ escape severity }}

Title: {{ escape title }}

Message: {{ escape message }}"
}
 
Only encoding the ":" as "%3A" results in a correct, working test notification but the error with the real notification still persists.

Code:
https://api.telegram.org/bot{{ secrets.BOT_TOKEN }}/sendMessage?chat_id={{ secrets.CHAT_ID }}&text=Message%3A{{ url-encode message }}