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.2.1.tar.gz (19.0 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.2.1-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dexgram_bot-0.2.1.tar.gz
  • Upload date:
  • Size: 19.0 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.2.1.tar.gz
Algorithm Hash digest
SHA256 205fec15fb14eb35a69b611565508f4507327f10c105337eac52892a8c610834
MD5 ca52cf0cd74c97215812a61cb5667db6
BLAKE2b-256 3751d3c0d585f4ab81258dfcead2d1d309650bebd21f7267bb5b67ae1f6c54bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for dexgram_bot-0.2.1.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.2.1-py3-none-any.whl.

File metadata

  • Download URL: dexgram_bot-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.7 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 616aa8516f680b6a5ce982e22ff5c1a227f8281f1394a9123267c241caaf0ab5
MD5 4366e9d8c3a636e98b6e211e65fe62d3
BLAKE2b-256 747cdcc2c94fdc16e313f9081925b958b51c740bdc3fa9a7b8314d942ea75148

See more details on using hashes here.

Provenance

The following attestation bundles were made for dexgram_bot-0.2.1-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