mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-05 01:32:09 +00:00
simplex-chat-python: split Client from Bot, add request/response API (#6976)
* simplex-chat-python: split Client from Bot, add request/response API
Client is now the base class for SimpleX participants that talk TO
services (monitors, probes, automated participants). Bot extends Client
with server features (address, auto-accept, welcome, commands).
New methods on Client (inherited by Bot):
connect_to(link) idempotent contact handshake
send_and_wait(id, text) send a message and await the reply
events() async iterator over chat events
@on_message(contact_id=N) filter by sender in decorators
BotProfile renamed to Profile (alias kept). New ContactAlreadyExistsError
subclass for cleaner error handling.
* simplex-chat-python: narrow event payload type per @on_event tag
@client.on_event("contactConnected") now types the handler's event
parameter as CEvt.ContactConnected instead of the unnarrowed
CEvt.ChatEvent union — mirroring how @on_message narrows by
content_type.
The 50 overloads are generated by the Haskell codegen into _events.py
(as a Protocol class), so new events stay in sync automatically.
Client.on_event is exposed as a property typed as that Protocol; the
runtime implementation is unchanged.
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
"""SimpleX Chat — Python client library for chat bots."""
|
||||
|
||||
from ._version import __version__
|
||||
from .api import ChatApi, ChatCommandError, ConnReqType, Db, PostgresDb, SqliteDb
|
||||
from .api import (
|
||||
ChatApi,
|
||||
ChatCommandError,
|
||||
ConnReqType,
|
||||
ContactAlreadyExistsError,
|
||||
Db,
|
||||
PostgresDb,
|
||||
SqliteDb,
|
||||
)
|
||||
from .bot import (
|
||||
Bot,
|
||||
BotCommand,
|
||||
BotProfile,
|
||||
ChatMessage,
|
||||
Client,
|
||||
CommandHandler,
|
||||
EventHandler,
|
||||
FileMessage,
|
||||
@@ -16,6 +25,7 @@ from .bot import (
|
||||
MessageHandler,
|
||||
Middleware,
|
||||
ParsedCommand,
|
||||
Profile,
|
||||
ReportMessage,
|
||||
TextMessage,
|
||||
UnknownMessage,
|
||||
@@ -35,8 +45,10 @@ __all__ = [
|
||||
"ChatCommandError",
|
||||
"ChatInitError",
|
||||
"ChatMessage",
|
||||
"Client",
|
||||
"CommandHandler",
|
||||
"ConnReqType",
|
||||
"ContactAlreadyExistsError",
|
||||
"CryptoArgs",
|
||||
"Db",
|
||||
"EventHandler",
|
||||
@@ -49,6 +61,7 @@ __all__ = [
|
||||
"MigrationConfirmation",
|
||||
"ParsedCommand",
|
||||
"PostgresDb",
|
||||
"Profile",
|
||||
"ReportMessage",
|
||||
"SqliteDb",
|
||||
"TextMessage",
|
||||
|
||||
Reference in New Issue
Block a user