php - Telegram API encode message to be sent

138

What is the encode parameters url of telegram? I usedurlencode ($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 dohttps://api.telegram.org/bot$token/sendMessage?chat_id=$chat_id&text=$message where$message is my text to be decoded

114

Answer

Solution:

just make an array and usehttp_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.

People are also looking for solutions to the problem: How do I pass JSON from PHP to jQuery

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.