From 9b547b58959c4d6931a921f51b1d1f4f765605fa Mon Sep 17 00:00:00 2001 From: feralheart Date: Sat, 24 Mar 2018 14:16:59 +0100 Subject: [PATCH 1/3] add getUserProfilePhotos method --- src/TelegramDriver.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/TelegramDriver.php b/src/TelegramDriver.php index cee9eef..46a4db3 100644 --- a/src/TelegramDriver.php +++ b/src/TelegramDriver.php @@ -71,6 +71,45 @@ public function getUser(IncomingMessage $matchingMessage) $userData->get('username'), $responseData['result']); } + /** + * @param IncomingMessage $matchingMessage + * @return array $userProfilePhotoPaths + * @throws TelegramException + */ + public function getUserProfilePhotos(IncomingMessage $matchingMessage) + { + $userId = $matchingMessage->getSender(); + + $profilePhotoParameters = [ + 'user_id' => $userId, + 'limit' => 1, + ]; + + $responseProfilePhoto = $this->http->post($this->buildApiUrl('getUserProfilePhotos'), [], $profilePhotoParameters); + + $responseDataProfilePhotos = json_decode($responseProfilePhoto->getContent(), true); + if ($responseProfilePhoto->getStatusCode() !== 200) { + throw new TelegramException('Error retrieving user photos info: '.$responseDataProfilePhotos['description']); + } + + foreach($responseDataProfilePhotos['result']['photos'] as $photoArray){ + foreach($photoArray as $photo){ + $profilePhotoParameters = [ + 'file_id' => $photo['file_id'], + ]; + $responsePhotoFile = $this->http->post($this->buildApiUrl('getFile'), [], $profilePhotoParameters); + + $responseDataPhotoFile = json_decode($responsePhotoFile->getContent(), true); + if ($responsePhotoFile->getStatusCode() !== 200) { + throw new TelegramException('Error retrieving user photos info: '.$responseDataPhotoFile['description']); + } + $userProfilePhotoPaths[] = "https://api.telegram.org/file/bot" . env('TELEGRAM_TOKEN') . "/" . $responseDataPhotoFile['result']['file_path']; + } + } + + return $userProfilePhotoPaths; + } + /** * Determine if the request is for this driver. * From bc46d31ad27ce4fa79fca3be63d87ad7af3ea32f Mon Sep 17 00:00:00 2001 From: feralheart Date: Sat, 24 Mar 2018 14:42:20 +0100 Subject: [PATCH 2/3] Apply fixes from StyleCI (#34) --- src/TelegramDriver.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/TelegramDriver.php b/src/TelegramDriver.php index 46a4db3..bb5f5e7 100644 --- a/src/TelegramDriver.php +++ b/src/TelegramDriver.php @@ -78,10 +78,9 @@ public function getUser(IncomingMessage $matchingMessage) */ public function getUserProfilePhotos(IncomingMessage $matchingMessage) { - $userId = $matchingMessage->getSender(); $profilePhotoParameters = [ - 'user_id' => $userId, + 'user_id' => $matchingMessage->getSender(), 'limit' => 1, ]; @@ -92,8 +91,8 @@ public function getUserProfilePhotos(IncomingMessage $matchingMessage) throw new TelegramException('Error retrieving user photos info: '.$responseDataProfilePhotos['description']); } - foreach($responseDataProfilePhotos['result']['photos'] as $photoArray){ - foreach($photoArray as $photo){ + foreach ($responseDataProfilePhotos['result']['photos'] as $photoArray){ + foreach ($photoArray as $photo){ $profilePhotoParameters = [ 'file_id' => $photo['file_id'], ]; @@ -103,7 +102,7 @@ public function getUserProfilePhotos(IncomingMessage $matchingMessage) if ($responsePhotoFile->getStatusCode() !== 200) { throw new TelegramException('Error retrieving user photos info: '.$responseDataPhotoFile['description']); } - $userProfilePhotoPaths[] = "https://api.telegram.org/file/bot" . env('TELEGRAM_TOKEN') . "/" . $responseDataPhotoFile['result']['file_path']; + $userProfilePhotoPaths[] = "https://api.telegram.org/file/bot".env('TELEGRAM_TOKEN')."/".$responseDataPhotoFile['result']['file_path']; } } From 436fe39fd891c269a94424bab7d56356343b9603 Mon Sep 17 00:00:00 2001 From: feralheart Date: Sat, 24 Mar 2018 14:44:33 +0100 Subject: [PATCH 3/3] Apply fices from StyleCI (#34) --- src/TelegramDriver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TelegramDriver.php b/src/TelegramDriver.php index bb5f5e7..8fb66a1 100644 --- a/src/TelegramDriver.php +++ b/src/TelegramDriver.php @@ -91,8 +91,8 @@ public function getUserProfilePhotos(IncomingMessage $matchingMessage) throw new TelegramException('Error retrieving user photos info: '.$responseDataProfilePhotos['description']); } - foreach ($responseDataProfilePhotos['result']['photos'] as $photoArray){ - foreach ($photoArray as $photo){ + foreach ($responseDataProfilePhotos['result']['photos'] as $photoArray) { + foreach ($photoArray as $photo) { $profilePhotoParameters = [ 'file_id' => $photo['file_id'], ]; @@ -102,7 +102,7 @@ public function getUserProfilePhotos(IncomingMessage $matchingMessage) if ($responsePhotoFile->getStatusCode() !== 200) { throw new TelegramException('Error retrieving user photos info: '.$responseDataPhotoFile['description']); } - $userProfilePhotoPaths[] = "https://api.telegram.org/file/bot".env('TELEGRAM_TOKEN')."/".$responseDataPhotoFile['result']['file_path']; + $userProfilePhotoPaths[] = 'https://api.telegram.org/file/bot'.env('TELEGRAM_TOKEN').'/'.$responseDataPhotoFile['result']['file_path']; } }