2016-11-27 179 views
-3

enter image description here如何在机器人电报创建键盘

帮我创建键盘(是/否)为telegramBot(PHP)

+0

SO不是让人们写你的代码的地方!你直到现在还做了什么?请从帮助中心阅读这两篇文章:[如何提出一个好问题?](http://stackoverflow.com/help/how-to-ask)和[如何创建最小,完整和可验证的示例] (http://stackoverflow.com/help/mcve) – EhsanT

+0

https://stackoverflow.com/questions/31099087/telegram-bot-custom-keyboard-in-php – vladkras

回答

1

我不知道PHP,但棘手的部分通常是键盘部分这是一个数组数组。呼叫sendMessage并通过类似下面的JSON:

{ 
    chat_id: 12345678, 
    text: "Hello, do you like ice cream?", 
    reply_markup: { 
    keyboard: [ 
     [{text: "Yes"}], 
     [{text: "No"}] 
    ] 
    } 
} 

替换12345678与你的聊天ID。

0

首先获得更新,并将其保存到$update然后ReplyKeyboardMarkup使用这种方法:

if ($update->message->text == '/start') { 
    $name = $update->message->chat->first_name; 
    bot('sendMessage',[ 
     'chat_id' => $update->message->chat->id, 
     'text'=>'Your Test', 
     'resize_keyboard'=>true, 
     'reply_markup'=>json_encode([ 
      'keyboard'=>[ 
      [ 
       ['text'=>'Num1'],['text'=>'Num2'] 
      ], 
      [ 
       ['text'=>'Num2'] 
      ], 
      ] 
     ]) 
    ]); 
    } 

和内嵌的键盘,你应该使用这个方法来发送:

 'reply_markup'=>json_encode([ 
      'inline_keyboard'=>[ 
      [ 
       ['text'=>'Num1'],['text'=>'Num2'] 
      ], 
      [ 
       ['text'=>'Num3'] 
      ], 
      ] 
     ]) 
    ]); 
    } 

记得BOT函数2个用于发送和接收数据到卷api的卷曲参数。