PHP / Telegram Bot: How to open a URL as Web App not an external Link?

I am creating a Telegram bot for my store with PHP.

Currently I have created the bot, used webhook URL to introduce my bot’s PHP file to Telegram. My code almost works and can respond commands I defined, but I have a button/command “Open the store“. When we click this button, a message will send to user with this content “Click the button below to open the store:” and a button bellow the message with name “Open store“.

In my code I set this button’s link $storeURL = 'https://example.com/?username='.$username.'&uid='.$userID; and it works good and could get username and used ID.

The problem is this button will show a pupop with message “Do you want the link? https://example.com/?username=xxxxxxx&uid=1234678“, And it will open this link in external browser.

But I need to open this button like a Web App (Mini-App) inside of Telegram not as an external link.

In BotFather I can set a custom URL and Custom Text for menu, this URL open like a webview/internal mini-app. And exactly I need to open the “Open store” button like a mini-app.

How is this possible? I just saw some PHP bots can do it. My website is coded with PHP so for this reason I want to use PHP for my bot. This is my PHP code for bot file in my website:

<?php

$botToken = '6877041912:AAE-LsUBqjuurlBSFA6l6jU_RcbdFO_t000';
$telegramApi = 'https://api.telegram.org/bot'.$botToken;

$servername = 'localhost';
$username = 'epfnwgng_farmms';
$password = 'BappJ5CstjY6';
$dbname = 'epfnwgng_farmdbn';

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die('Connection failed: '.$conn->connect_error);
}

$update = json_decode(file_get_contents('php://input'), true);

if (isset($update['message'])) {
    
$chatID = $update['message']['chat']['id'];
$messageText = $update['message']['text'];
$userID = $update['message']['from']['id'];
$username = $update['message']['from']['username'];

switch ($messageText) {
    case '/start':
        sendMessage($chatID, 'Welcome to the Telegram mini app bot! Choose an option below:');
        sendKeyboard($chatID);
        break;
    case 'Open store':
    $storeURL = 'https://example.com/?username='.$username.'&uid='.$userID;
    sendStore($chatID, $storeURL);
    break;
    case 'Referred members':
        $referredMembersCount = getReferredMembersCount($chatID);
        sendMessage($chatID, 'Number of referred members: '.$referredMembersCount);
        break;
    case 'Refer and point':
        $referLink = 'https://t.me/xxxxxxxx_bot?startuid='.$chatID;
        $message = 'Your referral link is '.$referLink.'. Share it and earn points for each user.';
        $referredPlayersCount = getReferredPlayersCount($chatID);
        $message .= "nnNumber of players with your UID in the game: ".$referredPlayersCount;
        sendMessage($chatID, $message);
        break;
    default:
        sendMessage($chatID, 'Invalid command. Please choose an option from the keyboard.');
        sendKeyboard($chatID);
}
}

function insertPlayerData($username, $userID) {
    global $conn;
    
    $check_sql = "SELECT * FROM players WHERE username = '$username'";
    $check_result = $conn->query($check_sql);
    
    if ($check_result->num_rows == 0) {
        $sql = "INSERT INTO players (username, UID) VALUES ('$username', '$userID')";
        $conn->query($sql);
    }
}

function getReferredMembersCount($chatID) {
    global $conn;
    $sql = "SELECT COUNT(*) AS referred_count FROM players WHERE referreduid = $chatID";
    $result = $conn->query($sql);
    $row = $result->fetch_assoc();
    return $row['referred_count'];
}

function getReferredPlayersCount($chatID) {
    global $conn;
    $sql = "SELECT COUNT(*) AS referred_players_count FROM players WHERE referreduid = $chatID";
    $result = $conn->query($sql);
    $row = $result->fetch_assoc();
    return $row['referred_players_count'];
}

function sendMessage($chatID, $message) {
    global $telegramApi;
    
    $data = [
        'chat_id' => $chatID,
        'text' => $message
    ];

    $ch = curl_init($telegramApi.'/sendMessage');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_exec($ch);
    curl_close($ch);
}

function sendStore($chatID, $storeURL) {
    global $telegramApi;
    $data = [
        'chat_id' => $chatID,
        'text' => 'Click the button below to open the store:',
        'reply_markup' => json_encode([
            'inline_keyboard' => [
                [
                    [
                        'text' => 'Open store',
                        'url' => $storeURL
                    ]
                ]
            ]
        ])
    ];
    $ch = curl_init($telegramApi . '/sendMessage');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_exec($ch);
    curl_close($ch);
}


function sendKeyboard($chatID) {
    global $telegramApi;
    $keyboard = [
        ['Open the Store'],
        ['Help', 'Support'],
        ['Referred members', 'Refer and point']
    ];
    $replyMarkup = [
        'keyboard' => $keyboard,
        'resize_keyboard' => true,
        'one_time_keyboard' => false
    ];
    $data = [
        'chat_id' => $chatID,
        'text' => 'Choose an option:',
        'reply_markup' => json_encode($replyMarkup)
    ];

    $ch = curl_init($telegramApi.'/sendMessage');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_exec($ch);
    curl_close($ch);
}

?>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật