Python client for chatbot platform
Project description
pychatbot2
A Python SDK for the chatbot platform, providing a clean and type-safe interface for interacting with messaging platforms.
Features
- Type-safe interfaces using Python's type hints
- Async/await support for all operations
- Event-driven architecture using Server-Sent Events (SSE)
- Support for various message content types (text, image, audio, card)
- Comprehensive error handling and logging
- Easy integration with messaging platforms
Installation
pip install pychatbot2
Quick Start
from pychatbot2 import ChatbotClient, ChatbotClientOptions, CommandRunner, Contact, ContactType, ChatMessagePayload, ChatMessagePlainContent
class MyCommandRunner(CommandRunner):
async def on_start(self, payload):
return {
"self": Contact(
contact_type=ContactType.PRIVATE,
contact_id="user123",
name="My Bot"
),
"contacts": []
}
async def get_self(self, payload):
return Contact(
contact_type=ContactType.PRIVATE,
contact_id="user123",
name="My Bot"
)
async def get_contacts(self, payload):
return []
async def get_contact_info(self, payload):
return {
"name": "Test Contact",
"members": []
}
async def send_chat_message(self, payload):
# Implement message sending logic
pass
# Create client options
options = ChatbotClientOptions(
base_url="https://api.example.com",
api_key="your-api-key",
message_platform_type="custom",
message_platform_account_id="account123",
command_runner=MyCommandRunner()
)
# Create and start the client
client = ChatbotClient(options)
await client.start()
# Handle incoming messages
async def handle_message(message):
payload = ChatMessagePayload(
contact_type=ContactType.PRIVATE,
contact_id="user123",
message_id="msg123",
sender_id="sender123",
content=ChatMessagePlainContent(text="Hello!"),
mentioned=False
)
await client.on_receive_chat_message(payload)
Development
Setup
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]"
Running Tests
pytest
Code Style
This project uses:
- Black for code formatting
- isort for import sorting
- mypy for type checking
Run the formatters:
black .
isort .
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
pychatbot2-0.1.3.tar.gz
(6.9 kB
view details)
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 pychatbot2-0.1.3.tar.gz.
File metadata
- Download URL: pychatbot2-0.1.3.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3f22cb65c733ad9583f7fbe7ba06093358d59caa206c0681338067261eb9de9
|
|
| MD5 |
50404dc4b9393e7d72c5dc1ebe96c6ce
|
|
| BLAKE2b-256 |
9b18c41dfe04dfde3f7045f904d2c5e5b9c3d31fcdac99abcbf3fdbf20010931
|
File details
Details for the file pychatbot2-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pychatbot2-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39304397c674e593ba57451b05e7bc038ea1599bbe77df8cbe19faa4789aa399
|
|
| MD5 |
70845f9f4188bba7507cd154f7e9d46e
|
|
| BLAKE2b-256 |
45ed2a93715fe607f65604da57594d9e74b0626fbe500296c7a7ccb3909cc2c1
|