danog / MadelineProto

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

log() expects parameter 1 to be float, string given in PeerHandler.php:44 #755

Closed djnotes closed 4 years ago

djnotes commented 4 years ago

I am trying different ways of sending messages by sending to different types of peers. I get the following error which crashes my app. Seems like a bug in PeerHandler.

New update: 
Array
(
    [_] => updateNewMessage
    [message] => Array
        (
            [_] => message
            [out] => 1
            [id] => 145
            [pts] => 146
            [pts_count] => 1
            [date] => 1579508875
            [media] => Array
                (
                    [_] => messageMediaEmpty
                )

            [user_id] => 1015817111
            [message] => message via user name
            [from_id] => 923639111
            [to_id] => Array
                (
                    [_] => peerUser
                    [user_id] => 1015817111
                )

        )

    [pts] => 146
    [pts_count] => 1
)
Exception:              log() expects parameter 1 to be float, string given in PeerHandler.php:44
Tools:                  Got the following exception within a forked strand started @ Loop:173, trying to rethrow
Tools:                  \danog\MadelineProto\Exception: log() expects parameter 1 to be float, string given in /Users/mhd/src/mdapp/vendor/danog/madelineproto/src/danog/MadelineProto/MTProtoTools/PeerHandler.php:44

TL Trace (YOU ABSOLUTELY MUST READ THE TEXT BELOW):

exceptionErrorHandler(2,"log() expects parameter 1 to be float, string given","\/Users\/mhd\/src\/mdapp\/vendor\/danog\/madelineproto\/src\/danog\/MadelineProto\/MTProtoTools\/PeerHandler.php",44,{"id":""})
PeerHandler.php(44):    log("",10)
PeerHandler.php(443):   toSupergroup("")
PeerHandler.php(498):   getId("channel#-1001262892111")
getInfo("channel#-1001262892111")
Coroutine.php(77):      current()
Coroutine.php(109):     __construct({})
Coroutine.php(161):     __construct({})
Placeholder.php(43):    danog\MadelineProto\{closure}(null,{"peer":"channel#-1001262892111","message":"message via tg-cli style (channel)"})
Coroutine.php(178):     onResolve({})
Coroutine.php(109):     __construct({})
Coroutine.php(109):     __construct({})
Coroutine.php(161):     __construct({})
Placeholder.php(43):    danog\MadelineProto\{closure}(null,{"_":"config","phonecalls_enabled":true,"default_p2p_contacts":true,"preload_featured_stickers":false,"ignore_phone_entities":false,"revoke_pm_inbox":true,"blocked_mode":false,"pfs_enabled":false,"date":1579507449,"expires":1579511523,"test_mode":false,"this_dc":5,"dc_txt_domain_name":"apv3.stel.com","chat_size_max":200,"megagroup_size_max":200000,"forwarded_count_max":100,"online_update_period_ms":210000,"offline_blur_timeout_ms":5000,"offline_idle_timeout_ms":30000,"online_cloud_timeout_ms":300000,"notify_cloud_delay_ms":30000,"notify_default_delay_ms":1500,"push_chat_period_ms":60000,"push_chat_limit":2,"saved_gifs_limit":200,"edit_time_limit":172800,"revoke_time_limit":172800,"revoke_pm_time_limit":172800,"rating_e_decay":2419200,"stickers_recent_limit":200,"stickers_faved_limit":5,"channels_read_media_period":604800,PeriodicLoop, my_bot:           Got signal in call check, exiting
PeriodicLoop, my_bot:          Got signal in serialize, exiting
PeriodicLoop, my_bot:          Got signal in phone config, exiting
PeriodicLoop, my_bot:          Got signal in config, exiting
PeriodicLoop, my_bot:          Got signal in TOS, exiting
DataCenterConnection, my_bot:  Disconnecting from shared DC 2
Connection, my_bot:            Disconnecting from DC 2.0
DataCenterConnection, my_bot:  Backed up  from DC 2.0
Connection, my_bot:            Disconnected from DC 2.0
DataCenterConnection, my_bot:  Backed up 0, added to 0 existing messages) from DC 2
DataCenterConnection, my_bot:  Disconnecting from shared DC 1
Connection, my_bot:            Disconnecting from DC 1.0
DataCenterConnection, my_bot:  Backed up  from DC 1.0
Connection, my_bot:            Disconnected from DC 1.0
DataCenterConnection, my_bot:  Backed up 0, added to 0 existing messages) from DC 1
DataCenterConnection, my_bot:  Disconnecting from shared DC 2_media
PeriodicLoop, my_bot:          Got signal in robin loop DC 2_media, exiting
Connection, my_bot:            Disconnecting from DC 2_media.0
DataCenterConnection, my_bot:  Backed up  from DC 2_media.0
Connection, my_bot:            Disconnected from DC 2_media.0
Connection, my_bot:            Disconnecting from DC 2_media.1
DataCenterConnection, my_bot:  Backed up  from DC 2_media.1
Connection, my_bot:            Disconnected from DC 2_media.1
Connection, my_bot:            Disconnecting from DC 2_media.2
DataCenterConnection, my_bot:  Backed up  from DC 2_media.2
Connection, my_bot:            Disconnected from DC 2_media.2
Connection, my_bot:            Disconnecting from DC 2_media.3
DataCenterConnection, my_bot:  Backed up  from DC 2_media.3
Connection, my_bot:            Disconnected from DC 2_media.3
Connection, my_bot:            Disconnecting from DC 2_media.4
DataCenterConnection, my_bot:  Backed up  from DC 2_media.4
Connection, my_bot:            Disconnected from DC 2_media.4
DataCenterConnection, my_bot:  Backed up 0, added to 0 existing messages) from DC 2_media
DataCenterConnection, my_bot:  Disconnecting from shared DC 3
Connection, my_bot:            Disconnecting from DC 3.0
DataCenterConnection, my_bot:  Backed up  from DC 3.0
Connection, my_bot:            Disconnected from DC 3.0
DataCenterConnection, my_bot:  Backed up 0, added to 0 existing messages) from DC 3
DataCenterConnection, my_bot:  Disconnecting from shared DC 4
Connection, my_bot:            Disconnecting from DC 4.0
DataCenterConnection, my_bot:  Backed up  from DC 4.0
Connection, my_bot:            Disconnected from DC 4.0
DataCenterConnection, my_bot:  Backed up 0, added to 0 existing messages) from DC 4
DataCenterConnection, my_bot:  Disconnecting from shared DC 4_media
PeriodicLoop, my_bot:          Got signal in robin loop DC 4_media, exiting
Connection, my_bot:            Disconnecting from DC 4_media.0
DataCenterConnection, my_bot:  Backed up  from DC 4_media.0
Connection, my_bot:            Disconnected from DC 4_media.0
Connection, my_bot:            Disconnecting from DC 4_media.1
DataCenterConnection, my_bot:  Backed up  from DC 4_media.1
Connection, my_bot:            Disconnected from DC 4_media.1
Connection, my_bot:            Disconnecting from DC 4_media.2
DataCenterConnection, my_bot:  Backed up  from DC 4_media.2
Connection, my_bot:            Disconnected from DC 4_media.2
Connection, my_bot:            Disconnecting from DC 4_media.3
DataCenterConnection, my_bot:  Backed up  from DC 4_media.3
Connection, my_bot:            Disconnected from DC 4_media.3
Connection, my_bot:            Disconnecting from DC 4_media.4
DataCenterConnection, my_bot:  Backed up  from DC 4_media.4
Connection, my_bot:            Disconnected from DC 4_media.4
DataCenterConnection, my_bot:  Backed up 0, added to 0 existing messages) from DC 4_media
DataCenterConnection, my_bot:  Disconnecting from shared DC 5
Connection, my_bot:            Disconnecting from DC 5.0
DataCenterConnection, my_bot:  Backed up  from DC 5.0
Connection, my_bot:            Disconnected from DC 5.0
DataCenterConnection, my_bot:  Backed up 0, added to 0 existing messages) from DC 5
MTProto, my_bot:          

