telegram-bot-sdk icon indicating copy to clipboard operation
telegram-bot-sdk copied to clipboard

How to use $arguments in handle method?

Open ddzobov opened this issue 4 years ago • 1 comments

public function make(Api $telegram, Update $update, array $entity)
    {
        $this->telegram = $telegram;
        $this->update = $update;
        $this->entity = $entity;
        $this->arguments = $this->parseCommandArguments();

        return call_user_func_array([$this, 'handle'], array_values($this->getArguments())); // here handle method should contain one array argument
    }

    /**
     * {@inheritdoc}
     */
    abstract public function handle(); // this method not contains $arguments arg

ddzobov avatar Jan 27 '21 16:01 ddzobov

If you look at Telegram\Bot\Commands\Command; abstract public function handle(); this method doesnt accept any argument, I tried: $this->getArguments() //this always return empty array

Use $commandWithArguments= $this->getUpdate()->message->text;

Example

public function handle() { $updates = $this->getUpdate(); $commandParts = explode(' ', $updates->message->text); $firstArgument = $commandParts[1] ?? 'default argument'; }

wawanmadda avatar Mar 10 '21 06:03 wawanmadda