Get message_id of Telegram bot sendPoll message php-ThrowExceptions

Exception or error:

I have written a Telegram bot with PHP.

After sendPoll method boot it needs to wait 10 seconds for user answer – if user hasn’t answered, the bot closes this Poll with method stopPoll. (Looks like Telegram’s official @quizbot)

I use webhooks – the stopPoll method required message_id option for close Poll and I don’t know how can I get the message_id of the latest sendPoll message in order to store it in the MySQL DB.

case '/sendpoll':
    $i = '';
        case 0:
            $stt->sendteleg($data = ['text'=>"Are you ready? \xF0\x9F\x9A\x80"], $chat_id_call, "sendMessage");
            $dataSend = getpollquestions(0,6);
            $stt->sendteleg($dataSend, $chat_id_call, "sendPoll");
            $hasstate =$dbconn->hasuserstate($user_id_call);
            }else {$dbconn->adduserstate($user_id_call,$message_id_call,'wait','poll');}
            $state = $dbconn->getuserstate($user_id_call);
            $statebolim = explode("-_-",$state);
            $datalimit = gettimeplus10($statebolim[2]);

            $dat = [
            'message_id' => json_encode($statebolim[0]+2)];
            $stt->sendteleg($dat, $chat_id_call, "stopPoll");

You can see that I save message_id of the last callbackbutton that starts Poll in the DB and +2 it for stopPoll (+1 for “Are you ready” message and +1 for last sendPoll message). It’s working, but there is exception if the user sends any message before the bot closes the Poll – message_id is wrong and stopPoll is not working.

Please tell me how can I make this code work?

How to solve:

i found solution, sending message(or Poll) with

$info = file_get_contents($bot_url."/sendPoll?" .http_build_query($dataSend));

returns all information about this action(chat_id, message_id, poll_id etc);
you can get all info by saving $info ;

Leave a Reply

Your email address will not be published. Required fields are marked *