A Telegram-style Python SDK for the Luffa Bot API
Project description
Luffa Python SDK
A Telegram-style Python SDK for the Luffa Bot API. Build bots in minutes with a clean decorator-based interface.
Install
pip install luffa
With .env support:
pip install luffa[dotenv]
Quickstart
import os
from dotenv import load_dotenv
from luffa import LuffaBot
load_dotenv()
bot = LuffaBot(secret=os.getenv("BOT_SECRET"))
@bot.command("ping")
async def ping(msg):
await msg.reply("Pong!")
@bot.on_message()
async def echo(msg):
await msg.reply(f"You said: {msg.text}")
bot.run()
That's it. Save as bot.py, add your BOT_SECRET to .env, and run it.
Getting Your Bot Secret
- Open robot.luffa.im and scan the QR code with Luffa
- Click New Bot to create a bot
- Copy the SecretKey — that's your
BOT_SECRET - Add the bot as a friend in Luffa to start chatting
Features
Commands
Register command handlers with the @bot.command() decorator. The leading / is handled automatically. Arguments are parsed into msg.args.
@bot.command("greet")
async def greet(msg):
name = msg.args[0] if msg.args else "stranger"
await msg.reply(f"Hello, {name}!")
User sends /greet World → bot replies Hello, World!
Fallback Handler
Catch all non-command messages (or unregistered commands) with @bot.on_message():
@bot.on_message()
async def fallback(msg):
await msg.reply("I don't understand that. Try /help")
Interactive Buttons
Send menu-style buttons in group chats. Private chats automatically fall back to a text list.
from luffa import button
@bot.command("menu")
async def menu(msg):
await msg.reply_buttons(
"What would you like to do?",
buttons=[
button("📋 Help", "/help"),
button("🏓 Ping", "/ping"),
button("ℹ️ About", "/about"),
],
)
Confirm Dialogs
Two side-by-side buttons for yes/no style interactions:
from luffa import confirm_button
@bot.command("delete")
async def delete(msg):
await msg.reply_confirm(
"Are you sure you want to delete?",
confirm=[
confirm_button("Yes", "/confirm_delete", style="destructive"),
confirm_button("Cancel", "/cancel"),
],
)
@Mentions
Mention users in group messages:
from luffa import mention
await bot.send_group_text(
group_id,
"@abc123 you've been invited!",
at_list=[mention("abc123", location=0, length=8)],
)
Hidden Buttons
Buttons can be hidden so the tapped message isn't visible to others:
button("Secret vote", "/vote yes", hidden=True)
API Reference
LuffaBot(secret, poll_interval=1)
The main bot class.
| Method | Description |
|---|---|
bot.command(name) |
Decorator — register a /command handler |
bot.on_message() |
Decorator — register a fallback handler |
bot.send_text(uid, text) |
Send a private message |
bot.send_group_text(uid, text, at_list?) |
Send a group text message |
bot.send_group_buttons(uid, text, buttons, dismiss?, at_list?) |
Send group message with buttons |
bot.send_group_confirm(uid, text, confirm, dismiss?, at_list?) |
Send group message with confirm buttons |
bot.run() |
Start polling (blocking) |
bot.start() |
Start polling (async) |
Message
Passed to every handler.
| Property | Type | Description |
|---|---|---|
msg.text |
str |
Message text |
msg.args |
list[str] |
Command arguments |
msg.uid |
str |
Chat ID (user or group) |
msg.sender_uid |
str |
ID of the user who sent it |
msg.is_group |
bool |
Whether it's a group message |
msg.msg_id |
str |
Unique message ID |
msg.at_list |
list |
@mentions in the message |
msg.url_link |
str | None |
Attached URL |
| Method | Description |
|---|---|
await msg.reply(text) |
Reply with text (auto-routes private/group) |
await msg.reply_buttons(text, buttons, dismiss?) |
Reply with menu buttons |
await msg.reply_confirm(text, confirm, dismiss?) |
Reply with confirm buttons |
Components
| Function | Description |
|---|---|
button(name, selector, hidden?) |
Create a menu button |
confirm_button(name, selector, style?, hidden?) |
Create a confirm button ("default" or "destructive") |
mention(uid, location?, length?) |
Create an @mention |
Limitations
The Luffa Bot API currently supports:
- ✅ Text messages (private & group)
- ✅ Interactive buttons (group only)
- ✅ @mentions (group only)
- ❌ Voice / audio messages
- ❌ Images / files
- ❌ Message deletion
- ❌ Admin actions (kick, mute, pin)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file luffa_sdk-0.1.0.tar.gz.
File metadata
- Download URL: luffa_sdk-0.1.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d12551bee8458b6e69af7f3194b82ca0ffe72d48c41e9b4ac295e40d9e1e7562
|
|
| MD5 |
3dd44df2a162ea1074d283d4cb4407b6
|
|
| BLAKE2b-256 |
6e96d8c7997d831b0e9e2cde364af2c66c0d251d5f2dc5d5390c97b27eb380c5
|
File details
Details for the file luffa_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: luffa_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76b05346ac8f2a908860df0e2a52a623ef873b9c0171a8c4f3ff45b4d9066f24
|
|
| MD5 |
9ce326aa8ed0d07fc70c2cad8229626d
|
|
| BLAKE2b-256 |
18636ab09ff9f1ba57aa4c72270fb03bfa6ca50264cfe9e1dd00c1ad4baf721e
|