Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make dynamic generated commands /command_movie1 #1403

Closed
mrTall opened this issue May 24, 2023 · 2 comments
Closed

How to make dynamic generated commands /command_movie1 #1403

mrTall opened this issue May 24, 2023 · 2 comments
Labels

Comments

@mrTall
Copy link

mrTall commented May 24, 2023

Hi, I'm trying to create dynamic command, but cannot wrap-up my head how to do this
I using laravel package, and trying to make list of commands, so for example command /movies return list of entity with:
Movie 01 /movie_01

Can I make a command /movie that will handle parameter 01?

@jacklul
Copy link
Collaborator

jacklul commented May 24, 2023

Use GenericCommand.php, something like this is a good starter:

<?php

namespace Longman\TelegramBot\Commands\SystemCommands;

use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;

class GenericCommand extends SystemCommand
{
    public function execute(): ServerResponse
    {
        $message = $this->getMessage();
        $command = $message->getCommand();

        // TODO: validate data in $command
        $command = explode('_', $command);
        $parameter = $command[1];
        $command = $command[0];

        // your logic
    }
}

@mrTall
Copy link
Author

mrTall commented May 24, 2023

@jacklul Brilliant! Thanks a lot! Thats works

@mrTall mrTall closed this as completed May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants