Test command send response to user
Nothing happens, but i receive updates http://prntscr.com/ifppqh
http://prntscr.com/ifptft
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
}
}
}
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.