danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.74k stars 617 forks source link

upload mp4 to group, something error #1494

Closed azhuang321 closed 2 months ago

azhuang321 commented 4 months ago

i just use this method

 $this->tgHandler->messages->sendMedia(
    peer: $_ENV['env_config']['tg']['group_id'],
    media: [
        '_' => 'inputMediaUploadedDocument',
        'file' => $file,
        'attributes' => [
            ['_' => 'documentAttributeAnimated']
        ]
    ],
);
local_bot  | TypeError: danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(): Return value must be of type string, null returned in /app/vendor/danog/madelineproto/src/MTProtoTools/FilesLogic.php:421
local_bot  | Stack trace:
local_bot  | #0 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(294): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(524288, 524288, NULL)
local_bot  | #1 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(323): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(1)
local_bot  | #2 /app/vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
local_bot  | #3 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}(NULL, NULL, Array)
local_bot  | #4 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #5 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #6 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume(NULL)
local_bot  | #7 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
local_bot  | #8 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #9 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #10 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(498): Fiber->start()
local_bot  | #11 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
local_bot  | #12 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #13 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
local_bot  | #14 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #15 /app/vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
local_bot  | #16 /app/vendor/danog/madelineproto/src/Wrappers/Loop.php(107): Amp\Future->await()
local_bot  | #17 /app/vendor/danog/madelineproto/src/AbstractAPI.php(84): danog\MadelineProto\MTProto->loop()
local_bot  | #18 /app/vendor/danog/madelineproto/src/AbstractAPI.php(65): danog\MadelineProto\AbstractAPI->startAndLoopLogic('App\\Core\\SendOp...', true)
local_bot  | #19 /app/vendor/danog/madelineproto/src/EventHandler.php(98): danog\MadelineProto\AbstractAPI->startAndLoopInternal('App\\Core\\SendOp...')
local_bot  | #20 /app/send.php(53): danog\MadelineProto\EventHandler::startAndLoopBot('local_bot.madel...', '********:AAHK...', Object(danog\MadelineProto\Settings))
local_bot  | #21 {main}

app/vendor/danog/madelineproto/src/MTProtoTools/FilesLogic.php:419 image

here need string but app/vendor/amphp/file/src/Driver/UvFile.php:56 return ?String

image

azhuang321 commented 4 months ago

and sometimes like this

image

azhuang321 commented 4 months ago

If the error occurs, i can no longer use the upload function

local_bot  | TypeError: danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(): Return value must be of type string, null returned in /app/vendor/danog/madelineproto/src/MTProtoTools/FilesLogic.php:421
local_bot  | Stack trace:
local_bot  | #0 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(294): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(524288, 524288, NULL)
local_bot  | #1 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(323): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(1)
local_bot  | #2 /app/vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
local_bot  | #3 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}(NULL, NULL, Array)
local_bot  | #4 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #5 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #6 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume(NULL)
local_bot  | #7 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
local_bot  | #8 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #9 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #10 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(498): Fiber->start()
local_bot  | #11 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
local_bot  | #12 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #13 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
local_bot  | #14 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #15 /app/vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
local_bot  | #16 /app/vendor/danog/madelineproto/src/Wrappers/Loop.php(107): Amp\Future->await()
local_bot  | #17 /app/vendor/danog/madelineproto/src/AbstractAPI.php(84): danog\MadelineProto\MTProto->loop()
local_bot  | #18 /app/vendor/danog/madelineproto/src/AbstractAPI.php(65): danog\MadelineProto\AbstractAPI->startAndLoopLogic('App\\Core\\SendOp...', true)
local_bot  | #19 /app/vendor/danog/madelineproto/src/EventHandler.php(98): danog\MadelineProto\AbstractAPI->startAndLoopInternal('App\\Core\\SendOp...')
local_bot  | #20 /app/send.php(53): danog\MadelineProto\EventHandler::startAndLoopBot('local_bot.madel...', '6425359497:AAHK...', Object(danog\MadelineProto\Settings))
local_bot  | #21 {main}TypeError: danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(): Return value must be of type string, null returned in /app/vendor/danog/madelineproto/src/MTProtoTools/FilesLogic.php:421

local_bot  | Stack trace:
local_bot  | #0 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(294): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(1048576, 524288, NULL)
local_bot  | #1 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(323): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(2)
local_bot  | #2 /app/vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
local_bot  | #3 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}(NULL, NULL, Array)
local_bot  | #4 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #5 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #6 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume(NULL)
local_bot  | #7 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
local_bot  | #8 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #9 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #10 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
local_bot  | #11 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
local_bot  | #12 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #13 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
local_bot  | #14 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #15 /app/vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
local_bot  | #16 /app/vendor/danog/madelineproto/src/Wrappers/Loop.php(107): Amp\Future->await()
local_bot  | #17 /app/vendor/danog/madelineproto/src/AbstractAPI.php(84): danog\MadelineProto\MTProto->loop()
local_bot  | #18 /app/vendor/danog/madelineproto/src/AbstractAPI.php(65): danog\MadelineProto\AbstractAPI->startAndLoopLogic('App\\Core\\SendOp...', true)
local_bot  | #19 /app/vendor/danog/madelineproto/src/EventHandler.php(98): danog\MadelineProto\AbstractAPI->startAndLoopInternal('App\\Core\\SendOp...')
local_bot  | #20 /app/send.php(53): danog\MadelineProto\EventHandler::startAndLoopBot('local_bot.madel...', '6425359497:AAHK...', Object(danog\MadelineProto\Settings))
local_bot  | #21 {main}

