Skip to main content

Python SDK for building bots on Dark Link / SimpleX Chat with rich GUI messages

Project description

dexgram-bot

Python SDK for building bots on Dark Link / SimpleX Chat with rich GUI messages.

Build Telegram-style bots with inline keyboards, product cards, catalogs, forms, and crypto payment integration.

Quick Start

1. Install

pip install dexgram-bot

Or from source:

git clone https://github.com/AsadKhanSwati/dexgram-bot.git
cd dexgram-bot
pip install -e .

2. Start SimpleX Chat CLI

Download the CLI from simplex.chat and run it as a WebSocket server:

simplex-chat -p 5225 --create-bot-display-name "MyBot"

3. Write Your Bot

from dexgram import Bot

bot = Bot(ws_url="ws://localhost:5225")

@bot.on_contact_connected
async def welcome(contact):
    await bot.send_inline_keyboard(
        contact.id,
        "Welcome! What would you like to do?",
        [
            [{"text": "Browse Products", "callback_data": "catalog"}],
            [{"text": "Help", "callback_data": "help"}],
        ],
    )

@bot.on_command("help")
async def help_cmd(contact, args):
    await bot.send_text(contact.id, "Commands: /help, /catalog")

@bot.on_callback("catalog")
async def show_catalog(contact, callback):
    await bot.send_catalog(contact.id, products=[
        {"id": "item-1", "title": "Widget", "price": "0.01", "currency": "ETH"},
        {"id": "item-2", "title": "Gadget", "price": "0.05", "currency": "ETH"},
    ])

@bot.on_message
async def fallback(contact, text):
    await bot.send_text(contact.id, f"You said: {text}")

bot.run()

Features

Inline Keyboards

Send messages with interactive buttons:

await bot.send_inline_keyboard(
    contact.id,
    "Choose an option:",
    [
        [{"text": "Option A", "callback_data": "a"}, {"text": "Option B", "callback_data": "b"}],
        [{"text": "Visit Website", "url": "https://example.com"}],
        [{"text": "Pay Now", "pay": True}],
    ],
)

Product Cards

Display product information with images and Buy buttons:

await bot.send_product_card(
    contact.id,
    id="shoe-1",
    title="Running Shoes",
    price="0.05",
    currency="ETH",
    description="Lightweight running shoes",
    network="ethereum",
    wallet_address="0x...",
    keyboard=[
        [{"text": "Buy Now", "pay": True}, {"text": "Add to Cart", "callback_data": "cart:shoe-1"}],
    ],
)

Catalogs

Send a horizontal carousel of products:

await bot.send_catalog(contact.id, products=[
    {"id": "p1", "title": "Item 1", "price": "0.01", "currency": "ETH"},
    {"id": "p2", "title": "Item 2", "price": "0.02", "currency": "ETH"},
    {"id": "p3", "title": "Item 3", "price": "0.03", "currency": "ETH"},
])

Forms

Collect structured input from users:

await bot.send_form(
    contact.id,
    id="shipping",
    title="Shipping Info",
    fields=[
        {"name": "name", "label": "Full Name", "field_type": "text"},
        {"name": "email", "label": "Email", "field_type": "email"},
        {"name": "country", "label": "Country", "field_type": "dropdown",
         "options": ["US", "UK", "Canada", "Germany"]},
    ],
    submit_label="Submit Order",
    callback_data="order:submit",
)

Crypto Payments

Trigger the wallet payment flow:

await bot.send_payment_request(
    contact_id=contact.id,
    amount="0.05",
    currency="ETH",
    network="ethereum",
    wallet_address="0x742d35Cc6634C0532925a3b844Bc9e7595f2bD18",
    memo="Order #1234",
)

Event Handlers

Decorators

Decorator Trigger
@bot.on_start Bot connected and ready
@bot.on_contact_connected New user connects to bot
@bot.on_contact_disconnected User disconnects
@bot.on_command("keyword") User sends /keyword
@bot.on_callback("pattern") User clicks inline button
@bot.on_message Any text message (fallback)

Callback Patterns

Callbacks support wildcard matching:

@bot.on_callback("buy:*")          # matches "buy:shoe-1", "buy:hat-2"
async def handle_buy(contact, callback):
    product_id = callback.data.split(":")[1]

@bot.on_callback("order:*:*")      # matches "order:123:confirm"
async def handle_order(contact, callback):
    parts = callback.data.split(":")
    order_id, action = parts[1], parts[2]

Low-Level Client

For advanced use, access the DexgramClient directly:

from dexgram import DexgramClient, ChatType
import asyncio

async def main():
    client = await DexgramClient.create("ws://localhost:5225")
    user = await client.api_get_active_user()
    print(f"Bot: {user.local_display_name}")

    await client.api_send_text(ChatType.DIRECT, contact_id, "Hello!")
    await client.disconnect()

asyncio.run(main())

Architecture

dexgram-bot
├── dexgram/
│   ├── __init__.py          # Public API exports
│   ├── transport.py         # WebSocket JSON protocol
│   ├── types.py             # Data types (Contact, User, ChatItem, ...)
│   ├── client.py            # DexgramClient — low-level API methods
│   ├── rich_messages.py     # BotMessage encode/decode (__BOT_MSG__ protocol)
│   └── bot.py               # Bot — high-level framework with decorators
└── examples/
    ├── echo_bot.py          # Minimal echo bot
    ├── shop_bot.py          # E-commerce bot with cart & payments
    └── faq_bot.py           # FAQ bot with search & nested menus

Message Protocol

Rich bot messages use a prefix-based protocol over standard SimpleX text messages:

  • __BOT_MSG__ + JSON — Bot sends rich content (keyboards, cards, forms)
  • __BOT_CB__ + JSON — User sends callback (button click, form submit)
  • __PAY_INV__ + JSON — Payment invoice (existing wallet protocol)
  • __PAY_CONF__ + JSON — Payment confirmation (existing wallet protocol)

The Dark Link mobile/desktop app detects these prefixes and renders the appropriate interactive UI components instead of plain text.

Examples

See the examples/ directory:

  • echo_bot.py — Minimal bot that echoes messages back
  • shop_bot.py — Full e-commerce bot with products, cart, checkout, and crypto payments
  • faq_bot.py — FAQ bot with categories, search, and nested navigation

Requirements

  • Python 3.10+
  • websockets library
  • SimpleX Chat CLI running as WebSocket server

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

dexgram_bot-0.1.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

dexgram_bot-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dexgram_bot-0.1.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dexgram_bot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a9c7790843dab31f995d609ee1ee920372c95909e0a2ec6d1b6fe85d3f5635d2
MD5 c554eda15d76716e1255928c2b6ab0ea
BLAKE2b-256 93bcfdd6adbb1e35dbabd429b9f6143a3c99885de5e8226b43ffc07cfe03d8ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for dexgram_bot-0.1.0.tar.gz:

Publisher: publish.yml on AsadKhanSwati/dexgram-bot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: dexgram_bot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dexgram_bot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88cd5fb894cfe720edc10f1520f1ca3930e493c40c834794c47b70827590ac96
MD5 809775bc5bce484fb856e3e97b42a66e
BLAKE2b-256 4df7e5000b88578c6663dff20f1940d305cdfb4fbe5e4c969cc92b35047bd484

See more details on using hashes here.

Provenance

The following attestation bundles were made for dexgram_bot-0.1.0-py3-none-any.whl:

Publisher: publish.yml on AsadKhanSwati/dexgram-bot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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