Longman\TelegramBot\Entities\Message::getPhoto PHP Method

getPhoto() public method

This method overrides the default getPhoto method and returns a nice array of PhotoSize objects.
public getPhoto ( ) : null | Longman\TelegramBot\Entities\PhotoSize[]
return null | Longman\TelegramBot\Entities\PhotoSize[]
    public function getPhoto()
    {
        $pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo');
        return empty($pretty_array) ? null : $pretty_array;
    }

Usage Example

 /**
  * SendBack
  *
  * Received a message, the bot can send a copy of it to another chat/channel.
  * You don't have to care about the type of the message, the function detect it and use the proper
  * REQUEST:: function to send it.
  * $data include all the var that you need to send the message to the proper chat
  *
  * @todo This method will be moved at an higher level maybe in AdminCommand or Command
  * @todo Looking for a more significative name
  *
  * @param Entities\Message $message
  * @param array            $data
  *
  * @return Entities\ServerResponse
  */
 protected function sendBack(Message $message, array $data)
 {
     $type = $message->getType();
     $type = $type == 'command' ? 'Message' : $type;
     if ($type == 'Message') {
         $data['text'] = $message->getText(true);
     } elseif ($type == 'Audio') {
         $data['audio'] = $message->getAudio()->getFileId();
         $data['duration'] = $message->getAudio()->getDuration();
         $data['performer'] = $message->getAudio()->getPerformer();
         $data['title'] = $message->getAudio()->getTitle();
     } elseif ($type == 'Document') {
         $data['document'] = $message->getDocument()->getFileId();
     } elseif ($type == 'Photo') {
         $data['photo'] = $message->getPhoto()[0]->getFileId();
     } elseif ($type == 'Sticker') {
         $data['sticker'] = $message->getSticker()->getFileId();
     } elseif ($type == 'Video') {
         $data['video'] = $message->getVideo()->getFileId();
     } elseif ($type == 'Voice') {
         $data['voice'] = $message->getVoice()->getFileId();
     } elseif ($type == 'Location') {
         $data['latitude'] = $message->getLocation()->getLatitude();
         $data['longitude'] = $message->getLocation()->getLongitude();
     }
     $callback_path = 'Longman\\TelegramBot\\Request';
     $callback_function = 'send' . $type;
     if (!method_exists($callback_path, $callback_function)) {
         throw new TelegramException('Methods: ' . $callback_function . ' not found in class Request.');
     }
     return call_user_func_array($callback_path . '::' . $callback_function, [$data]);
 }
All Usage Examples Of Longman\TelegramBot\Entities\Message::getPhoto