Skip to main content

ECSS Chat Client

Python клиент для работы с ECSS Chat.

Install

pip install ecss-chat-client

GetStarted

from ecss_chat_client import Client

Basic HTTP Client

Basic user

client=Client(
    server=Params.SERVER_IP,
    proto=Params.PROTOCOL,
    port=Params.SERVER_PORT,
    verify=False,
)
client.create_session(
    username=USERNAME, password=PASSWORD,
)

Basic bot

client=Client(
    server=Params.SERVER_IP,
    proto=Params.PROTOCOL,
    port=Params.SERVER_PORT,
    verify=False,
)
client.create_bot_session(token='You bot token')

Simple Echo Bot

class SimpleBot(Client):

    @decorator_service.ws_ping_wrapper(logger=logger)
    def on_message(self, ws: WebSocketApp, message):
        logger.info('### message ###')

        try:
            data = json.loads(message)
            received_message = data.get('msg')

            if received_message == 'connected':
                self.basic_websocket.auth()
            if received_message == 'result' and data.get('result').get('id'):
                self.basic_websocket.subscribe_notification()
            if received_message == 'changed':
                payload = data['fields']['args'][0]['payload']
                payload_type = payload['type']
                if payload_type == RoomTypes.DIRECT:
                    if len(payload['message']['msg']) > 0:
                        message = payload['message']['msg']
                        room_id = payload['rid']
                        self.messages.send(
                            text=message,
                            room_id=room_id,
                        )
        except json.JSONDecodeError:
            pass

    @staticmethod
    def on_error(ws: WebSocketApp, error):
        logger.error(error)

    @staticmethod
    def on_close(ws: WebSocketApp, close_status_code, close_msg):
        logger.warning('### closed ###')

    @staticmethod
    def send_message(client: Client, text, rid):
        client.messages.send(text, room_id=rid)


if __name__ == '__main__':
    bot_client = SimpleBot(server=SERVER, port=PORT, verify=False)
    bot_client.create_bot_session(token=TOKEN)
    logger.add('bot.log', rotation='500 MB')
    bot_client.basic_websocket.init_ws_client(
        on_message_handler=bot_client.on_message,
        on_error_handler=bot_client.on_error,
        on_close_handler=bot_client.on_close,
        token=TOKEN,
        client_uid=UID,
        logger=logger,
        websocket_trace=True,
    )

Вы можете обработать событие "on_pong" с помощью декоратора

@decorator_service.ws_ping_wrapper(logger=logger)
def on_message(self, ws: WebSocketApp, message):
    logger.info('### message ###')

    try:
        data = json.loads(message)
        received_message = data.get('msg')

Вы можете обработать событие "on_pong" с помощью функции "ping_handler"

def on_message(self, ws: WebSocketApp, message):
    logger.info('### message ###')

    try:
        data = json.loads(message)
        received_message = data.get('msg')

        if received_message == 'ping':
            self.basic_websocket.ping_handler()

Можно не передавать логер в декоратор с учетом, что кастомный логгер не был добавлен в "init_ws_client"

@decorator_service.ws_ping_wrapper()
def on_message(self, ws: WebSocketApp, message):
    logger.info('### message ###')

    try:
        data = json.loads(message)
        received_message = data.get('msg')

Metadata

Release files for ecss-chat-client 1.5.50

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ecss-chat-client 1.5.50
File Size Uploaded Provenance Actions
ecss_chat_client-1.5.50.tar.gz 25.8 kB Without provenance Details for ecss_chat_client-1.5.50.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ecss-chat-client 1.5.50
File Interpreter ABI Platform Actions
ecss_chat_client-1.5.50-py3-none-any.whl Python 3 none any Details for ecss_chat_client-1.5.50-py3-none-any.whl

Total release size: 63.5 kB

Release files / ecss_chat_client-1.5.50.tar.gz

Download URL ecss_chat_client-1.5.50.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5d3a9aef9ce62eb947c3c4a8da227c5f16d2e17b81b9c79ac14f15fbed6d8204
BLAKE2b-256 checksum
How to use checksums
66ab14216961be1c712f8ff96afa3ad82f14cbff9f117d4d50c8692f30ccfb00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / ecss_chat_client-1.5.50-py3-none-any.whl

Download URL ecss_chat_client-1.5.50-py3-none-any.whl
Size 37.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d0dc8265c6f2125a4b3498db4624b07f7496ff226efc4aa5aca0f0f3281bb52
BLAKE2b-256 checksum
How to use checksums
9ab1a0dbea6d9731a1e643c57602a14dea36bc6b6b49e79160801d431abb2047
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Security for ecss-chat-client 1.5.50

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.5.50 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page