首页 > 解决方案 > 无法通过 Telegram Bot API 发送带有标记的回复

问题描述

试图建立一个简单的机器人。这是我的代码:

    require 'vendor/autoload.php';
    use Telegram\Bot\Api;
    $telegram = new Api('<MY TOKEN>');
    $result = $telegram -> getWebhookUpdates();

    $text = $result["message"]["text"]; 
    $chat_id = $result["message"]["chat"]["id"]; 
    $name = $result["message"]["from"]["username"]; 
    $keyboard = [["news"],["more news"],["loolz"]]; 


    if ($text == "/start") {
            $reply = "Hello there!";
            $reply_markup = $telegram->replyKeyboardMarkup([ 'keyboard' => $keyboard, 'resize_keyboard' => true, 'one_time_keyboard' => false ]);
            $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $reply_markup ]);
    }

    if ($text == "/btn1") {
        $reply = "AWESOME! YOU TAPPED 2nd BUTTON :)";

        $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply ]);
    }

条件if ($text == "/btn1")有效,但是当我添加$reply_markup到“btn1”动作时它会停止。因此,第一个条件也不起作用,因为$reply_markup

我的项目中使用的这个SDK:点击

我应该如何解决这个问题?ty <3

标签: phptelegram-botphp-telegram-bot

解决方案


推荐阅读