1 | <?php |
||
15 | class Client |
||
16 | { |
||
17 | /** |
||
18 | * RegExp for bot commands |
||
19 | */ |
||
20 | const REGEXP = '/^\/([^\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 | public function __construct($token, $trackerToken = null) |
||
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 inlineQuery(Closure $action) |
||
61 | |||
62 | /** |
||
63 | * Use this method to add an event. |
||
64 | * If second closure will return true (or if you are passed null instead of closure), first one will be executed. |
||
65 | * |
||
66 | * @param \Closure $event |
||
67 | * @param \Closure|null $checker |
||
68 | * |
||
69 | * @return \TelegramBot\Api\Client |
||
70 | */ |
||
71 | public function on(Closure $event, Closure $checker = null) |
||
77 | |||
78 | /** |
||
79 | * Handle updates |
||
80 | * |
||
81 | * @param Update[] $updates |
||
82 | */ |
||
83 | public function handle(array $updates) |
||
90 | |||
91 | /** |
||
92 | * Webhook handler |
||
93 | * |
||
94 | * @return array |
||
95 | * @throws \TelegramBot\Api\InvalidJsonException |
||
96 | */ |
||
97 | public function run() |
||
103 | |||
104 | public function getRawBody() |
||
108 | |||
109 | /** |
||
110 | * Returns event function to handling the command. |
||
111 | * |
||
112 | * @param \Closure $action |
||
113 | * |
||
114 | * @return \Closure |
||
115 | */ |
||
116 | protected static function getEvent(Closure $action) |
||
143 | |||
144 | protected static function getInlineQueryEvent(Closure $action) |
||
153 | |||
154 | /** |
||
155 | * Returns check function to handling the command. |
||
156 | * |
||
157 | * @param string $name |
||
158 | * |
||
159 | * @return \Closure |
||
160 | */ |
||
161 | protected static function getChecker($name) |
||
174 | |||
175 | /** |
||
176 | * Returns check function to handling the inline queries. |
||
177 | * |
||
178 | * @return Closure |
||
179 | */ |
||
180 | protected static function getInlineQueryChecker() |
||
186 | |||
187 | |||
188 | public function __call($name, array $arguments) |
||
197 | } |
||
198 |