sendPhoto() public static method

Use this method to send photos. On success, the sent Message is returned
public static sendPhoto ( array $data, string $file = null ) : ServerResponse
$data array
$file string
return Longman\TelegramBot\Entities\ServerResponse
 /**
  * Command execute method
  *
  * @return mixed
  * @throws \Longman\TelegramBot\Exception\TelegramException
  */
 public function execute()
 {
     $message = $this->getMessage();
     $chat = $message->getChat();
     $user = $message->getFrom();
     $text = trim($message->getText(true));
     $chat_id = $chat->getId();
     $user_id = $user->getId();
     //Preparing Response
     $data = ['chat_id' => $chat_id];
     if ($chat->isGroupChat() || $chat->isSuperGroup()) {
         //reply to message id is applied by default
         //Force reply is applied by default so it can work with privacy on
         $data['reply_markup'] = Keyboard::forceReply(['selective' => true]);
     }
     //Conversation start
     $this->conversation = new Conversation($user_id, $chat_id, $this->getName());
     $notes =& $this->conversation->notes;
     !is_array($notes) && ($notes = []);
     //cache data from the tracking session if any
     $state = 0;
     if (isset($notes['state'])) {
         $state = $notes['state'];
     }
     $result = Request::emptyResponse();
     //State machine
     //Entrypoint of the machine state if given by the track
     //Every time a step is achieved the track is updated
     switch ($state) {
         case 0:
             if ($text === '') {
                 $notes['state'] = 0;
                 $this->conversation->update();
                 $data['text'] = 'Type your name:';
                 $data['reply_markup'] = Keyboard::remove(['selective' => true]);
                 $result = Request::sendMessage($data);
                 break;
             }
             $notes['name'] = $text;
             $text = '';
             // no break
         // no break
         case 1:
             if ($text === '') {
                 $notes['state'] = 1;
                 $this->conversation->update();
                 $data['text'] = 'Type your surname:';
                 $result = Request::sendMessage($data);
                 break;
             }
             $notes['surname'] = $text;
             $text = '';
             // no break
         // no break
         case 2:
             if ($text === '' || !is_numeric($text)) {
                 $notes['state'] = 2;
                 $this->conversation->update();
                 $data['text'] = 'Type your age:';
                 if ($text !== '') {
                     $data['text'] = 'Type your age, must be a number:';
                 }
                 $result = Request::sendMessage($data);
                 break;
             }
             $notes['age'] = $text;
             $text = '';
             // no break
         // no break
         case 3:
             if ($text === '' || !in_array($text, ['M', 'F'], true)) {
                 $notes['state'] = 3;
                 $this->conversation->update();
                 $data['reply_markup'] = (new Keyboard(['M', 'F']))->setResizeKeyboard(true)->setOneTimeKeyboard(true)->setSelective(true);
                 $data['text'] = 'Select your gender:';
                 if ($text !== '') {
                     $data['text'] = 'Select your gender, choose a keyboard option:';
                 }
                 $result = Request::sendMessage($data);
                 break;
             }
             $notes['gender'] = $text;
             // no break
         // no break
         case 4:
             if ($message->getLocation() === null) {
                 $notes['state'] = 4;
                 $this->conversation->update();
                 $data['reply_markup'] = (new Keyboard((new KeyboardButton('Share Location'))->setRequestLocation(true)))->setOneTimeKeyboard(true)->setResizeKeyboard(true)->setSelective(true);
                 $data['text'] = 'Share your location:';
                 $result = Request::sendMessage($data);
                 break;
             }
             $notes['longitude'] = $message->getLocation()->getLongitude();
             $notes['latitude'] = $message->getLocation()->getLatitude();
             // no break
         // no break
         case 5:
             if ($message->getPhoto() === null) {
                 $notes['state'] = 5;
                 $this->conversation->update();
                 $data['text'] = 'Insert your picture:';
                 $result = Request::sendMessage($data);
                 break;
             }
             /** @var PhotoSize $photo */
             $photo = $message->getPhoto()[0];
             $notes['photo_id'] = $photo->getFileId();
             // no break
         // no break
         case 6:
             if ($message->getContact() === null) {
                 $notes['state'] = 6;
                 $this->conversation->update();
                 $data['reply_markup'] = (new Keyboard((new KeyboardButton('Share Contact'))->setRequestContact(true)))->setOneTimeKeyboard(true)->setResizeKeyboard(true)->setSelective(true);
                 $data['text'] = 'Share your contact information:';
                 $result = Request::sendMessage($data);
                 break;
             }
             $notes['phone_number'] = $message->getContact()->getPhoneNumber();
             // no break
         // no break
         case 7:
             $this->conversation->update();
             $out_text = '/Survey result:' . PHP_EOL;
             unset($notes['state']);
             foreach ($notes as $k => $v) {
                 $out_text .= PHP_EOL . ucfirst($k) . ': ' . $v;
             }
             $data['photo'] = $notes['photo_id'];
             $data['reply_markup'] = Keyboard::remove(['selective' => true]);
             $data['caption'] = $out_text;
             $this->conversation->stop();
             $result = Request::sendPhoto($data);
             break;
     }
     return $result;
 }
 /**
  * Command execute method
  *
  * @return mixed
  * @throws \Longman\TelegramBot\Exception\TelegramException
  */
 public function execute()
 {
     $message = $this->getMessage();
     $chat_id = $message->getChat()->getId();
     $command = $message->getCommand();
     $text = trim($message->getText(true));
     $data = ['chat_id' => $chat_id];
     //No point in replying to messages in private chats
     if (!$message->getChat()->isPrivateChat()) {
         $data['reply_to_message_id'] = $message->getMessageId();
     }
     if ($command !== 'whois') {
         $text = substr($command, 5);
         //We need that '-' now, bring it back
         if (strpos($text, 'g') === 0) {
             $text = str_replace('g', '-', $text);
         }
     }
     if ($text === '') {
         $text = 'Provide the id to lookup: /whois <id>';
     } else {
         $user_id = $text;
         $chat = null;
         $created_at = null;
         $updated_at = null;
         $result = null;
         if (is_numeric($text)) {
             $results = DB::selectChats(true, true, true, null, null, $user_id);
             if (!empty($results)) {
                 $result = reset($results);
             }
         } else {
             $results = DB::selectChats(true, true, true, null, null, null, $text);
             if (is_array($results) && count($results) === 1) {
                 $result = reset($results);
             }
         }
         if (is_array($result)) {
             $result['id'] = $result['chat_id'];
             $chat = new Chat($result);
             $user_id = $result['id'];
             $created_at = $result['chat_created_at'];
             $updated_at = $result['chat_updated_at'];
             $old_id = $result['old_id'];
         }
         if ($chat !== null) {
             if ($chat->isPrivateChat()) {
                 $text = 'User ID: ' . $user_id . PHP_EOL;
                 $text .= 'Name: ' . $chat->getFirstName() . ' ' . $chat->getLastName() . PHP_EOL;
                 $username = $chat->getUsername();
                 if ($username !== null && $username !== '') {
                     $text .= 'Username: @' . $username . PHP_EOL;
                 }
                 $text .= 'First time seen: ' . $created_at . PHP_EOL;
                 $text .= 'Last activity: ' . $updated_at . PHP_EOL;
                 //Code from Whoami command
                 $limit = 10;
                 $offset = null;
                 $response = Request::getUserProfilePhotos(['user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]);
                 if ($response->isOk()) {
                     /** @var UserProfilePhotos $user_profile_photos */
                     $user_profile_photos = $response->getResult();
                     if ($user_profile_photos->getTotalCount() > 0) {
                         $photos = $user_profile_photos->getPhotos();
                         /** @var PhotoSize $photo */
                         $photo = $photos[0][2];
                         $file_id = $photo->getFileId();
                         $data['photo'] = $file_id;
                         $data['caption'] = $text;
                         return Request::sendPhoto($data);
                     }
                 }
             } elseif ($chat->isGroupChat()) {
                 $text = 'Chat ID: ' . $user_id . (!empty($old_id) ? ' (previously: ' . $old_id . ')' : '') . PHP_EOL;
                 $text .= 'Type: ' . ucfirst($chat->getType()) . PHP_EOL;
                 $text .= 'Title: ' . $chat->getTitle() . PHP_EOL;
                 $text .= 'First time added to group: ' . $created_at . PHP_EOL;
                 $text .= 'Last activity: ' . $updated_at . PHP_EOL;
             }
         } elseif (is_array($results) && count($results) > 1) {
             $text = 'Multiple chats matched!';
         } else {
             $text = 'Chat not found!';
         }
     }
     $data['text'] = $text;
     return Request::sendMessage($data);
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $message = $this->getMessage();
     $chat_id = $message->getChat()->getId();
     $text = $message->getText(true);
     $data = ['chat_id' => $chat_id, 'caption' => $text];
     //Return a random picture from the telegram->getUploadPath().
     return Request::sendPhoto($data, $this->ShowRandomImage($this->telegram->getUploadPath()));
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $message = $this->getMessage();
     $chat_id = $message->getChat()->getId();
     $text = $message->getText(true);
     $data = [];
     $data['chat_id'] = $chat_id;
     $data['caption'] = $text;
     //return Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
     return Request::sendPhoto($data, $this->ShowRandomImage($this->telegram->getUploadPath()));
 }
 public function execute()
 {
     $update = $this->getUpdate();
     $message = $this->getMessage();
     $chat_id = $message->getChat()->getId();
     $text = $message->getText(true);
     $data = array();
     $data['chat_id'] = $chat_id;
     $data['caption'] = $text;
     //$result = Request::sendDocument($data,'structure.sql');
     //$result = Request::sendSticker($data, $this->telegram->getUploadPath().'/'.'image.jpg');
     $result = Request::sendPhoto($data, $this->telegram->getUploadPath() . '/' . 'image.jpg');
     return $result;
 }
 public function execute()
 {
     $update = $this->getUpdate();
     $message = $this->getMessage();
     $user_id = $message->getFrom()->getId();
     $chat_id = $message->getChat()->getId();
     $message_id = $message->getMessageId();
     $text = $message->getText(true);
     //send chat action
     Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
     $caption = 'Your Id: ' . $message->getFrom()->getId();
     $caption .= "\n" . 'Name: ' . $message->getFrom()->getFirstName() . ' ' . $message->getFrom()->getLastName();
     $caption .= "\n" . 'Username: '******'user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]);
     //Check if the request isOK
     if ($ServerResponse->isOk()) {
         $UserProfilePhoto = $ServerResponse->getResult();
         $totalcount = $UserProfilePhoto->getTotalCount();
     } else {
         $totalcount = 0;
     }
     $data = [];
     $data['chat_id'] = $chat_id;
     $data['reply_to_message_id'] = $message_id;
     if ($totalcount > 0) {
         $photos = $UserProfilePhoto->getPhotos();
         //I pick the latest photo with the hight definition
         $photo = $photos[0][2];
         $file_id = $photo->getFileId();
         $data['photo'] = $file_id;
         $data['caption'] = $caption;
         $result = Request::sendPhoto($data);
         //Download the image pictures
         //Download after send message response to speedup response
         $file_id = $photo->getFileId();
         $ServerResponse = Request::getFile(['file_id' => $file_id]);
         if ($ServerResponse->isOk()) {
             Request::downloadFile($ServerResponse->getResult());
         }
     } else {
         //No Photo just send text
         $data['text'] = $caption;
         $result = Request::sendMessage($data);
     }
     return $result;
 }
 /**
  * Command execute method
  *
  * @return mixed
  * @throws \Longman\TelegramBot\Exception\TelegramException
  */
 public function execute()
 {
     $message = $this->getMessage();
     $from = $message->getFrom();
     $user_id = $from->getId();
     $chat_id = $message->getChat()->getId();
     $message_id = $message->getMessageId();
     $data = ['chat_id' => $chat_id, 'reply_to_message_id' => $message_id];
     //Send chat action
     Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
     $caption = sprintf('Your Id: %d' . PHP_EOL . 'Name: %s %s' . PHP_EOL . 'Username: %s', $user_id, $from->getFirstName(), $from->getLastName(), $from->getUsername());
     //Fetch user profile photo
     $limit = 10;
     $offset = null;
     $response = Request::getUserProfilePhotos(['user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]);
     if ($response->isOk()) {
         /** @var UserProfilePhotos $user_profile_photos */
         $user_profile_photos = $response->getResult();
         if ($user_profile_photos->getTotalCount() > 0) {
             $photos = $user_profile_photos->getPhotos();
             /** @var PhotoSize $photo */
             $photo = $photos[0][2];
             $file_id = $photo->getFileId();
             $data['photo'] = $file_id;
             $data['caption'] = $caption;
             $result = Request::sendPhoto($data);
             //Download the photo after send message response to speedup response
             $response2 = Request::getFile(['file_id' => $file_id]);
             if ($response2->isOk()) {
                 /** @var File $photo_file */
                 $photo_file = $response2->getResult();
                 Request::downloadFile($photo_file);
             }
             return $result;
         }
     }
     //No Photo just send text
     $data['text'] = $caption;
     return Request::sendMessage($data);
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $message = $this->getMessage();
     $chat = $message->getChat();
     $user = $message->getFrom();
     $text = $message->getText(true);
     $chat_id = $chat->getId();
     $user_id = $user->getId();
     //Preparing Respose
     $data = [];
     if ($chat->isGroupChat() || $chat->isSuperGroup()) {
         //reply to message id is applied by default
         //Force reply is applied by default to so can work with privacy on
         $data['reply_markup'] = new ForceReply(['selective' => true]);
     }
     $data['chat_id'] = $chat_id;
     //Conversation start
     $this->conversation = new Conversation($user_id, $chat_id, $this->getName());
     //cache data from the tracking session if any
     if (!isset($this->conversation->notes['state'])) {
         $state = '0';
     } else {
         $state = $this->conversation->notes['state'];
     }
     //state machine
     //entrypoint of the machine state if given by the track
     //Every time the step is achived the track is updated
     switch ($state) {
         case 0:
             if (empty($text)) {
                 $this->conversation->notes['state'] = 0;
                 $this->conversation->update();
                 $data['text'] = 'Type your name:';
                 $data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
                 $result = Request::sendMessage($data);
                 break;
             }
             $this->conversation->notes['name'] = $text;
             $text = '';
             // no break
         // no break
         case 1:
             if (empty($text)) {
                 $this->conversation->notes['state'] = 1;
                 $this->conversation->update();
                 $data['text'] = 'Type your surname:';
                 $result = Request::sendMessage($data);
                 break;
             }
             $this->conversation->notes['surname'] = $text;
             ++$state;
             $text = '';
             // no break
         // no break
         case 2:
             if (empty($text) || !is_numeric($text)) {
                 $this->conversation->notes['state'] = 2;
                 $this->conversation->update();
                 $data['text'] = 'Type your age:';
                 if (!empty($text) && !is_numeric($text)) {
                     $data['text'] = 'Type your age, must be a number';
                 }
                 $result = Request::sendMessage($data);
                 break;
             }
             $this->conversation->notes['age'] = $text;
             $text = '';
             // no break
         // no break
         case 3:
             if (empty($text) || !($text == 'M' || $text == 'F')) {
                 $this->conversation->notes['state'] = 3;
                 $this->conversation->update();
                 $keyboard = [['M', 'F']];
                 $reply_keyboard_markup = new ReplyKeyboardMarkup(['keyboard' => $keyboard, 'resize_keyboard' => true, 'one_time_keyboard' => true, 'selective' => true]);
                 $data['reply_markup'] = $reply_keyboard_markup;
                 $data['text'] = 'Select your gender:';
                 if (!empty($text) && !($text == 'M' || $text == 'F')) {
                     $data['text'] = 'Select your gender, choose a keyboard option:';
                 }
                 $result = Request::sendMessage($data);
                 break;
             }
             $this->conversation->notes['gender'] = $text;
             $text = '';
             // no break
         // no break
         case 4:
             if (is_null($message->getLocation())) {
                 $this->conversation->notes['state'] = 4;
                 $this->conversation->update();
                 $data['reply_markup'] = new ReplyKeyboardMarkup(['keyboard' => [[['text' => 'Share Location', 'request_location' => true]]], 'resize_keyboard' => true, 'one_time_keyboard' => true, 'selective' => true]);
                 $data['text'] = 'Share your location:';
                 $result = Request::sendMessage($data);
                 break;
             }
             $this->conversation->notes['longitude'] = $message->getLocation()->getLongitude();
             $this->conversation->notes['latitude'] = $message->getLocation()->getLatitude();
             // no break
         // no break
         case 5:
             if (is_null($message->getPhoto())) {
                 $this->conversation->notes['state'] = 5;
                 $this->conversation->update();
                 $data['text'] = 'Insert your picture:';
                 $data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
                 $result = Request::sendMessage($data);
                 break;
             }
             $this->conversation->notes['photo_id'] = $message->getPhoto()[0]->getFileId();
             // no break
         // no break
         case 6:
             if (is_null($message->getContact())) {
                 $this->conversation->notes['state'] = 6;
                 $this->conversation->update();
                 $data['text'] = 'Share your contact information:';
                 $data['reply_markup'] = new ReplyKeyboardMarkup(['keyboard' => [[['text' => 'Share Contact', 'request_contact' => true]]], 'resize_keyboard' => true, 'one_time_keyboard' => true, 'selective' => true]);
                 $result = Request::sendMessage($data);
                 break;
             }
             $this->conversation->notes['phone_number'] = $message->getContact()->getPhoneNumber();
             // no break
         // no break
         case 7:
             $this->conversation->update();
             $out_text = '/Survey result:' . "\n";
             unset($this->conversation->notes['state']);
             foreach ($this->conversation->notes as $k => $v) {
                 $out_text .= "\n" . ucfirst($k) . ': ' . $v;
             }
             $data['photo'] = $this->conversation->notes['photo_id'];
             $data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
             $data['caption'] = $out_text;
             $this->conversation->stop();
             $result = Request::sendPhoto($data);
             break;
     }
     return $result;
 }