core icon indicating copy to clipboard operation
core copied to clipboard

text message problem with unicode (UTF8) letters.

Open mbsaberi opened this issue 9 years ago • 16 comments

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'] = "ارسال پاسخ ...";

mbsaberi avatar Jun 04 '17 21:06 mbsaberi

There is good chance the text must be utf8_encode()'d (or utf8_decode()'d, can't remember) before putting it to $data['text'];

jacklul avatar Jun 04 '17 22:06 jacklul

utf8_encode( $data['text'] ) returns unreadable message.

mbsaberi avatar Jun 04 '17 22:06 mbsaberi

It is utf8_decode() -function you have to use.

haiksu avatar Jun 06 '17 05:06 haiksu

It returns something like this: ????? ???? ...

mbsaberi avatar Jun 06 '17 05:06 mbsaberi

I'm not experiencing this issue, the unicode text gets send perfectly.

Is this maybe a PHP / extension problem?

noplanman avatar Jun 06 '17 09:06 noplanman

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.

mbsaberi avatar Jun 06 '17 09:06 mbsaberi

Have you tried checking what the result of sendMessage is? Telegram usually return useful error description there.

jacklul avatar Jun 06 '17 09:06 jacklul

Good idea @jacklul, also maybe check the debug log if enabled (else enable it first).

noplanman avatar Jun 06 '17 09:06 noplanman

Here a similar issue on a python bot: https://github.com/python-telegram-bot/python-telegram-bot/issues/27#issuecomment-129289918

noplanman avatar Jun 06 '17 09:06 noplanman

@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');

mbsaberi avatar Jun 06 '17 09:06 mbsaberi

$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.

jacklul avatar Jun 06 '17 09:06 jacklul

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: ÇÑÓÇá ÇÓÎ ...

mbsaberi avatar Jun 06 '17 09:06 mbsaberi

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)

jacklul avatar Jun 06 '17 09:06 jacklul

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.

mbsaberi avatar Jun 06 '17 09:06 mbsaberi

I mean the files itself might not be set to utf8 encoding in editor you're using.

jacklul avatar Jun 06 '17 13:06 jacklul

@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

mbsaberi avatar Jun 06 '17 14:06 mbsaberi