You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But in the Conversation class, if I send several photos in one message, I can only get one - the first one.
As far as I understand, even if several photos were sent in one message, they are actually still uploaded in separate messages and it turns out that 1 photo = 1 message.
I extended the Conversation class and created a getPhoto method, which receives the photo and saves its URL in a property:
/**
* Get photo
*
* @param Nutgram $bot
* @return boolean
*/
public function getPhoto(Nutgram $bot):bool
{
// Getting the message type
$MessageType = $bot->message()->getType()->value;
// Check if the message is a photo
if( $MessageType !== MessageType::PHOTO->value){
return false;
}
$photo = end($bot->message()->photo);
// Getting a photo file
$file = $bot->getFile($photo->file_id);
// Get the url of the photo
$photoUrl = $file->url();
// Write the url of the photo to the property for storage
$this->userData['photos'][] = $photoUrl;
return true;
}
I call this method on the step that follows after the user uploads photos:
/**
* Step photos
*
* @param Nutgram $bot
* @return void
*/
public function stepPhotos(Nutgram $bot):void
{
$this->userData['location'] = $this->getLocation($bot);
$bot->sendMessage('Upload a photo of the salon');
$this->next('stepEmail');
}
/**
* Step email
*
* @param Nutgram $bot
* @return void
*/
public function stepEmail(Nutgram $bot):void
{
$photo = $this->getPhoto($bot);
if(!$photo){
$this->stepPhotos($bot);
return;
}
$bot->sendMessage('Enter the email address of the salon');
$this->next('stepPhone');
}
As a result, I only get the first photo, out of all to have been sent in one message.
Please tell me what I'm missing and where I made a mistake, and is it possible at all to receive all the photos that were sent in one message in the Conversation class?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello!
Thank you for developing such a wonderful library! :)
Please tell me, is it possible in the Conversation class to receive multiple photos sent by the user in one message?
I know that in the base Nutgram class, you can get all the photos sent in one message using handlers:
onMessageType:
$bot->onMessageType(MessageType::PHOTO, function (Nutgram $bot) {
$photo = end($bot->message()->photo);
$bot->getFile($photo->file_id)?->save('./');
});
onPhoto:
$bot->onMessageType(MessageType::PHOTO, function (Nutgram $bot) {
$photo = end($bot->message()->photo);
$bot->getFile($photo->file_id)?->save('./');
$bot->sendMessage('Photo saved!');
});
But in the Conversation class, if I send several photos in one message, I can only get one - the first one.
As far as I understand, even if several photos were sent in one message, they are actually still uploaded in separate messages and it turns out that 1 photo = 1 message.
I extended the Conversation class and created a getPhoto method, which receives the photo and saves its URL in a property:
I call this method on the step that follows after the user uploads photos:
As a result, I only get the first photo, out of all to have been sent in one message.
Please tell me what I'm missing and where I made a mistake, and is it possible at all to receive all the photos that were sent in one message in the Conversation class?
Beta Was this translation helpful? Give feedback.
All reactions