botman / botman/driver-telegram

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

Open
#130 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
94
Forks
74
PR merge metrics
No merged PRs in 30d

Description

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:

```php
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):

```json
{
"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"
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.