【问题标题】:how to create keyboard in bot telegram如何在机器人电报中创建键盘
【发布时间】:2017-04-11 05:02:02
【问题描述】:

enter image description here

帮我为电报机器人(php)创建键盘(是/否)

【问题讨论】:

标签: keyboard telegram-bot


【解决方案1】:

我不知道 PHP,但棘手的部分通常是键盘部分,它是一个数组数组。调用 sendMessage 并传递类似于以下 json 的内容:

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

将 12345678 替换为您的聊天 ID。

【讨论】:

    【解决方案2】:

    首先获取更新并将它们保存到$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 个参数,它们使用 curl 向电报 api 发送和接收数据。

    【讨论】:

      猜你喜欢
      • 2018-03-23
      • 1970-01-01
      • 2017-02-14
      • 2016-03-22
      • 2020-10-08
      • 1970-01-01
      • 2022-10-05
      • 2018-09-25
      • 2018-06-10
      相关资源
      最近更新 更多