Sorry if my question gets too messy, I'm new here, so, any advice is welcome.
How can I differentiate between a 'Message' update and a 'Callback Query' update? I've managed to make an inline keyboard, but when I use it, the bot just hangs, he doesn't reply anything. I did a little bit of research and found this question, which helped me understand the problem, but not much else.
My bot uses something like this right now:
// read incoming info and grab the chatID
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatID = $update["message"]["chat"]["id"];
switch($update["message"]["text"]){
/* insert magic here */
}
So, this code can handle Messages, but not CallbackQueries. If I wantew to handle them, I could use something like this (based on the other question's answer):
$callback_query = $update["callback_query"]
/* same as above */
But how can I check whether it is a message or a callback query?
if (($update['message']) != null) {
} else if ($update['callback_query'] != Null) {
According to telegram Docs:
At most one of the optional parameters can be present in any given update.
so you just need to check which one of them is not Null.
You can simply check if CallbackQuery is null or not. See the Telegram docs:
This object represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or game_short_name will be present.
来源:https://stackoverflow.com/questions/39264399/how-can-i-differentiate-between-a-message-update-and-a-callback-query-update