This repository was archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.php
More file actions
95 lines (77 loc) · 2.23 KB
/
route.php
File metadata and controls
95 lines (77 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
use Psr\Http\Message\RequestInterface;
use WooMaiLabs\TelegramBotAPI\Models\Update;
use WooMaiLabs\TelegramBotAPI\Router\Callback;
use WooMaiLabs\TelegramBotAPI\Router\Command;
use WooMaiLabs\TelegramBotAPI\Router\MiddlewareInterface;
use WooMaiLabs\TelegramBotAPI\Router\Router;
use WooMaiLabs\TelegramBotAPI\Router\WebhookResponse;
require '../vendor/autoload.php';
$handler1 = function (Update $update) {
return new WebhookResponse('sendMessage', [
'chat_id' => '@example_username',
'text' => 'Hello World!'
]);
};
$handler2 = function (Update $update) {
// you can also return void
};
$router = new Router(1145141919, 'ExampleBot');
/**
* Standard command
* @example /help
*/
$router->command(new Command('help'), $handler1);
/**
* Custom command prefix
* @example !ban
*/
$router->command(new Command('ban', '!'), $handler2);
/**
* Subcommand support
* @example /test_command subcommand sub_subcommand [param 1] [param 2] ...
*/
$router->command(new Command('test_command', subcommands: ['subcommand', 'sub_subcommand']), $handler2);
/**
* work with middlewares (FIFO, middleware 1 -> middleware 2)
* @var MiddlewareInterface $middleware1
* @var MiddlewareInterface $middleware2
*/
$router->command(new Command('hello'), $handler1, $middleware1, $middleware2);
/**
* Command alias
*/
$router->command([new Command('hello'), new Command('hi')], $handler2, $middleware1);
/**
* Callback Query
*/
$router->callback(new Callback('action1'), $handler1, $middleware2);
/**
* Plain text with regex
*/
$router->text('/^https?:\/\/example\.com/i', $handler1, $middleware1);
/**
* Plain text default route
*/
$router->text('', $handler1, $middleware1);
/**
* Inline Query
* It's similar to Plain text
*/
$router->inline('/^help/', $handler1, $middleware1);
$router->inline('', $handler2, $middleware1, $middleware2);
/**
* Global middlewares.
* Runs before any other middleware and any type of update.
*/
$router->addGlobalMiddlewares($middleware1, $middleware2);
/**
* Route the webhook
* @var RequestInterface $request
*/
$router->route(request: $request);
/**
* You can also use raw update object to route
*/
//$raw_update = json_decode('php://input');
//$router->route(update_object: $raw_update);