To manage Telegram inline-keyboard buttons in PHP, put short action data in each button’s callback_data, receive the resulting callback_query through a webhook or long polling, call answerCallbackQuery promptly for every press, and then edit the message or keyboard as needed. Telegram limits callback data to 1–64 bytes, and the callback may identify its message either through chat/message IDs or an inline_message_id.
How inline keyboards and callback queries work
An inline keyboard is an InlineKeyboardMarkup object whose inline_keyboard value is an array of rows. Each row contains button objects. A callback button supplies visible text and a callback_data value that Telegram returns to the bot when the button is pressed.
Telegram permits 1–64 bytes for callback_data. Use a compact action name or reference to server-side state—for example, order:42:confirm—rather than embedding a large object or sensitive information. Treat the value as an input to validate, not as authorization: Telegram notes that the originating message may no longer have a button with that data when the callback arrives.
A callback query includes a unique query ID, the user who pressed the button, and callback data. It also provides message context when the originating bot message is accessible. For a message sent through inline mode, the query can instead include inline_message_id. The exact fields available determine which identifier to use when editing the message.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Build an inline keyboard in PHP
Represent rows and buttons as nested PHP arrays, then include them as the message’s reply_markup. This example shows the data shape; it does not make the API request by itself.
$keyboard = [
'inline_keyboard' => [
[
['text' => 'Confirm', 'callback_data' => 'order:42:confirm'],
['text' => 'Cancel', 'callback_data' => 'order:42:cancel'],
],
[
['text' => 'Help', 'callback_data' => 'help'],
],
],
];
Pass this markup when sending a message, using the Bot API’s supported JSON or form request parameters. Keep business state on your server and check that the requested action is valid for the user and current state before applying it.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Receive callback queries in PHP
Telegram delivers updates through either getUpdates long polling or an HTTPS webhook configured with setWebhook. They are mutually exclusive while a webhook is set: long polling does not work with an outgoing webhook. If you specify allowed_updates, include callback_query so these updates are delivered.
Webhook handler outline
A webhook endpoint receives a JSON-serialized Update. Decode the request body, check for a callback query, and use its ID to acknowledge the press:
Recommended Free Tools
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
$update = json_decode(file_get_contents('php://input'), true);
if (isset($update['callback_query'])) {
$query = $update['callback_query'];
$queryId = $query['id'];
$data = $query['data'] ?? '';
// Validate $data and the user's permission against application state.
telegramApi('answerCallbackQuery', [
'callback_query_id' => $queryId,
]);
// Edit the message or its keyboard using the available message context.
}
telegramApi() is an application-defined HTTP-client function, not a built-in PHP or Telegram function. It must send a request to the Bot API, process HTTP and JSON errors, and keep the bot token out of public source code and logs. Telegram’s API uses HTTPS URLs in the form https://api.telegram.org/bot<TOKEN>/METHOD_NAME; requests can use GET or POST and supported parameter encodings include JSON. Successful responses are JSON objects with an ok status and a result.
For webhook verification, Telegram supports an optional secret_token when setting the webhook; check the corresponding request header before processing updates. The PHP outline above is pseudocode, not a tested, drop-in endpoint.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Long polling outline
With long polling, call getUpdates from a worker and process returned Update objects. Advance the offset beyond the highest update ID you have processed to avoid receiving those updates again. Do not run this worker while a webhook is configured.
Acknowledge every button press
Call answerCallbackQuery using the callback query’s id. Telegram clients display a progress indicator after a button press until the bot answers. The acknowledgement is necessary even when you do not want to show the user a message.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
For a quiet acknowledgement, provide the query ID without optional presentation parameters. If appropriate, the method can instead show notification text or an alert. For work that may take time, acknowledge promptly and perform the slow work afterward when the application flow allows it; Telegram’s MTProto button guidance also advises bots to respond as quickly as possible.
Update the message or its keyboard
After validating and handling the action, choose the edit method according to what should change:
editMessageReplyMarkupchanges only the inline keyboard.editMessageTextchanges the message text and can include replacement markup throughreply_markup.
For an accessible bot message in a chat, provide its chat ID and message ID. For an inline-mode message, the edit methods accept inline_message_id instead. Editing the original message can keep the conversation focused on one updated result instead of adding a separate bot reply for every button press.
Choose long polling or a webhook
| Delivery method | Use it when | Important constraint |
|---|---|---|
getUpdates long polling |
Your PHP deployment runs a worker that can repeatedly request updates. | It cannot be used while an outgoing webhook is configured. Advance the offset beyond processed update IDs. |
| HTTPS webhook | Your application has an HTTPS endpoint reachable by Telegram. | Webhook delivery and long polling are mutually exclusive. An optional secret token can help verify incoming requests. |
Telegram specifies the HTTP API and update fields, but does not require a particular PHP framework, SDK, router, or HTTP client. Those are implementation choices; verify a library’s current interface and behavior in its own documentation before relying on it.
Quick Recap
Official references
- Telegram Bot API — callback queries, inline keyboards, update delivery, request methods, and message editing.
- Telegram bot buttons (MTProto) — button interaction guidance.
- Telegram Bot API changelog — historical API changes, including the 2016 introduction of callback-query and inline-keyboard features.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

