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

# Client and helpers

> Configure TelegramAPI and query bot, chat, and file information.

## Constructor

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

telegram = TelegramAPI(
    'YOUR_BOT_TOKEN',
    session = None,
    timeout = 30,
    upload_timeout = 120,
    max_flood_retries = 3
)
```

| Parameter | Default | Description |
| - | - | - |
| `token` | required | Bot token from [@BotFather](https://telegram.me/BotFather) |
| `session` | `None` | Custom `requests.Session`; the client closes only sessions it created |
| `timeout` | `(10, 30)` | Timeout for normal API calls |
| `upload_timeout` | `(10, 120)` | Timeout for requests that contain files |
| `max_flood_retries` | `3` | Automatic retries for rate-limited requests |

`timeout` applies to normal API calls. `upload_timeout` applies to requests that contain files. Both accept a number of seconds or a `(connect, read)` tuple.

## Session ownership

Pass a custom session when you need shared connection settings:

```python theme={null}
import requests

session = requests.Session()
telegram = TelegramAPI('YOUR_BOT_TOKEN', session = session)
```

The client does not close a session that you pass in. It does close the session it creates itself. Use the context manager form, or call `close()` when you are done:

```python theme={null}
with TelegramAPI('YOUR_BOT_TOKEN') as telegram:
    telegram.send_message(chat_id = 'YOUR_CHAT_ID', text = 'Hi!')

telegram = TelegramAPI('YOUR_BOT_TOKEN')
telegram.close()
```

## Bot, chat, and file information

```python theme={null}
me = telegram.get_me()
print(me['id'], me['username'])

chat = telegram.get_chat(chat_id = '@example_channel')
print(chat['title'])

file_info = telegram.get_file(file_id = message.document.file_id)
print(file_info['file_path'])
```

`get_file()` returns Telegram's raw file metadata. In most cases you do not need to call it directly; use [`download_attachment()`](https://n-a-818b4087.mintlify.site/guides/downloads).

## Default download directory

`current_directory` controls where downloads are saved when `download_path` is omitted:

```python theme={null}
telegram.current_directory = '/path/to/downloads/'
```

## Helpers

```python theme={null}
telegram.is_url('https://example.com')  # True
telegram.is_url('/path/to/file')        # False

print(telegram.convert_timestamp(message.date))
# Output: '23/02/2022 10:19:00'
```

`convert_timestamp()` accepts the Unix timestamp fields on parsed messages. It returns a formatted date string.


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