1 | <?php |
||
15 | class Client |
||
16 | { |
||
17 | /** |
||
18 | * RegExp for bot commands |
||
19 | */ |
||
20 | const REGEXP = '/^(?:@\w+\s)?\/([^\s@]+)(@\S+)?\s?(.*)$/'; |
||
21 | |||
22 | /** |
||
23 | * @var \TelegramBot\Api\BotApi |
||
24 | */ |
||
25 | protected $api; |
||
26 | |||
27 | /** |
||
28 | * @var \TelegramBot\Api\Events\EventCollection |
||
29 | */ |
||
30 | protected $events; |
||
31 | |||
32 | /** |
||
33 | * Client constructor |
||
34 | * |
||
35 | * @param string $token Telegram Bot API token |
||
36 | * @param string|null $trackerToken Yandex AppMetrica application api_key |
||
37 | */ |
||
38 | 7 | public function __construct($token, $trackerToken = null) |
|
39 | { |
||
40 | 7 | $this->api = new BotApi($token); |
|
41 | 7 | $this->events = new EventCollection($trackerToken); |
|
42 | 7 | } |
|
43 | |||
44 | /** |
||
45 | * Use this method to add command. Parameters will be automatically parsed and passed to closure. |
||
46 | * |
||
47 | * @param string $name |
||
48 | * @param \Closure $action |
||
49 | * |
||
50 | * @return \TelegramBot\Api\Client |
||
51 | */ |
||
52 | public function command($name, Closure $action) |
||
56 | |||
57 | public function editedMessage(Closure $action) |
||
62 | |||
63 | public function channelPost(Closure $action) |
||
68 | |||
69 | public function editedChannelPost(Closure $action) |
||
74 | |||
75 | public function inlineQuery(Closure $action) |
||
80 | |||
81 | 1 | public function chosenInlineResult(Closure $action) |
|
86 | |||
87 | public function shippingQuery(Closure $action) |
||
92 | |||
93 | 4 | public function preCheckoutQuery(Closure $action) |
|
98 | 4 | ||
99 | 4 | /** |
|
100 | * Use this method to add an event. |
||
101 | * If second closure will return true (or if you are passed null instead of closure), first one will be executed. |
||
102 | * |
||
103 | * @param \Closure $event |
||
104 | * @param \Closure|null $checker |
||
105 | * |
||
106 | * @return \TelegramBot\Api\Client |
||
107 | */ |
||
108 | public function on(Closure $event, Closure $checker = null) |
||
114 | |||
115 | /** |
||
116 | * Handle updates |
||
117 | * |
||
118 | * @param Update[] $updates |
||
119 | */ |
||
120 | public function handle(array $updates) |
||
127 | |||
128 | /** |
||
129 | 4 | * Webhook handler |
|
130 | 4 | * |
|
131 | 1 | * @return array |
|
132 | * @throws \TelegramBot\Api\InvalidJsonException |
||
133 | */ |
||
134 | 3 | public function run() |
|
140 | |||
141 | public function getRawBody() |
||
145 | |||
146 | 3 | /** |
|
147 | 3 | * Returns event function to handling the command. |
|
148 | 3 | * |
|
149 | * @param \Closure $action |
||
150 | 3 | * |
|
151 | 4 | * @return \Closure |
|
152 | */ |
||
153 | protected static function getEvent(Closure $action) |
||
180 | |||
181 | protected static function getCustomEvent(Closure $action, $method) |
||
193 | |||
194 | /** |
||
195 | * Returns check function to handling the command. |
||
196 | * |
||
197 | * @param string $name |
||
198 | * |
||
199 | * @return \Closure |
||
200 | 4 | */ |
|
201 | protected static function getChecker($name) |
||
214 | |||
215 | |||
216 | /** |
||
217 | * Returns check function to handling the custom event |
||
218 | * @link https://core.telegram.org/bots/api#update |
||
219 | 4 | * |
|
220 | * @param string $method Update method name |
||
221 | * |
||
222 | 4 | * @return Closure |
|
223 | 4 | */ |
|
224 | protected static function getCustomEventChecker($method) |
||
230 | |||
231 | public function __call($name, array $arguments) |
||
240 | } |
||
241 |