Search code examples
phptelegramfile-get-contentstelegram-botphp-telegram-bot

Answer callback query


I have a Telegram with multiple functions running ok. Now I'm trying to add some more actions on inline buttons, however I can't seem to get it done.

I've wrapped all my bot code into an if and added an else condition for when a callback is sent, all of my bot actions are unaffected and running fine but the callback section isn't working at all.

This is my code, what may be missing?

define ('url',"https://api.telegram.org/botTOKEN/");

if (isset($update['message'])) {

//MY USUAL BOT LOGIC, EVERYHTING HERE RUN JUST FINE

} else if (isset($update['callback_query'])) {
    $callback_id = $update['callback_query']['id'];
    file_get_contents(url."answerCallbackQuery?callback_query_id=$callback_$id&text=SUCCESS");
}

Thanks in advance,


Solution

  • file_get_contents(url."answerCallbackQuery?callback_query_id=$callback_$id&text=SUCCESS");
    

    You've saved the callback_id in $callback_id, your are using $callback_$id in the code!

    Fixed;

    file_get_contents(url."answerCallbackQuery?callback_query_id={$callback_id}&text=SUCCESS");
    

    Try using {} around inline strings so there easy to spot! More info about {} here.