Closed devdenis closed 8 years ago
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.
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
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.
File input.txt have json with last message.
Well then, try
$input = file_get_contents("php://input");
if (!empty($input)) {
$telegram->setCustomInput($input);
}
before $update = $telegram->handle();
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
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.
$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?
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
Can close here?
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}