php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.91k stars 958 forks source link

Webhook does not return messages #572

Closed Marijnk7 closed 7 years ago

Marijnk7 commented 7 years ago

Required Information

Expected behaviour

command: /help should return data to the message

Actual behaviour

The messages is stored in the database but does not send a message to the chat. Table: telegrammessage (i have telegram as prefix) text column: /help entities column: [{"type":"bot_command","offset":0,"length":5}]

Steps to reproduce

$token = env('TELEGRAM_API_KEY');
$botName = env('TELEGRAM_BOT_NAME');

$mysql_credentials = [
    'host'     => env('DB_HOST'),
    'user'     => env('DB_USERNAME'),
    'password' => env('DB_PASSWORD'),
    'database' => env('DB_DATABASE'),
];

try {
    $telegram new Telegram($token, $botName);
    $telegram->enableMySQL($mysql_credentials, 'telegram_');
    $telegram->enableAdmin('12345678');

    // $telegram->addCommandsPath(app_path('Telegram\Commands'));
    //$telegram->setCommandConfig();

    // get the updates
    $telegram->handle();

} catch (TelegramException $exception) {
    Log::error('Could not handle telegram updates | ' . $exception->getMessage() . "\r\n"  . $exception->getTraceAsString());
}

Log::info('Message: ' . Request::getInput());

Extra details

I use laravel. I do not get any logs for nginx or laravel it self. I do get the access log and there it gives a status code 200.

I can send messages with Request:sendMessage()

What can be the problem?

jacklul commented 7 years ago

By default bot comes with public commands that do not reply.

Try executing /debug command, it should work out of the box. Make sure your custom commands path is included in the output, if it doesn't then there is path error in $telegram->addCommandsPath(app_path('Telegram\Commands'));!

noplanman commented 7 years ago

As @jacklul noted, there are no built-in public commands that create output. For some example commands, like /help, have a look at the separate example-bot repository.

Also, as a side-note, the user ID you pass to enableAdmin must be an integer, not string.

Marijnk7 commented 7 years ago

@jacklul @noplanman

Thank you! i've solved it. When i changed: enableAdmin to an integer the default commands worked. However i did not get any error message or whatsoever.

By the debug command i did not find my own command path. Eventually i found out my directory separator was facing the wrong way \ instead of / And i didn't have a trailing separator. I also did not receive an error message any where.

And now it works like a charm 👍

noplanman commented 7 years ago

Did you have the logging enabled? If so, you should have seen error entries there 😕

Anyway, good to see you've got it running!