telegram-bot-sdk
telegram-bot-sdk copied to clipboard
sendMediaGroup()
Hi, i want send a group of photos or videos as an album. But your method not working:
$media = [];
$media[] = [
'type' => 'photo',
'media' => InputFile::create('https://example.com/file1.jpg')
];
$media[] = [
'type' => 'photo',
'media' => InputFile::create('https://example.com/file2.jpg')
];
$media[] = [
'type' => 'video',
'media' => InputFile::create('https://example.com/file.mp4')
];
$param = [
'chat_id' => $chat_id,
'media' => $media
];
Telegram::sendMediaGroup($param);
Laravel => 7.9 SDK => 3.0.0
Maybe I made a mistake? Please, help me!
@irazasyed please, answer me
I'll look into this shortly.
@jonnywilliamson Error debug:
A path to local file, a URL, or a file resource should be uploaded using "Telegram\Bot\FileUpload\InputFile::create($pathOrUrlOrResource, $filename)" for "media" property.
But InputFile::create() is used.
We're in the process of a big announcement very very shortly. This issue will be dealt with very soon if you could please just bare with us a little longer. It'll be worth the wait.
Yes, sure. I'm wait :) Thanks!
interested in this as well
i am waiting too :)
Hey. I don’t know if my decision is right, but the following helped me:
$inputMediaPhoto = [ 'type' => 'photo', 'media' => '...', 'parse_mode' => 'HTML' ]; $inputMediaPhoto = \GuzzleHttp\json_encode($inputMediaPhoto);
I hope you get the point.
It does not working for me at all.
@s11e08 tell me please, what did you use for media in your example? Local path, URL or resource?
It does not working for me at all.
@s11e08 tell me please, what did you use for media in your example? Local path, URL or resource?
Я поторопился с ответом в эту тему, извини. Этот способ действительно помог мне с методом editMessageMedia, в качестве media я использовал file_id. Но сейчас проверил на sendMediaGroup и словил ошибку. Надеюсь новая версия библиотеки с фиксом всех багов выйдет скоро
Решил кто то вопрос?
$arr = [];
foreach ($array as $item){
$arr[] = InputMediaPhoto::make([
"media"=> InputFile::create($item->url),
"caption"=>$text,
]);
}
$add = Telegram::sendMediaGroup([
"chat_id"=>$cid,
"media"=>$arr,
]);
И пишет ошибку A path to local file, a URL, or a file resource should be uploaded using "Telegram\Bot\FileUpload\InputFile::create($pathOrUrlOrResource, $filename)" for "media" property.
@irazasyed please, answer me
big announcement very very shortly
@jonnywilliamson any update on this ? i cannot use this method
@foremtehan
Ah its very simple. We are on the cusp of a MASSIVE new release of the SDK. With some INSANE cool features. But Covid-19 managed to cause a lot of delay with lockdowns and people close to us affected.
So we are just trying to deal with that and finish off the documentation.
I can promise you it is worth the wait though.
@foremtehan
Ah its very simple. We are on the cusp of a MASSIVE new release of the SDK. With some INSANE cool features. But Covid-19 managed to cause a lot of delay with lockdowns and people close to us affected.
So we are just trying to deal with that and finish off the documentation.
I can promise you it is worth the wait though.
Its now? Ok?
Please Go to telegram-bot-sdk/src/Traits/Http.php
Edit Line number 343 Replace This code
if ((! $params[$inputFileField] instanceof InputFile) **&&** (is_string($params[$inputFileField]) && ! $this->is_json($params[$inputFileField]))) {
This solved my problem.
On an array, don't use InputFile::create
.
The media
parameter in sendMediaGroup
- serialized JSON array describing the messages to be sent.
$media = array(
array(
'type' => 'photo',
'media' => 'https://example.com/file1.jpg',
'caption' => '<b>Caption</b>',
'parse_mode' => 'HTML'
),
array(
'type' => 'photo',
'media' => 'https://example.com/file2.jpg',
)
);
$response = $telegram->sendMediaGroup([
'chat_id' => $chat_id,
'media' => json_encode($media),
]);
@irazasyed, I think it is necessary to make it possible to pass an array with Telegram\Bot\FileUpload\InputFile::create($pathOrUrlOrResource, $filename) objects to the sendMediaGroup() method. This is a very cool method, but instead now you have to send one file at a time, get "fileId" in the response message, delete the sent message, and then collect a special "media" array to make the send beautiful. If there is already some way to do it right - write, please! If you can fix something locally in the package so that the sendMediaGroup() method works as described, please explain, I'll fix it.
I know for fact this is the current way to do it in latest version.
Telegram::bot()->sendMediaGroup(
[
'chat_id' => '1234567',
'media' => [
InputMediaPhoto::make()->media(InputFile::file('filename1.jpg'),
InputMediaPhoto::make()->media(InputFile::file('filename2.jpg'),
InputMediaPhoto::make()->media(InputFile::file('filename3.jpg'),
InputMediaPhoto::make()->media(InputFile::file('filename4.jpg'),
]
];
InputFile::file()
Are you sure this is a right way? I don't have such method in 3.13.0 version...
$media = array( array( 'type' => 'photo', 'media' => 'https://example.com/file1.jpg', 'caption' => 'Caption', 'parse_mode' => 'HTML' ), array( 'type' => 'photo', 'media' => 'https://example.com/file2.jpg', ) );
$response = $telegram->sendMediaGroup([ 'chat_id' => $chat_id, 'media' => json_encode($media), ]);
this works just change the links to a valid image ,, but it doesn't work in local images from storage it has to be over http,, any help with that??
Я нашел решение, как отправлять локальные файлы при помощи sendMediaGroup. Решение на Laravel, но без него принцип не меняется.
$file = public_path() . "/" . 'storage/messages/45322/images/OQHLV0oEdfYw3PxBzpLkj2XKM16NUgcZK1xkCEc5.png';
$photo = InputFile::create($file);
Telegram::bot('tools')->sendMediaGroup([
'chat_id' => env('TELEGRAM_TOOLS_ID'),
'photo_1' => $photo,
'media' => json_encode([
// HTTP File
InputMediaPhoto::make([
'type' => 'photo',
'media' => 'https://avatars.mds.yandex.net/i?id=69cdc84022bfdb05b07a23f9d28fb7f1f72109ea-7909006-images-thumbs&n=13',
'caption' => '<b>New message</b>',
'parse_mode' => 'HTML',
]),
// By file_id
InputMediaPhoto::make([
'type' => 'photo',
'media' => 'AgACAgIAAxkDAAOsZfvgo10RU6ebLA4yLuRMdZmTll8AArPUMRsF4NhL19kGUqyw358BAAMCAANzAAM0BA',
]),
// By local
InputMediaPhoto::make([
'type' => 'photo',
'media' => 'attach://photo_1',
]),
]),
]);