Core: Commands not working

Created on 16 Feb 2018  路  6Comments  路  Source: php-telegram-bot/core

Required Information

  • Operating system: Mac OS X
  • PHP version: 7.2
  • PHP Telegram Bot version: ^0.52.0
  • Using MySQL database: yes
  • MySQL version: 5.7
  • Update Method:getUpdates
  • Self-signed certificate: no
  • RAW update (if available):

Expected behaviour

Test command send response to user

Actual behaviour


Nothing happens, but i receive updates http://prntscr.com/ifppqh
http://prntscr.com/ifptft

Steps to reproduce

Extra details

1) test command

class TestCommand extends UserCommand
{
    protected $name = 'test';

    protected $description = 'test';

    protected $usage = '/test';

    protected $enabled = true;


    public function execute()
    {
        $update = $this->getUpdate();


        var_dump($update);

        return Request::sendMessage([
            'chat_id' => $this->getMessage()->getChat()->getId(),
            'text' => 'test'
        ]);
    }

}

2) Get updates "worker"

class ArbBot extends Command
{
    public function configure()
    {
        $this->setName('bot:arb');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        try {
            $telegram = new Telegram(
                $_SERVER["TG_API_TOKEN"],
                $_SERVER["TG_USER_NAME"]
            );

            $bot_username =  $_SERVER["TG_USER_NAME"];

            TelegramLog::initErrorLog(__DIR__ . "/{$bot_username}_error.log");
            TelegramLog::initDebugLog(__DIR__ . "/{$bot_username}_debug.log");
            TelegramLog::initUpdateLog(__DIR__ . "/{$bot_username}_update.log");

            // Add commands paths containing your custom commands
            $telegram->addCommandsPath(__DIR__ . '/Commands/');



            $telegram->enableExternalMySql(Database::getInstance());

            // Requests Limiter (tries to prevent reaching Telegram API limits)
            $telegram->enableLimiter();
            // Handle telegram getUpdates request
            $server_response = $telegram->handleGetUpdates();

            if ($server_response->isOk()) {
                $update_count = count($server_response->getResult());
                $output->writeln(
                    sprintf("[%s] Processed %d updates.",
                            date('Y-m-d H:i:s'),
                            $update_count
                        )
                );
            } else {
                $output->writeln(sprintf(
                    "<error> Failed to fetch updates! %s</error>",
                    $server_response->printError(true)
                ));
            }
        } catch (TelegramException $exception) {
            // silence

            $output->writeln(
                sprintf("<error>Error telegram bot: %s</error>", $exception->getMessage())
            );
        } catch (\Exception $exception) {
            // other exceptions
        }
    }
}

All 6 comments

It looks like library doesn't know about your command, is the command path correct?
Make sure your commands are in correct namespace, eg. namespace Longman\TelegramBot\Commands\UserCommands; for user commands, currently this is required.

Edditionally execute /debug command and see if command paths point to the place where your test command is.

@jacklul Commands in namespace Trader\Bot\Commands. Can i use custom namespace for commands?

Maybe need enabled mysql?

Mysql enabled

@eskrano Currently using Longman\TelegramBot\Commands\UserCommands namespace is a requirement.

@jacklul Bad package.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Zoha picture Zoha  路  3Comments

irmmr picture irmmr  路  3Comments

vansanblch picture vansanblch  路  3Comments

smaznet picture smaznet  路  4Comments

NabiKAZ picture NabiKAZ  路  4Comments