Well. I provided the wrong parameter there. So that function didn't work. Its a working function.
you have to take these,
accesstoken = your access token
other params -
$raw_input = file_get_contents('php://input');
if(!empty($raw_input)){
$input = json_decode($raw_input, true);
$messageId = $input['entry'][0]['changes'][0]['value']['messages'][0]['id'];
$phoneId = $input['entry'][0]['changes'][0]['value']['metadata']['phone_number_id'];