1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 22:51:11 +01:00

Fix usage of inputMediaPhotoExternal and inputMediaDocumentExternal in sendMultiMedia

This commit is contained in:
Daniil Gentili 2023-08-03 20:52:48 +02:00
parent 373824c620
commit 17e84ec003
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 25 additions and 0 deletions

View File

@ -35,6 +35,7 @@ use danog\MadelineProto\Stream\ConnectionContext;
use danog\MadelineProto\Stream\MTProtoBufferInterface;
use danog\MadelineProto\Stream\MTProtoTransport\HttpsStream;
use danog\MadelineProto\Stream\MTProtoTransport\HttpStream;
use danog\MadelineProto\TL\Conversion\Extension;
use Webmozart\Assert\Assert;
/**
@ -332,11 +333,27 @@ final class Connection
if (isset($arguments['message']['reply_to_msg_id'])) {
$arguments['message']['reply_to_random_id'] = $arguments['message']['reply_to_msg_id'];
}
} elseif ($method === 'messages.uploadMedia' || $method === 'messages.sendMedia') {
if (is_array($arguments['media'])) {
if ($arguments['media']['_'] === 'inputMediaPhotoExternal') {
$arguments['media']['_'] = 'inputMediaUploadedPhoto';
$arguments['media']['file'] = new RemoteUrl($arguments['media']['url']);
} elseif ($arguments['media']['_'] === 'inputMediaDocumentExternal') {
$arguments['media']['_'] = 'inputMediaUploadedDocument';
$arguments['media']['file'] = new RemoteUrl($arguments['media']['url']);
$arguments['media']['mime_type'] = Extension::getMimeFromExtension(
pathinfo($arguments['media']['url'], PATHINFO_EXTENSION),
'application/octet-stream'
);
}
}
} elseif ($method === 'messages.sendMultiMedia') {
foreach ($arguments['multi_media'] as &$singleMedia) {
if (\is_string($singleMedia['media'])
|| $singleMedia['media']['_'] === 'inputMediaUploadedPhoto'
|| $singleMedia['media']['_'] === 'inputMediaUploadedDocument'
|| $singleMedia['media']['_'] === 'inputMediaPhotoExternal'
|| $singleMedia['media']['_'] === 'inputMediaDocumentExternal'
) {
$singleMedia['media'] = $this->methodCallAsyncRead('messages.uploadMedia', ['peer' => $arguments['peer'], 'media' => $singleMedia['media']]);
}

View File

@ -50,6 +50,8 @@ echo "Latest tag: $TAG"
# Clean up
madelinePath=$PWD
dd if=/dev/random of=tests/60 bs=1M count=60
k()
{
while :; do pkill -f "MadelineProto worker $(pwd)/tests/../testing.madeline" || break && sleep 1; done

View File

@ -263,6 +263,9 @@ $MadelineProto->loop(function () use ($MadelineProto) {
// Image
$media['photo'] = ['_' => 'inputMediaUploadedPhoto', 'file' => __DIR__.'/faust.jpg'];
// Image by URL
$media['photo'] = ['_' => 'inputMediaPhotoExternal', 'url' => 'https://github.com/danog/MadelineProto/raw/v8/tests/faust.jpg'];
// Sticker
$media['sticker'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/lel.webp', 'attributes' => [['_' => 'documentAttributeSticker', 'alt' => 'LEL']]];
@ -278,6 +281,9 @@ $MadelineProto->loop(function () use ($MadelineProto) {
// Document
$media['document'] = ['_' => 'inputMediaUploadedDocument', 'file' => __DIR__.'/60', 'mime_type' => 'magic/magic', 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'magic.magic']]];
// Document by URL
$media['document'] = ['_' => 'inputMediaUploadedDocument', 'url' => 'https://github.com/danog/MadelineProto/raw/v8/tests/60'];
$message = 'yay '.PHP_VERSION_ID;
$mention = yield $MadelineProto->getInfo(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
$mention = $mention['user_id']; // Selects only the numeric user id