I use a Telegram bot to incorporate weather alerts from a local weatherservice into my homeautomation system. Today I discovered a weird problem because the message containing the weather alert wasn't sent. If I try this in bash on Linux:
output="Nationaal Hitteplan";curl "https://api.telegram.org/botxxxxxxxxx:longsecuritycode/sendMessage?chat_id=xxxxxxxxx&text=$output"
(I removed my personal tokens in the above command of course...)
then I get a 400 Bad Request and the message is not sent.
If I change output="Nationaal Hitteplan" to output="Nationaal hitteplan" then the message is send as it is supposed to be.
I don't see what's wrong here. The term Nationaal Hitteplan is basically a set of advisories about what to do in hot weather. It has no negative meaning associated with it but apparently Telegram detects a problem.
Does someone have a solution for this except from changing the term as described above?
Asked
Active
Viewed 46 times
0

wie5Ooma
- 281
- 1
- 4
- 15
-
1Try replacing the space with %20 – xhienne Aug 06 '20 at 22:29
-
To expand on @xhienne's suggestion, try percent-encoding any strings you pass as URL parameters. – l0b0 Aug 06 '20 at 22:32
1 Answers
3
Url's that contains special characters like a space should be url-encoded.
Use the following curl command to let curl let the encoding:
token='xxxxxxxxx:longsecuritycode';
output="Nationaal Hitteplan";
curl -G \
--data-urlencode 'chat_id=1234567' \
--data-urlencode "text=${output}" \
"https://api.telegram.org/bot${token}/sendMessage"

0stone0
- 34,288
- 4
- 39
- 64
-
Thanks, that works great. It also saves on some filtering that was previously necessary. – wie5Ooma Aug 07 '20 at 18:27