1 | <?php |
||
9 | class Bot implements BotInterface { |
||
10 | |||
11 | use \League\Event\EmitterTrait; |
||
12 | |||
13 | /** @var string */ |
||
14 | private $botToken; |
||
15 | /** @var int */ |
||
16 | private $offset; |
||
17 | /** @var \React\HttpClient\Client */ |
||
18 | private $client; |
||
19 | |||
20 | /** |
||
21 | * @param string $botToken |
||
22 | */ |
||
23 | 5 | public function __construct(string $botToken) |
|
27 | |||
28 | /** |
||
29 | * @param \React\HttpClient\Client |
||
30 | */ |
||
31 | 5 | public function setClient(Client $client) { |
|
34 | |||
35 | public function poll() { |
||
40 | |||
41 | /** |
||
42 | * @param \React\HttpClient\Response $response |
||
43 | */ |
||
44 | public function _handlePollResponse(Response $response) { |
||
48 | |||
49 | /** |
||
50 | * @param array $data |
||
51 | * @param \React\HttpClient\Response $response |
||
52 | */ |
||
53 | public function _handlePollData($data, $response) { |
||
71 | |||
72 | /** |
||
73 | * @param \React\HttpClient\Response $response |
||
74 | */ |
||
75 | public function _handlePollError(Response $response) { |
||
79 | |||
80 | /** |
||
81 | * @param string $message |
||
82 | */ |
||
83 | public function getResponder($message) { |
||
84 | 1 | return function ($text) use($message){ |
|
85 | $this->sendResponse($text, $message); |
||
86 | 1 | }; |
|
87 | } |
||
88 | |||
89 | 1 | public function getMassagesRequest(): Request { |
|
90 | 1 | return $this->client->request( |
|
91 | 1 | 'GET', |
|
92 | 1 | $this->botCommand('getUpdates', ['offset' => $this->offset]) |
|
93 | ); |
||
94 | } |
||
95 | |||
96 | 1 | public function sendResponse(string $responseText, array $incomingMessage) { |
|
97 | 1 | $responseData = $this->postDataEncoder([ |
|
98 | 1 | 'chat_id' => $incomingMessage['message']['chat']['id'], |
|
99 | 1 | 'reply_to_message_id' => $incomingMessage['message']['message_id'], |
|
100 | 1 | 'text' => $responseText |
|
101 | ]); |
||
102 | |||
103 | 1 | $responseCall = $this->client->request( |
|
104 | 1 | 'POST', |
|
105 | 1 | $this->botCommand('sendMessage'), |
|
106 | 1 | $this->getResponseHeaders($responseData) |
|
107 | ); |
||
108 | |||
109 | 1 | $responseCall->end($responseData); |
|
110 | 1 | } |
|
111 | |||
112 | public function setUpdateId($id) { |
||
115 | |||
116 | |||
117 | 2 | private function botCommand(string $command, array $params = []) :string { |
|
118 | 2 | $params = (count($params)) ? '?' . $this->postDataEncoder($params) : ''; |
|
122 | |||
123 | |||
124 | 2 | private function assembleUri($command, $params) :string { |
|
132 | |||
133 | 2 | public function getResponseHeaders(string $responseString) :array { |
|
139 | |||
140 | 2 | private function postDataEncoder(array $data) :string { |
|
149 | } |
||
150 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.