> ## Documentation Index
> Fetch the complete documentation index at: https://n-a-818b4087.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Updates and polling

> Receive raw updates or iterate over parsed Message objects.

## Raw updates

`get_updates()` returns Telegram's raw update dictionaries and advances the internal offset for you:

```python theme={null}
updates = telegram.get_updates(
    long_poll_timeout = 30,
    allowed_updates = ['message', 'callback_query'],
    limit = 100
)

for update in updates:
    print(f'Update ID: {update["update_id"]}')
```

## Parsed updates

`poll_updates()` is a generator that parses each update into a `Message` object:

```python theme={null}
for message in telegram.poll_updates(
    polling_interval = 1,
    long_poll_timeout = 30,
    max_retries = None,
    allowed_updates = ['message']
):
    print(f'Update ID: {message.update_id}')
    print(f'Message ID: {message.message_id}')
    print(f'Update type: {message.update_type}')
    print(f'Text: {message.text}')
```

With long polling enabled (the default), Telegram holds the request for up to `long_poll_timeout` seconds, so `polling_interval` is only used when `long_poll_timeout = 0`.

`max_retries` limits consecutive network or server failures. Permanent errors such as an invalid token or a webhook conflict are raised immediately.

## Parsed message data

Common fields are available directly on the `Message` object:

| Field | Description |
| - | - |
| `update_id` | Telegram update identifier |
| `message_id` | Message identifier |
| `update_type` | Type of update, such as `message` or `callback_query` |
| `from_id`, `from_first_name`, `from_username`, `from_is_bot` | Sender details |
| `chat_id`, `chat_type`, `chat_first_name`, `chat_username` | Chat details |
| `date`, `edit_date` | Unix timestamps |
| `text`, `caption` | Message text or media caption |
| `media_group_id` | Album identifier when the message belongs to a media group |
| `raw_message` | The original Telegram message dictionary |
| `raw` | The original Telegram update dictionary |

Media properties such as `message.photo`, `message.document`, `message.audio`, `message.video`, `message.voice`, `message.animation`, `message.sticker`, `message.video_note`, `message.contact`, and `message.location` are parsed objects with the fields Telegram provides.

```python theme={null}
for message in telegram.poll_updates():
    print(f'From ID: {message.from_id}')
    print(f'Chat ID: {message.chat_id}')
    print(f'Date: {telegram.convert_timestamp(message.date)}')
    print(f'Text: {message.text}')
    print(f'Caption: {message.caption}')
    print(f'Media group ID: {message.media_group_id}')

    if message.sticker:
        print(f'Sticker: {message.sticker.file_id}')
        print(f'Emoji: {message.sticker.emoji}')

    if message.document:
        print(f'Document: {message.document.file_name}')
        print(f'Size: {message.document.file_size}')

    if message.location:
        print(f'Location: {message.location.latitude}, {message.location.longitude}')

    print(message.raw_message)
    print(message.raw)
```

## Non-message updates

Updates such as callback queries are also returned as `Message` objects. Their `update_type` is set, and the untouched update is available in `.raw`:

```python theme={null}
for message in telegram.poll_updates(allowed_updates = ['callback_query']):
    callback = message.raw.get('callback_query')
    if callback:
        print(callback['id'], callback.get('data'))
```

## Backwards-compatible aliases

Older names are still available:

* `message.id` is `message.message_id`
* `sticker.type` is `sticker.sticker_type`
* `video.unique_id` is `video.file_unique_id`
* `video.video_size` is `video.file_size`

> [!NOTE]
>
> A webhook and `poll_updates()` cannot be used at the same time. Call `delete_webhook()` before switching back to polling.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.