Using the HTTP API of telegram to send message in PHP like the following:
$msg = "New Comment is **added** from:n".$domain; file_get_contents('https://api.telegram.org/botTOKEN:CODE/sendMessage?chat_id=@MYCHANNEL&text='.$msg.'&parse_mode=markdown');
Just adding the last parameter &parse_mode=markdown
causes 400 bad request. Removing it, everything works fine.
However, removing n
from the $msg
string makes it works fine.
Now, I don’t know why the new line n
leads to 400 bad request. Also, I don’t know how to add new line to the message body!
Advertisement
Answer
urlencode()
the msg;
$msg = urlencode("New Comment is **added** from:n" . "mydomain");
The url is ended after the newline was found, therefore PHP cant send the request, resulting in a 400.