local_bot  | [2024-03-07 10:39:29] main.error: [2024-03-07 10:39:29] main.ERROR: try again [] []  [] []
local_bot  | TypeError: danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(): Return value must be of type string, null returned in /app/vendor/danog/madelineproto/src/MTProtoTools/FilesLogic.php:421
local_bot  | Stack trace:
local_bot  | #0 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(294): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(524288, 524288, NULL)
local_bot  | #1 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(323): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(1)
local_bot  | #2 /app/vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
local_bot  | #3 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}(NULL, NULL, Array)
local_bot  | #4 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #5 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #6 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume(NULL)
local_bot  | #7 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
local_bot  | #8 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #9 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #10 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
local_bot  | #11 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
local_bot  | #12 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #13 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
local_bot  | #14 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #15 /app/vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
local_bot  | #16 /app/vendor/danog/madelineproto/src/Wrappers/Loop.php(107): Amp\Future->await()
local_bot  | #17 /app/vendor/danog/madelineproto/src/AbstractAPI.php(84): danog\MadelineProto\MTProto->loop()
local_bot  | #18 /app/vendor/danog/madelineproto/src/AbstractAPI.php(65): danog\MadelineProto\AbstractAPI->startAndLoopLogic('App\\Core\\SendOp...', true)
local_bot  | #19 /app/vendor/danog/madelineproto/src/EventHandler.php(98): danog\MadelineProto\AbstractAPI->startAndLoopInternal('App\\Core\\SendOp...')
local_bot  | #20 /app/send.php(53): danog\MadelineProto\EventHandler::startAndLoopBot('local_bot.madel...', '6425359497:AAHK...', Object(danog\MadelineProto\Settings))
local_bot  | #21 {main}
local_bot  | TypeError: danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(): Return value must be of type string, null returned in /app/vendor/danog/madelineproto/src/MTProtoTools/FilesLogic.php:421
local_bot  | Stack trace:
local_bot  | #0 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(294): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(1048576, 524288, NULL)
local_bot  | #1 /app/vendor/danog/madelineproto/src/MTProtoTools/Files.php(323): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}(2)
local_bot  | #2 /app/vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
local_bot  | #3 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}(NULL, NULL, Array)
local_bot  | #4 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #5 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #6 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume(NULL)
local_bot  | #7 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
local_bot  | #8 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
local_bot  | #9 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #10 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
local_bot  | #11 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
local_bot  | #12 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #13 /app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
local_bot  | #14 /app/vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
local_bot  | #15 /app/vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
local_bot  | #16 /app/vendor/danog/madelineproto/src/Wrappers/Loop.php(107): Amp\Future->await()
local_bot  | #17 /app/vendor/danog/madelineproto/src/AbstractAPI.php(84): danog\MadelineProto\MTProto->loop()
local_bot  | #18 /app/vendor/danog/madelineproto/src/AbstractAPI.php(65): danog\MadelineProto\AbstractAPI->startAndLoopLogic('App\\Core\\SendOp...', true)
local_bot  | #19 /app/vendor/danog/madelineproto/src/EventHandler.php(98): danog\MadelineProto\AbstractAPI->startAndLoopInternal('App\\Core\\SendOp...')
local_bot  | #20 /app/send.php(53): danog\MadelineProto\EventHandler::startAndLoopBot('local_bot.madel...', '6425359497:AAHK...', Object(danog\MadelineProto\Settings))
local_bot  | #21 {main}
azhuang321 commented 4 months ago

After the error occurs, my program tries to upload the same file again and continues to report the error, but if I change the name of the file and upload it again it works!

\Amp\async(function ()use($jsonData, $file){
                    \Amp\delay(0.3);
                    try {
                        $this->tgHandler->messages->sendMedia(
                            peer: $_ENV['env_config']['tg']['group_id'],
                            media: [
                                '_' => 'inputMediaUploadedDocument',
                                'file' => $file,
                                'attributes' => [
                                    ['_' => 'documentAttributeAnimated']
                                ]
                            ],
                        );
                    }catch (\Throwable $exception){
                        Logger::getInstance()->error('上传文件出错',['$jsonData'=>$jsonData,'$file'=>$file,'$exception'=>$exception]);
                        \Amp\File\move($file,$_ENV['app_config']['sender']['mp4_path'].'/'.$_ENV['app_config']['sender']['stream_path'].'/'.$jsonData['round_no'].'back.mp4');
                        $this->tgHandler->messages->sendMedia(
                            peer: $_ENV['env_config']['tg']['group_id'],
                            media: [
                                '_' => 'inputMediaUploadedDocument',
                                'file' => $_ENV['app_config']['sender']['mp4_path'].'/'.$_ENV['app_config']['sender']['stream_path'].'/'.$jsonData['round_no'].'back.mp4',
                                'attributes' => [
                                    ['_' => 'documentAttributeAnimated']
                                ]
                            ],
                        );
                    }
                });
azhuang321 commented 4 months ago

Using the latest official docker image

azhuang321 commented 4 months ago

and sometimes like this

image

If the upload completes and the track is unknown, no exception is thrown.

danog commented 2 months ago

Should be all fixed now