Skip to main content

Telegram bot toolkit: named connections, long-polling, send/receive, and a wavi-compatible driver

Project description

teli — Telegram bot toolkit

teli is a Python library and CLI for managing Telegram bots: named connections, async long-polling, message handlers, and a wavi-compatible driver interface for drop-in use alongside WhatsApp automation.

Install

pip install teli
# with user-client support (Telethon):
pip install "teli[user]"

Quick start — CLI

# Register a bot
teli add mybot --token 123456:ABC...

# Discover your chat_id (send /start to the bot, look at output)
teli listen mybot

# Lock down allowed chats
teli update mybot --allow 987654321

# Send a message
teli send mybot 987654321 "Hello from teli!"

Quick start — Python

from teli.bot import Bot

async with Bot.from_connection("mybot") as bot:
    await bot.send_message(987654321, "Hello!")

Long-polling daemon with handlers:

bot = Bot.from_connection("mybot")

@bot.on_command("start")
async def handle_start(msg):
    await bot.send_message(msg["chat"]["id"], "Hi! I'm running on teli.")

await bot.start()
# ... keep alive ...
await bot.stop()

Driver interface (wavi-compatible)

teli.driver exposes the same 7-function interface as wavi_driver, so Pulpo and other orchestrators can treat Telegram and WhatsApp interchangeably:

import teli.driver as td

await td.connect("mybot")                          # start bot
await td.send("mybot", "987654321", "Hola!")       # contact = chat_id
print(await td.status("mybot"))                    # {"daemon_running": True, ...}
print(td.list_session_names())                     # ["mybot"]
await td.stop("mybot")
Function Returns Notes
connect(session, new) {"ok": bool, "qr_page": None, ...} new is a no-op (no QR for bots)
check_updates(session) {"status": "ok", "new_inbound": []} no-op — Telegram is push
send(session, contact, text) {"ok": bool, ...} contact = chat_id
status(session) {"daemon_running": bool, "authenticated": bool, ...}
list_session_names() list[str] sync
stop(session) {"ok": bool, ...}
daemon_running_by_pid(session) bool sync

Named connections

Connections are stored in data/connections.json (or $TELI_DATA_DIR/connections.json):

{
  "connections": [
    {
      "name": "mybot",
      "token": "123456:ABC...",
      "allowed_chats": ["987654321"]
    }
  ]
}

User client (Telethon)

The optional [user] extra enables a user-account listener (receive messages sent to your bot from your own Telegram account):

teli user setup mybot --api-id 12345 --api-hash abc123 --bot-username mybotname
teli user connect mybot
teli user listen mybot

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teli_lib-0.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teli_lib-0.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file teli_lib-0.1.0.tar.gz.

File metadata

  • Download URL: teli_lib-0.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for teli_lib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 03db4d74351448640f498ee1d4d0b6f4399cc2e6a3f212afbef285c5b9646a71
MD5 ea3634b4f58fa882da4f0d7d9c4634ca
BLAKE2b-256 af8d76811e4e54b5b1c5161aaba80596ab24632bb12fb1f09c0bd2ff3a59f19b

See more details on using hashes here.

File details

Details for the file teli_lib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: teli_lib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for teli_lib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20f09d259850fb6f4d12357d32f2de564a09584f6895e2d7256fa7b26117b4d8
MD5 5925465e65bca0a706166c6d200da154
BLAKE2b-256 fd1572e42933609e0a68fa9bef84075f735112524a47baa3ab5d79c5c1cbab2d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page