电报机器人键盘

时间:2017-10-11 17:56:29

标签: laravel telegram-bot

我用laravel创建了一个电报机器人队。代码的一部分。

$available_buttons =ReportToAbonent::select("report_id")
    ->join("telegram.reports", "report_to_abonent.report_id", "=", "reports.id")
    ->where("abonent_id", "=", $abonent[0]->id)
    ->where("active","=","1")
    ->get();

$keyboard = array();
foreach ($available_buttons as $value)
{
    $keyboard[] = array($value->report_id);
}

$reply_markup = \Telegram::replyKeyboardMarkup([
    'keyboard' => $keyboard,
    'resize_keyboard' => true,
    'one_time_keyboard' => false
]);

如果我打印

$keyboard`, its structure looks like if `$keyboard = [
            ['7', '8', '9'],
            ['4', '5', '6'],
            ['1', '2', '3'],
            ['0']
        ];

但在第一种情况下,电报客户端没有键盘。在第二种情况下,它存在。我能做错什么。

2 个答案:

答案 0 :(得分:0)

内联键盘格式错误,请查看API reference

您可以参考此示例请求:

只包含一个按钮:(参数和响应)

Awesome Telegram Bot

包含2x3按钮:

Awesome Telegram Bot

答案 1 :(得分:0)

这是每个键盘的两个例子:

普通键盘:

  const opts = {
    reply_markup: JSON.stringify({
      keyboard: [
        ['Normal'],
      ],
      resize_keyboard: true,
      one_time_keyboard: true,
    }),
  };

内联键盘:

  const inlineopts = {
    reply_markup: {
      inline_keyboard: [
        [{
          text: 'Yahoo',
          url: 'www.yahoo.com',
        }],
        [{
          text: 'Google',
          url: 'www.google.com',
        }],
      ],
    },
  };