On a custom UserCommand
getMessage()->getForwardFrom() should return a User but returns null. The reply from Telegram is correct, I can see on the raw update logs that forward_from is defined with the user data, but this method don't return a User but null. As I can't see where can ask this project this questions, I do it by opening a issue...
I didn't change original code or is a complex project yet, it should work, I'm looking at the UserCommand examples to make mine.
Hi @juanjofm
You need to catch the getForwardFrom in the GenericmessageCommand, as it doesn't count as a user command.
Could you explain what you're trying to achieve? And what do you mean by On a custom UserCommand?
what I want to do is that when a message is forwarded to the bot in a private chat with a user and the message from a public group for example and with a command like /getid the bot returns the original user id.
what I mean on a custom UserCommand its just a new command on the Commands folder copying example files, but I get null when I try to get getMessage()->getForwardFrom()
Ok, that should work though.
/getid (from private chat or group)getid command$this->getMessage()->getForwardFrom()->getId()What does your raw update look like?
(Replace the IDs and names to ensure privacy)
Well, for me $this->getMessage()->getForwardFrom() is already null.
raw update like $this->getUpdate()->toJson()? doesn't show "forward_from" and the User object.
But, on raw logs like
Longman\TelegramBot\TelegramLog::initUpdateLog($path . '/' . $BOT_NAME . '_update.log');
it shows "forward_from" and User data is good.
Strange. If the message itself is forwarded, there should be something in ->getForwardFrom().
What if you add this to your GenericmessageCommand.php in execute() method:
$message = $this->getMessage();
return Request::sendMessage([
'chat_id' => $message->getChat()->getId(),
'text' => $message->getForwardFrom() ? $message->getForwardFrom()->getId() : 'not forwarded...',
]);
Then forward a message to your bot in the private chat. Does this work?
says not forwarded...
Hmm, that's very strange. Will need to do some testing to figure this one out.
Any extra information you can give me about your setup?
mmm idk, I know it is weird, is it working for you? It needs a database? Im not using one. But the data Telegram sends is good because you can see it on the log...
Yes, it's working for me, with and without database, with and without webhook.
I don't understand yet why it's not working, even though it's in the raw update...
Do you have PHP 7 too? Idk what to do next, I tried many things already. I can't even find an error that can be the cause of this problem.
Do you have PHP 7 too?
Yes I do. Don't think that's the problem though.
Summoning @jacklul @akalongman @MBoretto
Any ideas?
Alternatively, would it be possible to log into your server that's running the bot?
would it be possible to log into your server that's running the bot?
sorry, thats no possible xD
Can be some parsing error? I mean, if on the logs I get the right json from Telegram but when I do $this->getUpdate()->toJson() the "forward_from" already doesnt exists?
I've just noticed that getUpdate() doesn't seem to be returning the correct value I think.
Something weird is going on, hmmm 馃槙
What I noticed when it comes to DB:
Forward message from private chat:
forward_from = id (correct)forward_from_chat = null (missing)forward_from_message_id = null (correct)Forward message from group chat:
forward_from = id (correct)forward_from_chat = null (missing)forward_from_message_id= null (correct)Forward message from channel:
forward_from = null (correct)forward_from_chat = id (correct)forward_from_message_id = number (correct)I bet $this->getMessage()->getForwardFrom()->getId() will work correctly on messages forwarded from channels.
I met this problem too, and found out that it's a correct behavior, since -

ok, for me forward_from ,forward_from_chat , forward_from_message_id is null forwarding group chats or channel messages, all null.
I'm using this inside class GetidCommand extends UserCommand {
And, sorry, I did this again:
What if you add this to your GenericmessageCommand.php in execute() method:
$message = $this->getMessage();
return Request::sendMessage([
'chat_id' => $message->getChat()->getId(),
'text' => $message->getForwardFrom() ? $message->getForwardFrom()->getId() : 'not forwarded...',
]);Then forward a message to your bot in the private chat. Does this work?
and the result is that it returns empty answer (without command, just forwarding from group or channel).
I have php cache disabled btw.
I tried on other hosting/server and its not working.
@juanjofm Did you manage to resolve this?
Hi @noplanman no, but I stopped trying... Everything else worked well.
i have this issue to. does any idea to solve this?
Is this still actual?
I think it is all about Telegram's recent privacy update. Users can break the link back to them in forwarded messages.
If a user breaks the link, then getForwardFrom() would return null which shouldn't. Because there are already some information about the forwarded message like forward_sender_name, forward_date and text.
Hope the bug will be resolved soon.
@ttvd94 Are you experiencing this problem now?
(This issue is very old, so not sure the initial problem is due to the recent changes)
I don't know how, but I resolved this issue long ago, it was working, sorry for not commenting. But I can't test if it's working right now because I don't develop a Telegram bot since more than a year now.
Let me look for the code and see if I can help with it.
@ttvd94 Are you experiencing this problem now?
@noplanman Yes I am. And I worked it around like I said.
Right, I've had a look at this and this isn't a Telegram problem, but rather a data access problem.
As @ttvd94 pointed out, sometimes the forwarded message doesn't contain the forward_from field but instead has the forward_sender_name and forward_date fields set.
So when trying to access the data, that needs to be checked for:
$message = $this->getMessage();
$forward_from_date = $message->getForwardDate();
$forward_from_name = $message->getForwardSenderName();
if ($forward_from = $message->getForwardFrom() ?: $message->getForwardFromChat()) {
$forward_from_name = $forward_from->tryMention();
}
Most helpful comment
I don't know how, but I resolved this issue long ago, it was working, sorry for not commenting. But I can't test if it's working right now because I don't develop a Telegram bot since more than a year now.
Let me look for the code and see if I can help with it.