Search code examples
phptelegramphp-telegram-bot

[madelineproto][php] Click Keyboard button and get the updated message


im working on a script that subscribe to inline keyboard bot when i click the keyboard button in bot the bot will update the message with another buttons

what i done

i got the bot message and click on a button

what im missing is that when i click the button i can not get the updated buttons

my code :

Calling the class and add event handler

$MadelineProto = new API('accounts/us2.madeline',$settings);
$MadelineProto->async(true);
$MadelineProto->startAndLoop(\MessagesEventHandler::class);

**Get last update message **

 public function onUpdateNewMessage(array $update): \Generator 

    {
             if (isset($update['message']['out']) && $update['message']['out']) {
                return;
            }
            if(isset($update['message']['from_id'])){
            if (isset($update['message']['reply_markup']['rows'])) {
                foreach ($update['message']['reply_markup']['rows'] as $row) {
                    foreach ($row['buttons'] as $button) {
                        if(strpos($button['text'],'تجميع النقاط') !== false){
                            try{
                            print_r(json_encode($button));
                            $a = yield $this->messages->getBotCallbackAnswer(['msg_id'=>$update['message']['id'],'peer'=>self::ReciverID]); 
                            print_r(json_encode($a)) ;
                        }catch(Exception $e){
                            echo "erorr : ".$e->getMessage() ;
                        } }
                       }} }
    }


Solution

  • i used onUpdateEditMessage method to get the updated buttons when i click a button.