Keyboard 如何在bot电报中创建键盘

Keyboard 如何在bot电报中创建键盘,keyboard,telegram-bot,Keyboard,Telegram Bot,请帮助我为telegramBot php创建键盘是/否我不懂php,但棘手的部分通常是键盘部分,它是一个数组数组。调用并传递类似以下json的内容: { chat_id: 12345678, text: "Hello, do you like ice cream?", reply_markup: { keyboard: [ [{text: "Yes"}], [{text: "No"}] ] } } 将12345678替换为您的聊天id。首

请帮助我为telegramBot php创建键盘是/否

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

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

将12345678替换为您的聊天id。

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

因此不能要求人们编写代码!到现在为止你自己都做了些什么?请阅读帮助中心的这两篇文章:和