Skip to content

Commit 5bfdda1

Browse files
authored
Update methods.md
1 parent 0245722 commit 5bfdda1

File tree

1 file changed

+81
-7
lines changed

1 file changed

+81
-7
lines changed

methods.md

+81-7
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,91 @@ Bot::onText(['hello', 'hay'], function(Request $request){
123123
});
124124
```
125125
---
126-
### Updates
127-
User Request class to get updates.
126+
### Controller
128127
```php
128+
# app/Resources/bot.php
129+
130+
Bot::onText('hello', "App/Controller/HelloController@sayHello");
131+
Bot::onText('hello', [App/Controller/HelloController::class ,"sayHello"]);
132+
```
133+
134+
```php
135+
# app/Controllers/HelloController.php
136+
129137
use LaraGram\Request\Request;
130138

131-
$request = new Request();
139+
class HelloController
140+
{
141+
public function sayHello(Request $request)
142+
{
143+
$request->sendMessage(chat()->id, "hello");
144+
}
145+
}
146+
```
147+
---
148+
### Group Listeners:
149+
150+
Use one Controller for many listeners:
151+
```php
152+
Bot::controller("App/Controller/GreetingController")->group(function(){
153+
Bot::onText('hello', "sayHello");
154+
Bot::onText('hello', "sayBye");
155+
// ...
156+
});
157+
```
158+
159+
Conditions:
160+
161+
- Access Controll:
162+
```php
163+
Bot::can("administrator")->group(function(){
164+
// ...
165+
})
166+
```
167+
168+
```php
169+
Bot::canNot("administrator")->group(function(){
170+
// ...
171+
})
172+
```
173+
174+
- Scope Controll:
175+
```php
176+
Bot::scope("private")->group(function(){
177+
// ...
178+
})
179+
```
132180

133-
$text = $request->message->text;
134-
$reply_to_message_chat_id = $request->message->reply_to_message->chat->id;
135-
$callback_data = $request->callback_query->data;
136-
$new_chat_members = $request->message->new_chat_members;
181+
```php
182+
Bot::outOfScope("private")->group(function(){
183+
// ...
184+
})
185+
```
186+
187+
- Is Replied?
188+
```php
189+
Bot::hasReply()->group(function(){
190+
// ...
191+
})
192+
```
193+
194+
```php
195+
Bot::hasNotReply()->group(function(){
196+
// ...
197+
})
198+
```
199+
200+
- Multiple Conditions:
201+
```php
202+
Bot::group(["can" => "creator", "scope" => "private"], function(){
203+
// ...
204+
})
205+
```
206+
207+
```php
208+
Bot::canNot("administrator")->hasReply()->group(function(){
209+
// ...
210+
})
137211
```
138212
---
139213
### [⬅️⬅️ Return to home](https://github.com/laraXgram/Document/blob/v1.10/readme.md)

0 commit comments

Comments
 (0)