driver-telegram icon indicating copy to clipboard operation
driver-telegram copied to clipboard

getSender() returns a user ID instead of a bot ID

Open chimit opened this issue 3 months ago • 0 comments

When the bot receives an incoming message from itself in the Heard middleware, $message->getSender() returns a user Telegram ID instead of a bot Telegram ID.

In the example below, I log messages from bots:

if (data_get($message->getPayload(), 'from.is_bot') === true) {
    Log::debug('Catch bot messages.', [
        'getSender' => $message->getSender(),
        'payload' => $message->getPayload(),
    ]);
}

The incoming message is a bot message. Bot Telegram ID is 2222222222 which is clearly visible in the payload in from.id, but $message->getSender() for some reason returns a different Telegram ID of 11111111 (which is an ID of a user in that chat):

{
    "getSender": 11111111,
    "payload": {
        "message_id": 1328846,
        "from": {
            "id": 2222222222,
            "is_bot": true,
            "first_name": "My bot name",
            "username": "somebotname"
        },
        "chat": {
            "id": -3333333333,
            "title": "Some chat name",
            "type": "group",
            "all_members_are_administrators": true,
            "accepted_gift_types": {
                "unlimited_gifts": false,
                "limited_gifts": false,
                "unique_gifts": false,
                "premium_subscription": false
            }
        },
        "date": 1757250577,
        "text": "Bot response"
    }
}

chimit avatar Sep 07 '25 15:09 chimit