Search code examples
phptelegram-botphp-telegram-bottelegram-webhook

how to create a button that makes an http request without visting link on telegram bot


I'm trying to create a bot that shows a button. once the button is clicked I want the request to be done without user having to actually visit the link.

This is the current function I've.

function show_button($db, $chatID, $id) {

$cols = $db->query("SELECT id, text FROM `texts` where id = '" . $id . "'");

$arry = array();

$chunks = array();
foreach($cols as $key => $value) {
    array_push($chunks, $value['id']);
}

$chunk_array = array_chunk($chunks, 1);

$arr = array(
    "inline_keyboard" => array()
);

foreach($chunk_array as $key => $value) {
    foreach($value as $nvalue) {
        array_push($arry, array(
            "text" => "Forward this:", //str_replace(' ', '%20', $nvalue)
            "url" => "www.somewebsite.org/huge.php")); //"I|" . str_replace(' ', '%20', $nvalue)
    }
    array_push($arr["inline_keyboard"], $arry);
    $arry = array();
}

$msg="Here is the button";

send_buttons($chatID, $msg, $arr);

}


Solution

  • Impossible to accomplish on user's side for obvious security reasons.

    However, you can create a button with "callback_data" (instead of "url") that does this request on your server (you will have to handle it yourself). Just remember that you can't pass long links through callback data field as it's size is limited to only 64 bytes, you will either have to shorten the links or use ID system.