My code resulting in the crash is as follows:

                        $id = $update['message']['from_id'];
                        yield $this->messages->sendMessage(['peer' => $id , 'message' => 'message via user id']);
                        yield $this->messages->sendMessage(['peer' => '@my_id' , 'message' => 'message via user name']);
                        yield $this->messages->sendMessage(['peer' =>  'https://t.me/channel_id', 'message' => 'message via link']);
                        // yield $this->messages->sendMessage(['peer' => 'https://t.me/joinchat/BkEqFQ8TpsKipG7d2H2AAA' , 'message' => 'message via user name']);
                        yield $this->messages->sendMessage(['peer' => "channel#-1001262892111" , 'message' => 'message via tg-cli style (channel)']);
                        yield $this->messages->sendMessage(['peer' => "user#$id", 'message' => 'message via tg-cli style (user)']);
                        yield $this->messages->sendMessage(['peer' => "chat#252946555", 'message' => 'message via tg-cli style (chat)']);

I am not sure if I am ever sending a message to a super group with this code, but the method toSuperGroup() is called anyways.

danog commented 4 years ago

channel#-1001262892111 is not a valid combination, use -1001262892111 or channel#1262892111, instead. Anyway, you should never be doing this manual kind of conversion, just pass the peer and you're done.

djnotes commented 4 years ago

Why do update objects sometimes give -some_long_id and other times some_short_id? What is the difference between tg-cli style IDs and bot api style IDs? On Jan 20, 2020 15:01, Daniil Gentili notifications@github.com wrote:channel#-1001262892111 is not a valid combination, use -1001262892111 or channel#1262892111, instead. Anyway, you should never be doing this manual kind of conversion, just pass the peer and you're done.