Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-open: Input is empty! - hook.php #203

Closed
devdenis opened this issue May 24, 2016 · 10 comments
Closed

Re-open: Input is empty! - hook.php #203

devdenis opened this issue May 24, 2016 · 10 comments

Comments

@devdenis
Copy link

Have the same problem with webhooks. Use SSL from Let's Encrypt, webhook is set, but have the error:
exception 'Longman\TelegramBot\Exception\TelegramException' with message 'Input is empty!' in path/vendor/longman/telegram-bot/src/Telegram.php:414 Stack trace: #0 path/index.php(14): Longman\TelegramBot\Telegram->handle() #1 {main}

@noplanman
Copy link
Member

That error is normal if you call hook.php directly.
Did you follow the installation instructions in the readme properly? Make sure you haven't left out any steps 😊

If you did and it's still not working, post again here.

@devdenis
Copy link
Author

devdenis commented May 24, 2016

in my hook file

require_once 'vendor/autoload.php';
require_once 'config.php';

try {
  $telegram = new Longman\TelegramBot\Telegram($bot_token, $bot_name);
  $update = $telegram->handle();
  file_put_contents('value.txt', $update);
}
catch (Longman\TelegramBot\Exception\TelegramException $e) {
   echo $e;
}

after send message in telegram client I have empty value.txt, but if unset webhook and use $telegram->handleGetUpdates(); I have some json in value.txt

@jacklul
Copy link
Collaborator

jacklul commented May 24, 2016

after send message in telegram client I have empty value.txt, but if unset webhook and use $telegram->handleGetUpdates(); I have some json in value.txt

That's because $telegram->handle(); returns result, not input.

Just to verify... put this:

file_put_contents('input.txt', file_get_contents("php://input"));

before require_once 'vendor/autoload.php';

and then send command to the bot, is the 'input.txt' file empty? It shouldn't, if it is it MIGHT be an issue with webhost configuration.

@devdenis
Copy link
Author

devdenis commented May 24, 2016

File input.txt have json with last message.

@jacklul
Copy link
Collaborator

jacklul commented May 24, 2016

Well then, try

$input = file_get_contents("php://input");
if (!empty($input)) {
    $telegram->setCustomInput($input);
}

before $update = $telegram->handle();

@devdenis
Copy link
Author

devdenis commented May 24, 2016

try {
  $telegram = new Longman\TelegramBot\Telegram($bot_token, $bot_name);
  $input = file_get_contents("php://input");
  if (!empty($input)) {
    $telegram->setCustomInput($input);
  }
  $update = $telegram->handle();
  file_put_contents('value.txt', $update);
}
catch (Longman\TelegramBot\Exception\TelegramException $e) {
   echo $e;
}

value.txt is empty

@jacklul
Copy link
Collaborator

jacklul commented May 24, 2016

Does it throw 'input empty' exception now?

$update = $telegram->handle();
file_put_contents('value.txt', $update);

as I said before: this will not output the update, it will output the result of handle(), which can be reply from Telegram API to, for example, sendMessage.

@devdenis
Copy link
Author

$update = $telegram->handle();
file_put_contents('value.txt', $update);

in file value.txt - I have "1"
but how I can get and process the message from user?

@jacklul
Copy link
Collaborator

jacklul commented May 24, 2016

You're doing it wrong, $telegram->handle(); is not supposed to return anything for you to work with.

I have a feeling you haven't read the readme, it's all there.

How to create own commands:
https://github.com/akalongman/php-telegram-bot#custom-commands

@MBoretto
Copy link
Collaborator

Can close here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants