Skip to main content

Async Python SDK for building bots on the Luffa messaging platform

Project description

Luffa Bot Python SDK

Async, OpenAI-style SDK for building bots for the Luffa messaging platform.

Features

  • Fully async (based on httpx and asyncio)
  • OpenAI-style interface (luffa_bot.robot_key = "...")
  • Simple APIs: receive(), send_to_user(), send_to_group(), and run()
  • Advanced group messages with buttons, confirms, and @mentions
  • Built-in deduplication, concurrency control, and middleware support
  • CLI for quick bot setup

Installation

pip install luffa-bot-python-sdk

Quickstart

import asyncio
import luffa_bot

# Set the robot secret key
luffa_bot.robot_key = "YOUR_ROBOT_SECRET"

async def main():
    # Poll once for messages
    envelopes = await luffa_bot.receive()
    for env in envelopes:
        for msg in env.messages:
            if env.type == 0:
                await luffa_bot.send_to_user(env.uid, f"You said: {msg.text}")
            else:
                await luffa_bot.send_to_group(env.uid, f"[group] {msg.text}")

asyncio.run(main())

Running a Bot Loop

Use the built-in run() method to continuously poll and handle messages.

import asyncio
import luffa_bot

luffa_bot.robot_key = "YOUR_ROBOT_SECRET"

async def handler(msg, env, client):
    if "help" in msg.text.lower():
        await client.send_to_user(env.uid, "How can I help?")
    else:
        await client.send_to_user(env.uid, f"Echo: {msg.text}")

asyncio.run(luffa_bot.run(handler, interval=1.0, concurrency=5))

Features of run()

  • Automatic deduplication by msgId
  • Configurable polling interval
  • Concurrency limit (process multiple messages at once)
  • Middleware and error hook support

Sending Group Messages with Buttons

from luffa_bot.models import GroupMessagePayload, SimpleButton

payload = GroupMessagePayload(
    text="Pick an option:",
    button=[SimpleButton(name="OK", selector="ok")]
)

await luffa_bot.send_to_group("GROUP_ID", payload, message_type=2)
  • message_type=1 → Text only
  • message_type=2 → Buttons/advanced messages

Environment Variables

  • LUFFA_ROBOT_SECRET: Default robot key if not set via luffa_bot.robot_key.

CLI

A CLI is included for quick bot testing:

export LUFFA_ROBOT_SECRET="..."

# Run an echo bot
luffa-bot run --interval 1.0

# Send DM to a user
luffa-bot send --uid <USER_ID> --text "Hello"

# Send message to a group with buttons
luffa-bot send-group --uid <GROUP_ID> --text "Hi group" --with-buttons

Development

  • Tests: Run pytest (uses pytest-asyncio + respx)
  • Lint: Run ruff check .
  • Type-check: Run mypy .

Author

Niraj Kulkarni (Sabma Labs, University of Surrey)


License

MIT 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

luffa_bot_python_sdk-0.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

luffa_bot_python_sdk-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: luffa_bot_python_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for luffa_bot_python_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3ee5bd2228b7634725c09cdc96f135fa5961556aaca60cb240d917030ec22c2c
MD5 03ca306d93f5d64b41b0e70b172af732
BLAKE2b-256 bbaf391fd79d7396af0a75e8a597c59ba327c045b7156762cecf3a88716eb395

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for luffa_bot_python_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef93d3fff67ea4879bab747587f735ddd500fa5292e2d05b0af8371eb9578c2e
MD5 8d80ba53a0bd23fa8cf0582bbb24e4bc
BLAKE2b-256 dbeedb953be9cee0ca40462b7193470c9be7fe6be53b0821913d77f0ee1cef75

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