php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.87k stars 951 forks source link

Problem with getting /echo working – please provide minimum working example #43

Closed danielberlin closed 8 years ago

danielberlin commented 8 years ago

I try to set up hook.php but with little success so far.

  1. The minimum example:
try {
   $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
   $telegram->enableMySQL($credentials);
   // later commands are handled here
   $telegram->handle();
}

works so far.

  1. However, if I add commands (is it correct to do this before the method $telegram->handle()?), MySQL logging stops working and the web server error_log logs 500 Internal Server Error (see #39).
  2. Exceptions are logged but not when (1) happened. I can have an exception logged by calling php hook.php from command line, then the exception says exception 'Longman\TelegramBot\Exception\TelegramException' with message 'Input is empty!' so exception logging should work.
  3. My basic question is: What is the exact way to add any functionality to above minimum example such as echo or whoami?

Is this correct?

$echo = new Longman\TelegramBot\Commands\EchoCommand;    
$echo->execute();

Or this way?

$telegram->executeCommand('echo', $update);

Or both? I cannot figure this out without diving into the classes but it should be clear in the documentation already.

The point is, I believe that Telegram API stops sending me requests if I produce to many server errors. Because after trying this out, even the basic example above stops working (MySQL no longer logs anything) and I have to wait a day or so and suddenly it works again.

Please provide a minimum working example in README.md with which users can instantly get at least the /echo Telegram bot command working.

I don't know if this would be a minimum working example, but please add something like the following to README.md to make it clear and instantly get a working bot:

try {
   $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
   $telegram->enableMySQL($credentials);
   $echo = new Longman\TelegramBot\Commands\EchoCommand; // or whatever is correct to activate "/echo"
   $echo->execute();
   $telegram->handle();
}

If this would be easy to get started with, I think it will be a great success! Thank you.

danielberlin commented 8 years ago

And now I get this error in the web server's log with above minimum example:

PHP Catchable fatal error:  Argument 1 passed to Longman\\TelegramBot\\Entities\\ServerResponse::__construct() must be of the type array, null given, called in /www/bot/vendor/longman/telegram-bot/src/Request.php on line 151 and defined in /www/bot/vendor/longman/telegram-bot/src/Entities/ServerResponse.php on line 26

But this should be logged in TelegramException.log instead of the web server's error_log, shouldn't it?

weiddolo commented 8 years ago

I've the same problem; if you fix please contact me :D

danielberlin commented 8 years ago

@weiddolo Which of the problems I described above do you have?

MBoretto commented 8 years ago

Example are provided, see in the main dir example-* files. Line uncommented are mandatory. Commands are triggered when are wrote by the users in the chats, you don't have to call them before handle methods.

danielberlin commented 8 years ago

Then I can only report that example-hook.php never worked when I type /echo in a chat. No answer in the chat. No logging about this. MySQL logging works, but sometimes not with this error:

2015-10-05 20:08:39 exception 'Longman\TelegramBot\Exception\TelegramException' with message 'Input is empty!'