|
1 |
| - |
2 | 1 | # Symfony bundle for Telegram Bot API
|
3 | 2 |
|
4 |
| -A symfony bundle for `luzrain/telegram-bot-api` |
| 3 | +[](https://www.php.net/releases/8.2/en.php) |
| 4 | + |
| 5 | +[](../../actions/workflows/tests.yaml) |
| 6 | + |
| 7 | +A symfony bundle for [luzrain/telegram-bot-api](https://github.com/luzrain/telegram-bot-api) library. |
5 | 8 |
|
6 | 9 | ## Installation
|
7 | 10 | ### Install composer package
|
8 | 11 | ``` bash
|
9 |
| -$ composer require luzrain/telegram-bot-bundle (TODO) |
| 12 | +$ composer require luzrain/telegram-bot-bundle |
10 | 13 | ```
|
| 14 | + |
11 | 15 | ### Enable the Bundle
|
12 | 16 | ```php
|
13 | 17 | <?php
|
@@ -47,9 +51,43 @@ telegram_webhook:
|
47 | 51 | ```
|
48 | 52 |
|
49 | 53 | ### Set webhook url
|
| 54 | +Install webhook url using the console command: |
50 | 55 | ``` bash
|
51 |
| -$ bin/console telegram:set-webhook-url |
| 56 | +$ bin/console telegram:webhook:set --url=https://domain.xyz/telagram-webhook |
| 57 | +``` |
| 58 | + |
| 59 | +## Example of usage |
| 60 | +### Command controller |
| 61 | +```php |
| 62 | +use Luzrain\TelegramBotApi\Method; |
| 63 | +use Luzrain\TelegramBotApi\Type; |
| 64 | +use Luzrain\TelegramBotBundle\Attribute\OnCommand; |
| 65 | +use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand; |
| 66 | + |
| 67 | +final class StartCommandController extends TelegramCommand |
| 68 | +{ |
| 69 | + #[OnCommand('/start')] |
| 70 | + public function __invoke(Type\Message $message, string $argument = ''): Method |
| 71 | + { |
| 72 | + return $this->reply('Hello from symfony bot'); |
| 73 | + } |
| 74 | +} |
52 | 75 | ```
|
53 | 76 |
|
54 |
| -..... TODO |
| 77 | +### Message controller |
| 78 | +```php |
| 79 | +use Luzrain\TelegramBotApi\Event; |
| 80 | +use Luzrain\TelegramBotApi\Method; |
| 81 | +use Luzrain\TelegramBotApi\Type; |
| 82 | +use Luzrain\TelegramBotBundle\Attribute\OnEvent; |
| 83 | +use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand; |
55 | 84 |
|
| 85 | +final class OnMessageController extends TelegramCommand |
| 86 | +{ |
| 87 | + #[OnEvent(Event\Message::class)] |
| 88 | + public function __invoke(Type\Message $message): Method |
| 89 | + { |
| 90 | + return $this->reply('You write: ' . $message->text); |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
0 commit comments