telegram keyboard not showing non English languages chracters?

浪子不回头ぞ 提交于 2020-01-06 08:16:12

问题


I'm trying to write a php telegram bot in Persian which is a non English utf8 language. when I try to send plain text in Persian to my client it works perfectly ok

    $array = [
    "chat_id" => $chat_id,
    "text" => $someNonEnglishText
];
$telegram->sendMessage($array);

but when I try to send keyboard data with the code below it just show some question marks like ???????????????? on my keyboard buttons

    $reply_markup = $telegram->replyKeyboardMarkup([
  'keyboard' => $someNonEnglishkeyboard, 
  'resize_keyboard' => true, 
  'one_time_keyboard' => true
   ]);
    $telegram->sendMessage([
  'chat_id' => $updates[0]->getMessage()->getChat()->getId(), 
  'text' => $something,
  'reply_markup' => $reply_markup
]);

an I'm perfectly sure that my bot php file is utf8 by running the following command in terminal file myfile.php whilch I got the answer: surveyBot.php: PHP script, UTF-8 Unicode text

can someone help?

ps:the above code works perfectly fine for English keyboard.


回答1:


Instead of using specific telegram framework, use following code (just for test purposes). Change chat_id and BOT_TOKEN variables. When this code runs, if you receive healthy keyboard then your framework has problem with utf-8.($telegram belonging class in your code)

<?php

$chat_id = 123; //replace with your client chat id
define('BOT_TOKEN','1234:xyz'); //replace with your token

define('BOTAPI','https://api.telegram.org/bot' . BOT_TOKEN .'/');
$reply_markup = [
    'keyboard'          => [[['text' => 'سلام'], ['text' => 'خدانگهدار']]],
    'resize_keyboard'   => true,
    'one_time_keyboard' => true,
];
$data = [
    'chat_id'      => $chat_id,
    'text'         => 'utf-8 test',
    'reply_markup' => json_encode($reply_markup),
];
$ch = curl_init(BOTAPI . 'sendMessage');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);


来源:https://stackoverflow.com/questions/38501810/telegram-keyboard-not-showing-non-english-languages-chracters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!