@@ -96,8 +96,72 @@ final class OnMessageController
96
96
{
97
97
return new Method\SendMessage(
98
98
chatId: $message->from->id,
99
- text: 'You write : ' . $message->text,
99
+ text: 'You wrote : ' . $message->text,
100
100
);
101
101
}
102
102
}
103
+ ```
104
+
105
+ ### Access control controller
106
+ ``` php
107
+ use Luzrain\TelegramBotApi\Event;
108
+ use Luzrain\TelegramBotApi\EventCallbackReturn;
109
+ use Luzrain\TelegramBotApi\Type;
110
+ use Luzrain\TelegramBotBundle\Attribute\OnEvent;
111
+ use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand;
112
+
113
+ final class AccessControlController extends TelegramCommand
114
+ {
115
+ // Set the highest priority to ensure that this method is executed before any others.
116
+ #[OnEvent(Event\Update::class, priority: 10)]
117
+ public function __invoke(Type\Update $update): EventCallbackReturn
118
+ {
119
+ // Stop executing other controllers if the sender doesn't meet some conditions
120
+ if ($update->message?->from->id !== 123456789) {
121
+ return $this->stop();
122
+ }
123
+
124
+ return $this->continue();
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Publish list of command as bot button
130
+ It's possible to publish all your commands that will be shown as list of available commands in the bot's menu button.
131
+ To do this fill in the _ description_ field and the _ publish_ flag in the OnCommand attribute, and run the command.
132
+ ``` bash
133
+ $ bin/console telegram:button:setcommands
134
+ ```
135
+
136
+ For button delete.
137
+ ``` bash
138
+ $ bin/console telegram:button:delete
139
+ ```
140
+
141
+ ``` php
142
+ use Luzrain\TelegramBotApi\Method;
143
+ use Luzrain\TelegramBotApi\Type;
144
+ use Luzrain\TelegramBotBundle\Attribute\OnCommand;
145
+ use Luzrain\TelegramBotBundle\TelegramBot\TelegramCommand;
146
+
147
+ final class CommandsController extends TelegramCommand
148
+ {
149
+ #[OnCommand(command: '/command1', description: 'Test command 1', publish: true)]
150
+ public function __invoke(Type\Message $message): Method
151
+ {
152
+ return $this->reply('Command 1 response');
153
+ }
154
+
155
+ #[OnCommand(command: '/command2', description: 'Test command 2', publish: true)]
156
+ public function __invoke(Type\Message $message): Method
157
+ {
158
+ return $this->reply('Command 2 response');
159
+ }
160
+
161
+ #[OnCommand(command: '/command3', description: 'This command will not be published', publish: false)]
162
+ public function __invoke(Type\Message $message): Method
163
+ {
164
+ return $this->reply('Command 3 response');
165
+ }
166
+ }
103
167
```
0 commit comments