1 | <?php |
||
16 | class Client |
||
17 | { |
||
18 | /** |
||
19 | * RegExp for bot commands |
||
20 | */ |
||
21 | const REGEXP = '/^\/([^\s@]+)(@\S+)?\s?(.*)$/'; |
||
22 | |||
23 | /** |
||
24 | * @var \TelegramBot\Api\BotApi |
||
25 | */ |
||
26 | protected $api; |
||
27 | |||
28 | /** |
||
29 | * @var \TelegramBot\Api\Events\EventCollection |
||
30 | */ |
||
31 | protected $events; |
||
32 | |||
33 | /** |
||
34 | * Client constructor |
||
35 | * |
||
36 | * @param string $token Telegram Bot API token |
||
37 | * @param string|null $trackerToken Yandex AppMetrica application api_key |
||
38 | */ |
||
39 | public function __construct($token, $trackerToken = null) |
||
44 | |||
45 | /** |
||
46 | * Use this method to add command. Parameters will be automatically parsed and passed to closure. |
||
47 | * |
||
48 | * @param string $name |
||
49 | * @param \Closure $action |
||
50 | * |
||
51 | * @return \TelegramBot\Api\Client |
||
52 | */ |
||
53 | public function command($name, Closure $action) |
||
57 | |||
58 | public function inlineQuery(Closure $action) |
||
62 | |||
63 | /** |
||
64 | * Use this method to add an event. |
||
65 | * If second closure will return true (or if you are passed null instead of closure), first one will be executed. |
||
66 | * |
||
67 | * @param \Closure $event |
||
68 | * @param \Closure|null $checker |
||
69 | * |
||
70 | * @return \TelegramBot\Api\Client |
||
71 | */ |
||
72 | public function on(Closure $event, Closure $checker = null) |
||
78 | |||
79 | /** |
||
80 | * Handle updates |
||
81 | * |
||
82 | * @param Update[] $updates |
||
83 | */ |
||
84 | public function handle(array $updates) |
||
91 | |||
92 | /** |
||
93 | * Webhook handler |
||
94 | * |
||
95 | * @return array |
||
96 | * @throws \TelegramBot\Api\InvalidJsonException |
||
97 | */ |
||
98 | public function run() |
||
104 | |||
105 | /** |
||
106 | * Returns event function to handling the command. |
||
107 | * |
||
108 | * @param \Closure $action |
||
109 | * |
||
110 | * @return \Closure |
||
111 | */ |
||
112 | protected static function getEvent(Closure $action) |
||
135 | |||
136 | protected static function getInlineQueryEvent(Closure $action) |
||
145 | |||
146 | /** |
||
147 | * Returns check function to handling the command. |
||
148 | * |
||
149 | * @param string $name |
||
150 | * |
||
151 | * @return \Closure |
||
152 | */ |
||
153 | protected static function getChecker($name) |
||
166 | |||
167 | /** |
||
168 | * Returns check function to handling the inline queries. |
||
169 | * |
||
170 | * @return Closure |
||
171 | */ |
||
172 | protected static function getInlineQueryChecker() |
||
178 | |||
179 | |||
180 | public function __call($name, array $arguments) |
||
189 | } |
||
190 |