skip to Main Content

I have the following PHP code with the parse_mode=MarkdownV2 and it isn’t posting to the channel I have it linked to. I verified this works, because if I remove the parse_mode it will post to the channel. Do I have some type of formatting error before sending this to the telegram bot?

$realurl = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

$encoded = urlencode($realurl ." n**". $obj->region .' - '. $obj->org .'** - '. $_SERVER['REMOTE_ADDR'] .' Referrer: '. $_SERVER['HTTP_REFERER'] );

file_get_contents($api_path."/sendmessage?chat_id=-152445&parse_mode=MarkdownV2&disable_web_page_preview=1&text=$encoded"); 

2

Answers


  1. Chosen as BEST ANSWER

    Reason why it doesn't work is because you need to escape the following characters: . - _

    Using . - _
    

    This is the error message you get if you submit a message with . in it:

    {"ok":false,"error_code":400,"description":"Bad Request: can't parse entities: 
    Character '.' is reserved and must be escaped with the preceding '\'"}
    

  2. The Telegram MarkdownV2 Docs shows the following example for bold text:

    *bold *text*
    

    Your code shows:

    $realurl ." n**". $obj->region .' - '. $obj->org .'** - ' .
    

    So you open and close the bold tag right away, therefore nothing is shown in bold.


    You need to use a single * instead off the double **!
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search