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.1.tar.gz (15.3 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.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: luffa_bot_python_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 15.3 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.1.tar.gz
Algorithm Hash digest
SHA256 fa6b7bab5a6e6f761685870137983b9b8c9f70d0f5b55436912c705c4435c3fb
MD5 2ba6b3dd5b13490c61d237a856c50191
BLAKE2b-256 cd98e314117970a8e94f9aa29fa32b6dc25b117cda67285071d582a3e2fc9401

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for luffa_bot_python_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a481412bcebea40f480f1594678046215bcdaa1d6625c27d4b8d26683f3962d7
MD5 5ff956769ccc00fd6e38dc7b981da0e0
BLAKE2b-256 ca9be800d232bb031fe6b313e706177474c854d41f7d97d8a4282600299ccb57

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