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+
websocketslibrary- SimpleX Chat CLI running as WebSocket server
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9c7790843dab31f995d609ee1ee920372c95909e0a2ec6d1b6fe85d3f5635d2
|
|
| MD5 |
c554eda15d76716e1255928c2b6ab0ea
|
|
| BLAKE2b-256 |
93bcfdd6adbb1e35dbabd429b9f6143a3c99885de5e8226b43ffc07cfe03d8ad
|
Provenance
The following attestation bundles were made for dexgram_bot-0.1.0.tar.gz:
Publisher:
publish.yml on AsadKhanSwati/dexgram-bot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dexgram_bot-0.1.0.tar.gz -
Subject digest:
a9c7790843dab31f995d609ee1ee920372c95909e0a2ec6d1b6fe85d3f5635d2 - Sigstore transparency entry: 1180398186
- Sigstore integration time:
-
Permalink:
AsadKhanSwati/dexgram-bot@0783fe0dacabcbca56b2276c8502c701f753e271 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AsadKhanSwati
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0783fe0dacabcbca56b2276c8502c701f753e271 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88cd5fb894cfe720edc10f1520f1ca3930e493c40c834794c47b70827590ac96
|
|
| MD5 |
809775bc5bce484fb856e3e97b42a66e
|
|
| BLAKE2b-256 |
4df7e5000b88578c6663dff20f1940d305cdfb4fbe5e4c969cc92b35047bd484
|
Provenance
The following attestation bundles were made for dexgram_bot-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on AsadKhanSwati/dexgram-bot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dexgram_bot-0.1.0-py3-none-any.whl -
Subject digest:
88cd5fb894cfe720edc10f1520f1ca3930e493c40c834794c47b70827590ac96 - Sigstore transparency entry: 1180398236
- Sigstore integration time:
-
Permalink:
AsadKhanSwati/dexgram-bot@0783fe0dacabcbca56b2276c8502c701f753e271 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AsadKhanSwati
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0783fe0dacabcbca56b2276c8502c701f753e271 -
Trigger Event:
release
-
Statement type: