【问题标题】:ReplyMarkup in php telegram botphp电报机器人中的ReplyMarkup
【发布时间】:2016-05-03 06:16:14
【问题描述】:

我的电报机器人有问题。我想为我的机器人制作 Keybaord。当我从浏览器运行我的电报 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 变量) 时,这不起作用。 我的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);
}
?>

请在我犯错误的地方提供帮助。 谢谢大家。

【问题讨论】:

    标签: telegram telegram-bot


    【解决方案1】:

    试试这个代码:

     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);
        }
    

    【讨论】:

      猜你喜欢
      • 2017-08-18
      • 2019-03-14
      • 2022-06-14
      • 2022-10-05
      • 1970-01-01
      • 2017-09-01
      • 2017-12-15
      • 2018-02-27
      • 2018-07-22
      相关资源
      最近更新 更多