Eliana
Eliana

Reputation: 415

Telegram API encode message to be sent

What is the encode parameters url of telegram? I used urlencode ($message) but on mobile the message is not decoded from the app. **If I don't use the encode for the message , I get an error

gateway (error 501 or 502**, I don't remember)

.

The example url is that I do https://api.telegram.org/bot$token/sendMessage?chat_id=$chat_id&text=$message where $message is my text to be decoded

Upvotes: 1

Views: 4670

Answers (1)

Arda
Arda

Reputation: 6926

just make an array and use http_build_query method. It also handles the encoding for you.

An example would be like this:

$queryStringArray = [
  'chat_id' => $chat_id,
  'text'    => $message,
];


$url = 'https://api.telegram.org/bot'.$token.'/sendMessage?'.http_build_query($queryStringArray);

I'm using this exact way in my micro Telegram bot app here.

Upvotes: 1

Related Questions