ID from a forwarded message

A forwarded message carries where it came from. A bot that receives it sees the channel's or sender's ID in forward_origin.

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
TOKEN='paste-your-token-here'
curl -s "https://api.telegram.org/bot$TOKEN/getUpdates"

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.