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?
2
Answers
You can simply check if CallbackQuery is null or not.
See the Telegram docs:
CallbackQuery
According to telegram Docs:
so you just need to check which one of them is not Null.