> ## 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.

# Quickstart

> Install the client, create a bot, and send your first message.

## Prerequisites

* Python 3.10 or newer
* A Telegram bot token from [@BotFather](https://telegram.me/BotFather)
* The numeric ID of the chat where you want to send messages

## Install

From a checkout of the repository:

```bash theme={null}
git clone https://github.com/mishka/TelegramAPI.git
cd TelegramAPI
python -m pip install .
```

For development, install the test and lint tools as well:

```bash theme={null}
python -m pip install -e ".[dev]"
```

`requests` is installed automatically.

## Create a bot

1. Open [@BotFather](https://telegram.me/BotFather) in Telegram.
2. Send `/newbot` and follow the prompts.
3. Copy the token BotFather returns.

Keep the token private. Anyone with the token can control the bot.

## Find your chat ID

Send `/my_id` to [@get\_id\_bot](https://telegram.me/get_id_bot). It replies with your numeric user ID.

You can also send a message to your bot and inspect the raw updates:

```text theme={null}
https://api.telegram.org/YOUR_TOKEN/getUpdates
```

Look for `message.chat.id` in the response.

## Send a message

```python theme={null}
from TelegramAPI import TelegramAPI

telegram = TelegramAPI('YOUR_BOT_TOKEN')

telegram.send_message(
    chat_id = 'YOUR_CHAT_ID',
    text = 'Hello from TelegramAPI!'
)
```

The client can also be used as a context manager, which closes its HTTP session when the block exits:

```python theme={null}
from TelegramAPI import TelegramAPI

with TelegramAPI('YOUR_BOT_TOKEN') as telegram:
    telegram.send_message(chat_id = 'YOUR_CHAT_ID', text = 'Hello!')
```

## Receive updates

`poll_updates()` yields parsed `Message` objects and keeps polling until you stop the loop:

```python theme={null}
from TelegramAPI import TelegramAPI

with TelegramAPI('YOUR_BOT_TOKEN') as telegram:
    for message in telegram.poll_updates(allowed_updates = ['message']):
        print(message.chat_id, message.text)

        if message.text == '/ping':
            telegram.send_message(chat_id = message.chat_id, text = 'pong')
```

> [!TIP]
>
> Long polling is enabled by default. Telegram holds the request open for up to 30 seconds, so the loop does not need a busy wait.

## Next steps

* [Send messages and keyboards](https://n-a-818b4087.mintlify.site/guides/messages.md)
* [Send photos, videos, audio, and documents](https://n-a-818b4087.mintlify.site/guides/media.md)
* [Work with updates and parsed data](https://n-a-818b4087.mintlify.site/guides/updates.md)
* [Download attachments](https://n-a-818b4087.mintlify.site/guides/downloads.md)


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