diff --git a/README.md b/README.md index f036063..ec16534 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # yii2-telegram-api ``` php - +'components' => [ + 'telegram' => [ + 'class' => 'mirocow\component\Telegram', + 'token' => 'api-telegram-token', + ] +], ``` \ No newline at end of file diff --git a/composer.json b/composer.json index 25eb12e..2a4991f 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "autoload": { "psr-4": { - "mirocow\\telegramm\\api\\": "src" + "mirocow\\telegram\\": "src" } } } diff --git a/src/Client.php b/src/Client.php index 3e058e1..0a13bea 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,12 +1,6 @@ onUpdate(function (Update $update) { - print_r($update); - }); - - $daemon->run(); - - } -} \ No newline at end of file diff --git a/src/commands/HelpCommand.php b/src/commands/HelpCommand.php new file mode 100644 index 0000000..34a83d2 --- /dev/null +++ b/src/commands/HelpCommand.php @@ -0,0 +1,19 @@ +module->token); + + $daemon = new Daemon($client); + + $daemon + ->onUpdate(function (Update $update) use ($client) { + + if(isset($update->message->text) && substr($update->message->text, 0,1) == '/' && $command = str_replace('/','', $update->message->text)) { + + if(isset($this->module->commands[$command])) { + $command = $this->module->commands[$command]; + } else { + $command = 'mirocow\\telegram\\commands\\' . ucfirst($command) . 'Command'; + } + + if(class_exists($command)){ + $message = (new $command)->run($update); + } else { + $message = Yii::t('app', 'Uncknow command'); + } + + } else { + + $message = ''; + + } + + if($message) { + $response = $client->sendMessage([ + 'chat_id' => $update->message->chat->id, + 'text' => $message + ]); + } + + }); + + $daemon->run(); + + } +} \ No newline at end of file diff --git a/src/interfaces/CommandInterface.php b/src/interfaces/CommandInterface.php new file mode 100644 index 0000000..620b34e --- /dev/null +++ b/src/interfaces/CommandInterface.php @@ -0,0 +1,10 @@ +