Five-Minute Quickstart
Set MINIPROTO_API_ID, MINIPROTO_API_HASH and MINIPROTO_BOT_TOKEN as shown in Installation. This example connects to Telegram using a session kept in memory.
import os
from miniproto import Client, ClientConfig, InMemorySessionStorage, event_loop
async def main() -> None: config = ClientConfig( api_id=int(os.environ["MINIPROTO_API_ID"]), api_hash=os.environ["MINIPROTO_API_HASH"], session_storage=InMemorySessionStorage(), ) async with Client(config) as client: await client.sign_in_bot(os.environ["MINIPROTO_BOT_TOKEN"]) me = await client.get_me() print(f"authorized bot ID: {me.id}")
event_loop.run(main())On success, the program prints the bot’s Telegram ID. Leaving the async with block closes the connection and discards the in-memory session. To keep authorization across restarts, follow Phone, Bot and 2FA Authorization. To post from this bot, see First High-Level Operation.