1

I'm messing around with writing a own bot for telegramm using hook.io to host the php script. The problem that I have is that file_get_contents("php://input") always seems to be empty, since the bot does not react if I try to do anything related to the update:

$updates = json_decode(file_get_contents('php://input') ,true);

if($updates['ok']){

  //loop over all messages
  foreach($updates['result'] as $key => $value){
     if($value['message']['text']==="/test"){
       $chat_id =   $value['message']['chat']['id'];
       $result = file_get_contents( $apiURL . $apiToken . '/sendMessage?chat_id=' . $chat_id . '&text=test');
     }
  }

}

Can anyone tell whats wrong with this one?

1
  • are you trying to do POST on your backend ? If it's not a telegram's query php://input empty anyway? Commented Feb 13, 2017 at 5:05

1 Answer 1

2

I corrected in this way:

$updates = json_decode(file_get_contents('php://input') ,true);

if($updates['update_id']){

 if($updates['message']['text']==="/test"){
   $chat_id =   $updates['message']['chat']['id'];
   $result = file_get_contents( $apiURL . $apiToken . '/sendMessage?chat_id=' . $chat_id . '&text=test');
 }
}

the message is always one, so I deleted the foreach

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I didn't think of that. Also I found out that Hook.io deletes the content of 'php:\\input' and pastes them into the $Hook array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.