@@ -61,7 +61,7 @@ public function sendMessage(SendMessage $sendMessage): Message
6161 return $ message ;
6262 }
6363
64- throw new \LogicException ('Unexpected response: ' . (string ) $ response ->getBody ());
64+ throw new \LogicException ('Unexpected response: ' . (string )$ response ->getBody ());
6565 }
6666
6767 public function sendPhoto (SendPhoto $ sendPhoto ): ResponseInterface
@@ -98,21 +98,21 @@ public function sendDocument(SendDocument $sendDocument): Message
9898
9999 if ($ doc instanceof FileId || $ doc instanceof FileUrl) {
100100 $ data = get_values ($ sendDocument );
101- $ data ['document ' ] = (string ) $ doc ;
101+ $ data ['document ' ] = (string )$ doc ;
102102
103103 $ response = $ this ->httpClient ->post ($ this ->getMethodUrl ('sendDocument ' ), [
104104 'json ' => $ data ,
105105 ]);
106106
107- $ json = json_decode ((string ) $ response ->getBody (), true );
107+ $ json = json_decode ((string )$ response ->getBody (), true );
108108 if (isset ($ json ['ok ' ]) && $ json ['ok ' ]) {
109109 $ message = new Message ();
110110 set_values ($ message , $ json ['result ' ]);
111111
112112 return $ message ;
113113 }
114114
115- throw new \LogicException ('Unexpected response: ' . (string ) $ response ->getBody ());
115+ throw new \LogicException ('Unexpected response: ' . (string )$ response ->getBody ());
116116 }
117117
118118 if ($ doc instanceof InputFile) {
@@ -134,18 +134,18 @@ public function sendDocument(SendDocument $sendDocument): Message
134134 'multipart ' => $ data ,
135135 ]);
136136
137- $ json = json_decode ((string ) $ response ->getBody (), true );
137+ $ json = json_decode ((string )$ response ->getBody (), true );
138138 if (isset ($ json ['ok ' ]) && $ json ['ok ' ]) {
139139 $ message = new Message ();
140140 set_values ($ message , $ json ['result ' ]);
141141
142142 return $ message ;
143143 }
144144
145- throw new \LogicException ('Unexpected response: ' . (string ) $ response ->getBody ());
145+ throw new \LogicException ('Unexpected response: ' . (string ) $ response ->getBody ());
146146 }
147147
148- throw new \LogicException (sprintf ('Unexpected document: %s ' . get_class ($ doc )));
148+ throw new \LogicException (sprintf ('Unexpected document: %s ' . get_class ($ doc )));
149149 }
150150
151151 public function sendInvoice (SendInvoice $ sendInvoice )
@@ -175,7 +175,7 @@ public function editMessageText(EditMessageText $editMessageText): ?Message
175175 'json ' => get_values ($ editMessageText ),
176176 ]);
177177
178- $ json = json_decode ((string ) $ response ->getBody (), true );
178+ $ json = json_decode ((string )$ response ->getBody (), true );
179179
180180 if (isset ($ json ['ok ' ]) && $ json ['ok ' ]) {
181181 $ message = new Message ();
@@ -184,7 +184,7 @@ public function editMessageText(EditMessageText $editMessageText): ?Message
184184 return $ message ;
185185 }
186186
187- throw new \LogicException ('Unexpected response: ' . (string ) $ response ->getBody ());
187+ throw new \LogicException ('Unexpected response: ' . (string ) $ response ->getBody ());
188188 }
189189
190190 public function deleteMessage (DeleteMessage $ deleteMessage ): bool
@@ -193,7 +193,7 @@ public function deleteMessage(DeleteMessage $deleteMessage): bool
193193 'json ' => get_values ($ deleteMessage ),
194194 ]);
195195
196- $ response = json_decode ((string ) $ response ->getBody (), true );
196+ $ response = json_decode ((string )$ response ->getBody (), true );
197197
198198 if (isset ($ response ['ok ' ]) && $ response ['ok ' ]) {
199199 return true ;
@@ -202,6 +202,31 @@ public function deleteMessage(DeleteMessage $deleteMessage): bool
202202 return false ;
203203 }
204204
205+ /**
206+ * @see https://core.telegram.org/bots/api#getfile
207+ */
208+ public function getFile (GetFile $ getFile ): File
209+ {
210+ $ response = $ this ->httpClient ->post ($ this ->getMethodUrl ('getFile ' ), [
211+ 'json ' => get_values ($ getFile ),
212+ ]);
213+
214+ $ json = json_decode ((string ) $ response ->getBody (), true );
215+
216+ if (isset ($ json ['ok ' ]) && $ json ['ok ' ]) {
217+ $ file = new File ();
218+ set_values ($ file , $ json ['result ' ]);
219+
220+ if ($ path = $ file ->getFilePath ()) {
221+ $ file ->setFileUrl (sprintf ('https://api.telegram.org/file/bot%s/%s ' , $ this ->token , $ path ));
222+ }
223+
224+ return $ file ;
225+ }
226+
227+ throw new \LogicException ('Unexpected response: ' . (string ) $ response ->getBody ());
228+ }
229+
205230 private function getMethodUrl (string $ method ): string
206231 {
207232 return sprintf ('https://api.telegram.org/bot%s/%s ' , $ this ->token , $ method );
0 commit comments