0

problem create keyboard inline_keyboard with URL in telegram when iam use "&" in address url, keyboard not create in to telegram?!!!!!!!

this code is work:

$text = "server=164.132.117.18\nport=8585\nsecret=c53a3eae90544e68a37cbe41c5d31442";
$keyboard = array(
    'resize_keyboard' => true,
    'inline_keyboard' => array(
        array(
            array('text' => "Click for Connect", 'url' => "https://t.me/proxy?server=164.132.117.18port=8585secret=c53a3eae90544e68a37cbe41c5d31442")
        )
    )
);
$url = API_URL_KEY . "sendMessage?chat_id=" . CHAT_ID_USER . "&text=" . urlencode($text). "&reply_markup=" . json_encode($keyboard);
$ch = curl_init();
$optArray = array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
curl_exec($ch);
curl_close($ch);

but, this code not work:

$text = "server=164.132.117.18\nport=8585\nsecret=c53a3eae90544e68a37cbe41c5d31442";
$keyboard = array(
    'resize_keyboard' => true,
    'inline_keyboard' => array(
        array(
            array('text' => "Click for Connect", 'url' => "https://t.me/proxy?server=164.132.117.18&port=8585&secret=c53a3eae90544e68a37cbe41c5d31442")
        )
    )
);
$url = API_URL_KEY . "sendMessage?chat_id=" . CHAT_ID_USER . "&text=" . urlencode($text). "&reply_markup=" . json_encode($keyboard);
$ch = curl_init();
$optArray = array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
curl_exec($ch);
curl_close($ch);

Does anyone have a solution?

Rajesh Pandya
  • 1,540
  • 4
  • 18
  • 31

1 Answers1

2

What you get when trying to call the url you built is Error Code 400 "Bad Request: can't parse reply keyboard markup JSON object".

Try to urlencode() the url part found in $keyboard.

$keyboard = array(
    'resize_keyboard' => true,
    'inline_keyboard' => array(
        array(
            array('text' => "Click for Connect", 'url' => urlencode("https://t.me/proxy?server=164.132.117.18&port=8585&secret=c53a3eae90544e68a37cbe41c5d31442"))
        )
    )
);

This should work.

newsha
  • 1,288
  • 1
  • 10
  • 13