TelegramBot / Api

Native PHP Wrapper for Telegram BOT API
MIT License
1.09k stars 324 forks source link

Алиасы или роутинг #241

Closed jenokizm closed 4 years ago

jenokizm commented 4 years ago

Привет. Допустим есть команда /help есть /menu, как их объединить в одной чтобы не дублировать их код? Или другой случай, внутри $bot->on() при достижении оперделенного условия вызвать пользователю код из /menu?

iGusev commented 4 years ago

Что-то вроде такого:

$commandFunc = function ($message) use ($bot) {
    $bot->sendMessage($message->getChat()->getId(), 'my command');
};

$bot->command('help', $commandFunc);
$bot->command('menu', $commandFunc);

Или так:

$bot->on(
    function (Update $update) use ($bot) {
        $bot->sendMessage($update->getMessage()->getChat()->getId(), 'my command');
    },
    function (Update $update) {
        return in_array($update->getMessage()->getText(), ['/help', '/menu']);
    }
);