danog / MadelineProto

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

Some public channels return (400) (CHANNEL_INVALID) error! #1443

Closed mohamadx closed 7 months ago

mohamadx commented 7 months ago

Hi everyone

I'm using this code for getting last posts of public channels:

$MadelineProto->start();

$channel = $MadelineProto->getInfo('@telegram');

$messages = $MadelineProto->messages->getHistory(
    peer: $channel['InputPeer'], 
    offset_id: 0, 
    limit: 20, 
    offset_date: 0, 
    add_offset: 0, 
    max_id: 0,
    min_id: 1,
    hash: $channel['Chat']['access_hash']
);

print_r(
    $messages['messages'][0]
);

but it doesn't work for some public channel like @tasnimnews ( https://t.me/s/tasnimnews ) I used my phone number for login and I joined this channel in my account it's not on my block list. why I receive this error?!

the complete error :

Exception:          Telegram returned an RPC error: The provided channel is invalid (400) (CHANNEL_INVALID), caused by /Users/.../Desktop/telegram/vendor/danog/madelineproto/src/MTProtoSession/ResponseHandler.php:382
Revision: 8.0.0-beta166

TL trace:
['messages.getHistory']
WrappedFuture.php(59):  danog\MadelineProto\MTProtoSession\{closure}()
CallHandler.php(99):    await()
CallHandler.php(45):    methodCallAsyncRead("messages.getHistory",{"peer":{"_":"inputPeerChannel","channel_id":1001976122,"access_hash":6339374532108886914,"min":true},"limit":20,"hash":6339374532108886914})
Server.php(243):        methodCallAsyncRead("messages.getHistory",{"peer":{"_":"inputPeerChannel","channel_id":1001976122,"access_hash":6339374532108886914,"min":true},"limit":20,"hash":6339374532108886914},null)
AbstractDriver.php(423):    clientRequest({},4,["methodCallAsyncRead",["messages.getHistory",{"peer":{"_":"inputPeerChannel","channel_id":1001976122,"access_hash":6339374532108886914,"min":true},"limit":20,"hash":6339374532108886914},null]])
AbstractDriver.php(614):    invokeMicrotasks()
Revolt\EventLoop\Internal\{closure}()
DriverSuspension.php(61):   resume({})
AbstractDriver.php(423):    Revolt\EventLoop\Internal\{closure}()
AbstractDriver.php(614):    invokeMicrotasks()
Revolt\EventLoop\Internal\{closure}()
DriverSuspension.php(61):   resume()
AbstractDriver.php(423):    Revolt\EventLoop\Internal\{closure}()
AbstractDriver.php(614):    invokeMicrotasks()
Revolt\EventLoop\Internal\{closure}()
AbstractDriver.php(495):    resume()
AbstractDriver.php(551):    invokeCallbacks()
Revolt\EventLoop\Internal\{closure}()
AbstractDriver.php(93): resume()
DriverSuspension.php(114):  Revolt\EventLoop\Internal\{closure}()
Future.php(251):        suspend()
Server.php(165):        await()
entry.php(119):         waitShutdown()
entry.php(154):         danog\MadelineProto\Ipc\Runner\{closure}()
mohamadx commented 7 months ago

This problem happened for some channels that I subscribed to I don't know what happening but when I leave / join again to that channels, problem solved

danog commented 7 months ago

You must not extract the access hash manually, your code should look like this:

$messages = $MadelineProto->messages->getHistory(
    peer: '@username', 
    limit: 20,
);