@@ -33,6 +33,7 @@ class Request
33
33
'getUserProfilePhotos ' ,
34
34
'getUpdates ' ,
35
35
'setWebhook ' ,
36
+ 'getFile '
36
37
);
37
38
38
39
public static function initialize (Telegram $ telegram )
@@ -166,6 +167,11 @@ public static function executeCurl($action, array $data)
166
167
return $ result ;
167
168
}
168
169
170
+ protected static function encodeFile ($ file )
171
+ {
172
+ return new \CURLFile ($ file );
173
+ }
174
+
169
175
public static function send ($ action , array $ data = null )
170
176
{
171
177
if (!in_array ($ action , self ::$ methods )) {
@@ -179,6 +185,9 @@ public static function send($action, array $data = null)
179
185
180
186
$ result = self ::executeCurl ($ action , $ data );
181
187
188
+ echo $ result ;
189
+ print_r (json_decode ($ result , true ));
190
+
182
191
$ bot_name = self ::$ telegram ->getBotName ();
183
192
return new ServerResponse (json_decode ($ result , true ), $ bot_name );
184
193
}
@@ -200,11 +209,15 @@ public static function sendMessage(array $data)
200
209
return $ result ;
201
210
}
202
211
203
- //TODO forwardMessage
204
-
205
- protected static function encodeFile ($ file )
212
+ public static function forwardMessage (array $ data )
206
213
{
207
- return new \CURLFile ($ file );
214
+
215
+ if (empty ($ data )) {
216
+ throw new TelegramException ('Data is empty! ' );
217
+ }
218
+
219
+ $ result = self ::send ('forwardMessage ' , $ data );
220
+ return $ result ;
208
221
}
209
222
210
223
public static function sendPhoto (array $ data , $ file = null )
@@ -310,22 +323,50 @@ public static function sendChatAction(array $data)
310
323
return $ result ;
311
324
}
312
325
313
- //getUserProfilePhotos
326
+ public static function getUserProfilePhotos ($ data )
327
+ {
328
+ if (empty ($ data )) {
329
+ throw new TelegramException ('Data is empty! ' );
330
+ }
331
+ if (!isset ($ data ['user_id ' ])) {
332
+ throw new TelegramException ('User id is empty! ' );
333
+ }
334
+
335
+ $ result = self ::send ('getUserProfilePhotos ' , $ data );
336
+ return $ result ;
337
+ }
314
338
315
339
public static function getUpdates ($ data )
316
340
{
317
341
$ result = self ::send ('getUpdates ' , $ data );
318
342
return $ result ;
319
343
}
320
344
321
- public static function setWebhook ($ url )
345
+ public static function setWebhook ($ url, $ file = null )
322
346
{
323
- $ result = self ::send ('setWebhook ' , array ('url ' => $ url ));
347
+ if (empty ($ url )) {
348
+ throw new TelegramException ('Url is empty! ' );
349
+ }
350
+ $ data ['url ' ] = $ url ;
351
+
352
+ if (!is_null ($ file )) {
353
+ $ data ['certificate ' ] = self ::encodeFile ($ file );
354
+ }
355
+
356
+ $ result = self ::send ('setWebhook ' , $ data );
324
357
return $ result ;
325
358
}
326
359
327
- //getFile
328
360
361
+ public static function getFile ($ data )
362
+ {
363
+ if (empty ($ data )) {
364
+ throw new TelegramException ('Data is empty! ' );
365
+ }
366
+
367
+ $ result = self ::send ('getFile ' , $ data );
368
+ return $ result ;
369
+ }
329
370
/**
330
371
* Send Message in all the active chat
331
372
*
0 commit comments