First of all thanks for great job!
I have created callbackquery command where I'm checking the callback_data for a string like "order:123".
I need to start an other command such as /reply 123.
But when I'm trying
return $this->telegram->executeCommand('reply 123');
I'm getting following exception:
PHP message: PHP Fatal error: Uncaught Error: Call to a member function getChat() on nul
l in /home/cargo/larabot/vendor/longman/telegram-bot/src/Commands/SystemCommands/GenericCommand.php:37
Stack trace:
#0 /home/cargo/larabot/vendor/longman/telegram-bot/src/Commands/Command.php(131): Longman\TelegramBot\Commands\SystemCommands\GenericCommand->execute()
#1 /home/cargo/larabot/vendor/longman/telegram-bot/src/Telegram.php(437): Longman\TelegramBot\Commands\Command->preExecute()
#2 /home/cargo/larabot/vendor/longman/telegram-bot/src/Telegram.php(428): Longman\TelegramBot\Telegram->executeCommand('Generic')
#3 /home/cargo/larabot/commands/CallbackqueryCommand.php(53): Longman\TelegramBot\Telegram->executeCommand('oreply 18')
#4 /home/cargo/larabot/vendor/longman/telegram-bot/src/Commands/Command.php(131): Longman\TelegramBot\Commands\SystemCommands\CallbackqueryCommand->execute()
#5 /home/cargo/larabot/vendor/longman/telegram-bot/src/Telegram.php(437): Longman\TelegramBot\Commands\Command->preExecute()
Does it a way to do it?
At the moment there is no clean way to execute a subcommand. Seems like one of those obvious things that one should just be able to do, right?
The only thing that I can think of, is to extract the functionality from the /reply command you're trying to call and execute it specifically.
If you need a more thorough explanation, let me know!
@akalongman @MBoretto @jacklul
Am I just totally oblivious to the library actually being able to do this?
The only way I found of doing this is the following, which is an ugly hack and I'm not exactly sure of all the things it might break:
// In the command's execute(), if we want to send "/echo testing".
// Note that we explicitly need to create the EchoCommand object!
$ud = clone $this->getUpdate();
\Tests\TestHelpers::setObjectProperty($ud->getMessage(), 'text', '/echo testing');
(new EchoCommand($this->telegram, $ud))->preExecute();
You can instead be sending /reply_parameter command and then explode "_" and execute first part then inside reply command extract the second part and use it as a parameter, thats how i did contact/reply system in my bots.
So I have a contact command that puts inline button under user message:
'text' => "Reply",
'callback_data' => 'reply_' . $message->getFrom()->getId()
then in callbackquerycommand I have this simple thing:
$data = $callback_query->getData();
$command = explode('_', $data);
$command = $command[0];
if ($this->getTelegram()->getCommandObject($command)) {
return $this->getTelegram()->executeCommand($command);
}
and then on top of my reply command i have:
$testtext = explode('reply_', $command);
$text = $testtext[1];
hope this helps
Most helpful comment
You can instead be sending /reply_parameter command and then explode "_" and execute first part then inside reply command extract the second part and use it as a parameter, thats how i did contact/reply system in my bots.
So I have a contact command that puts inline button under user message:
then in callbackquerycommand I have this simple thing:
and then on top of my reply command i have:
hope this helps