Skip to main content

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

  1. Clone the repository
  2. 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.5.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

pychatbot2-0.1.5-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file pychatbot2-0.1.5.tar.gz.

File metadata

  • Download URL: pychatbot2-0.1.5.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pychatbot2-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9a5d7c9556e3e9321250d9d3ece5d40d443834b298ca904b028a0fc8d29ef72f
MD5 b16f7ba7425b43f8bb78fb7bf2b9fbc4
BLAKE2b-256 0ef30d81afb9a25222d89e43ee66a579dc5c97888e90268601f85ab2eb5311da

See more details on using hashes here.

File details

Details for the file pychatbot2-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pychatbot2-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pychatbot2-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ef2c5cb13ff816d5deb538d1b857f8ca30de544c9d8f6314e6f8a9023ba130d4
MD5 ce3c66e64fd17b0c14e418f96f4f2538
BLAKE2b-256 08b8c4b5806b3a066091d05fa99c3eaafb09f1af4bbfb53dbb48cb3bb78f717f

See more details on using hashes here.

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