text message problem with unicode (UTF8) letters.
Required Information
- Operating system: CentOS 6.x
- PHP version: 5.6
- PHP Telegram Bot version: 0.44.1
- Using MySQL database: no
- MySQL version:
- Update Method: Webhook
- Self-signed certificate: no
- RAW update (if available):
Expected behaviour
sendMessage must send unicode text to telegram.
Actual behaviour
sendMessage does not send anything to telegram unless I change text message to non-unicode (English for example).
Steps to reproduce
Extra details
Example code:
$data['text'] = "ارسال پاسخ ...";
There is good chance the text must be utf8_encode()'d (or utf8_decode()'d, can't remember) before putting it to $data['text'];
utf8_encode( $data['text'] ) returns unreadable message.
It is utf8_decode() -function you have to use.
It returns something like this: ????? ???? ...
I'm not experiencing this issue, the unicode text gets send perfectly.
Is this maybe a PHP / extension problem?
It is strange to me too @noplanman. I don't know is this a PHP/extension problem or not. There is no way to find it out. Do you have any solution to check? My server is hosting many websites and all of them are working with Unicode strings with no problem. I just have problem with my Telegram bot.
Have you tried checking what the result of sendMessage is? Telegram usually return useful error description there.
Good idea @jacklul, also maybe check the debug log if enabled (else enable it first).
Here a similar issue on a python bot: https://github.com/python-telegram-bot/python-telegram-bot/issues/27#issuecomment-129289918
@jacklul may you tell me please how can I find that error descriptions? I am new in writing Telegram bots. Also @noplanman is it possible to give me a link or some guides about debug log?
I've tested these solutions and none of them did not worked for me to solve the problem. 1- utf8_encode() 2- utf8_decode() 3- header('Content-Type: text/html; charset=utf-8');
$Result = sendMessage (xxx)
File_put_contents('log. Txt', Print_r($result, true)) ; will be the easiest way to see what telegram replied, you can also call $result - >getResult () - >getDescription ()
Forgive the format, mobile.
You can enable debug log in hook script.
Thank you @jacklul.
If I don't use utf8_encode(), I won't see any reply message in Telegram, and will get this error:
Longman\TelegramBot\Entities\ServerResponse Object
(
[ok] =>
[error_code] => 400
[description] => Bad Request: message text must be encoded in UTF-8
...
But if I use utf8_encode(), I will see the result but in this shape:
ÇÑÓÇá ÇÓÎ ...
I'm out of ideas, maybe project php files isn't set to utf8? Any chance you can test this on php7? Can you try running it locally with getUpdates? (you will have to unset webhook)
What do you mean about "maybe project php files isn't set to utf8?" ? Is there any config file that I must put settings in?
Can you try running it locally with getUpdates? (you will have to unset webhook)
As I said I am new in Telegram Bot. I will try but I don't know how much does it take time.
I mean the files itself might not be set to utf8 encoding in editor you're using.
@jacklul that's it. My editor did not support UTF-8. I changed settings and now it's working with no need to any other function. Thank you so much @jacklul