ID from a forwarded message

Get a channel ID or a user ID from a forwarded message: forward a post to a bot and read forward_origin in the update. This works for private channels you can read but not link to, and the inspector below shows when Telegram hides the sender.

Steps

  1. Forward the message to a bot

    Any bot you created with @BotFather. Open a private chat with it and forward the message there.

  2. Call getUpdates

    With your own bot: run the command shown in the inspector.

  3. Read forward_origin

    type channel → chat.id is the channel. type user → sender_user.id is the person. type chat → sender_chat.id. type hidden_user → no ID exists.

The four origin types

channelchat.id, message_idA post from a channel. Also gives the original message's ID.
usersender_user.idA person who allows linking their account in forwards.
chatsender_chat.idSent on behalf of a group, e.g. by an anonymous admin.
hidden_usersender_user_name onlyThe sender hides their account. No ID is transmitted.

Source: Bot API, MessageOrigin.

getUpdates inspector

Paste what getUpdates returned (or a single update or message). Every ID in it is listed. Read in your browser — nothing is uploaded.

1 · Fetch your bot's updates in a terminal
# in your own terminal: $TOKEN is your bot's token, which never goes into this page
curl -s "https://api.telegram.org/bot$TOKEN/getUpdates"

When forwarding is the right method

The public lookup needs an @username. Forwarding works without one. Any post you can see in Telegram can be forwarded to a bot, and the update the bot receives says where the post came from. That makes it the simplest way to get the ID of a private channel you are subscribed to, without adding a bot to it.

A worked example

You read a private channel and want its ID for an alert bot. Open the channel, forward any post to your own bot, call getUpdates and paste the JSON into the inspector. forward_origin.type is channel, and forward_origin.chat.id is a number starting with -100: that is the channel’s chat_id. forward_origin.message_id is the original post’s ID inside that channel.

When there is no ID

People can hide their account in forwards (Settings, Privacy, Forwarded messages). Their messages then arrive as hidden_user with only a display name, for every bot alike. No method recovers the ID from such a forward. Ask the person to write to the bot directly instead; then message.from.id is theirs.

Forwarding versus copying

Some clients offer “forward without author” or the bot receives a copy made with copyMessage. A copy carries no origin at all. Use a normal forward.

Old field names

Bot API 7.0 replaced forward_from and forward_from_chat with forward_origin. An old library may still show the old names, or drop the field. The inspector reads both.

FAQ

How do I get a channel ID from a forwarded message?

Forward any post of the channel to a bot you control and call getUpdates. message.forward_origin.chat.id is the channel's ID; this also works for private channels you are a member of.

Why is there no ID for a forwarded user?

The person has set “Forwarded messages” to hide their account. Telegram then sends forward_origin of type hidden_user with only the display name — there is no ID to read, for any bot.

What happened to forward_from and forward_from_chat?

Bot API 7.0 replaced them with forward_origin, an object whose type is user, hidden_user, chat or channel. Older libraries may still show the old field names; the inspector reads both.

Does forwarding work for groups?

A message written in a group by a person is forwarded as coming from that person, so you get the user's ID (or a hidden user). You get a group's ID only for messages sent on behalf of the group itself, such as anonymous admin posts.

Can I get the ID of a private channel without being admin?

Yes, if you can read it: forward one of its posts to a bot you control and read forward_origin.chat.id. You do not have to add the bot to the channel.

Why does forward_origin show type chat?

The message was sent on behalf of a group, for example by an anonymous admin. sender_chat.id is the group’s ID.