2

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,

Chrishow
  • 363
  • 1
  • 5
  • 13
  • `file_get_contents(url.` Is that `url` missing a `$`? – brombeer Apr 03 '20 at 09:57
  • No, it's fine, edited the question and added the definition on the first line. Bot parameters are ok since all of my sendmessage and sendphoto logics on the first if work perfectly, the problem is something with the callback catching. – Chrishow Apr 03 '20 at 10:02

1 Answers1

2
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.

0stone0
  • 34,288
  • 4
  • 39
  • 64
  • 1
    Holy smokes man, I can't believe it was a typo error...Thanks a lot for the reccomendation of {} very useful!! – Chrishow Apr 03 '20 at 11:21