Skip to content

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

@danielberlin

Description

@danielberlin

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 MySQL logging works only with no other commands active, but then HTTP/500 #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions