telegram - php Telegram Bot 中的ReplyMarkup

标签 telegram telegram-bot

我的 Telegram Bot 有问题。我想为我的机器人制作 Keybaord。当我从浏览器运行我的 Telegram api url 时,它可以工作:

     https://api.telegram.org/mybottoken/sendmessage?chat_id=93119306&text=something&reply_markup={"keyboard":[["Yes","No"],["Maybe"],["1","2","3"]], "one_time_keyboard":true};

但是

当我想在我的 php 文件中运行到这个 url($sendto Variable) 时,这不起作用。
我的 php 代码是:
<?php 
define('BOT_TOKEN', '183690241:AAHgluc7D9g0DF_InurfBj2YdBgPE7fmymo');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
    $array = array(); 
// read incoming info and grab the chatID
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatID = $update["message"]["chat"]["id"];
$chatText = $update["message"]["text"]; 
// compose reply
$reply =  sendMessage();

// send reply
$sendto =API_URL."sendmessage?chat_id=".$chatID."&text=".$reply."&reply_markup={"keyboard":[["Yes","No"],["Maybe"],["1","2","3"]], "one_time_keyboard":true};

file_get_contents($sendto);
function sendMessage(){
     global $chatID;
     global $chatText;
     if ($chatText =="/start") {
         $message = "Salam - Roboate Megat Hastam";
     }
     elseif ($chatText =="Khoobi?") {
         $message = "Merc -  Shomaa khobi?";
     }
       elseif ($chatText =="Chand salete?") {
         $message = "Be Tu Che!";
     }
 else
     {
         $message = "No Command";
     }


return rawurlencode($message);
}
?>

请帮助我犯错的地方。
谢谢大家。

最佳答案

试试这个代码:

 var_dump($keyboard = json_encode($keyboard = [
                       'keyboard' => [
                         ['Yes'],['No'],['Maybe'],
                         ['1'],['2'],['3'],
                       ] ,

                       'resize_keyboard' => true,
                       'one_time_keyboard' => true,
                  'selective' => true
                   ]),true);


    function sendKeyboard($chat_id, $keyboard) {

        $text = "Merc -  Shomaa khobi?";
        file_get_contents(API_URL ."sendMessage?chat_id=".$chat_id."&reply_markup=".$keyboard."&text=".urlencode($text));

    }

    if($message == "/start"){

        sendKeyboard($chat_id, $keyboard);
    }

关于telegram - php Telegram Bot 中的ReplyMarkup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35671692/

相关文章:

java - 如何使用 Java 为 Telegram Bot 键盘编写一组自定义命令?

seo - 如何强制 Telegram 更新链接预览?

python - 电报机器人。 heroku 网络服务器上的 "Webhook can be set up only on ports 80, 88, 443 or 8443"错误

Telegram 机器人发送消息到聊天错误 : chat not found

ubuntu - MyTonCtrl emi 命令抛出 'GetValidatorStatus' 错误

python - 加载到 Python 时,短 ogg 文件( Telegram 语音消息)的持续时间不正确

docker - Docker 容器中的 Telethon TelegramClient 身份验证

node.js - Telegram Bot |检测用户是否从移动设备或桌面设备发送消息

javascript - Bannerets/tdl 的 TDLib(Telegram 数据库库)身份验证和登录示例(Node.js pakage)