• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Send and receive files from the Telegram bot

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
The next important feature that needed to be implemented was the ability to send photos.

Sending photos in a Telegram bot with

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.




There are three ways to send a photo.

Send via link


For example, we have a picture that can be downloaded from the address

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

. Using the link, the file can be sent to the bot.
Example:


$link = '

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



Bot::new()->photo($link)->send();
Send photo contents


In this method, our file does not need to be accessible via a link. Our file exists somewhere on the server and can be sent using Bot::inputFile.

Example:


$file = Bot::inputFile(__DIR__.'/assets/test.png');
Bot::new()->photo($file)->send();

How to add a caption to a photo?


Bot::new()->photo($file)->caption('Hello caption ?')->send();
Receive a photo from the client in the bot


To find out whether the type of message the client sent to the bot is a photo or not, we can do the following:


if(Bot::message()->type() == Message::TYPE_PHOTO){
// ...
}

If the client has sent a photo, we can access its information through the photo method.

Telegram sends us a file_id which contains a unuque identifier and if you save this identifier you can send the photo later without having to upload it again (

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

)


if(Bot::message()->type() == Message::TYPE_PHOTO){

$file_id = Bot::message()->photo()->first()->fileId();

}

Telegram sends us an array of images of different sizes, the first one being the lowest and the last one being the highest resolution and size.
In the example above, we received the first one. Other methods are also available.

MethodDescription
firstReturns the first value
lastReterns the last value
countNumber of arrays
indexOfReturns the value based on its index.
asArrayReturns the entire array in its entirety.

If the photo has a caption, you can get it like this:


$caption = Bot::message()->caption();

If there is no caption, it returns null.

Now, if you have access to the file_id, you can resend that image in the same way as explained:



$file_id = $file_id = Bot::message()->photo()->last()->fileId();

bot::new()->photo($file_id)->caption('New Caption ...')->send();


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу