Connect Chatom to CSP

Install csp, wrap a backend with chatom.csp.BackendAdapter, and use the adapter inside a graph.

pip install csp

Subscribe to messages

import csp
from chatom.csp import BackendAdapter

adapter = BackendAdapter(backend)

@csp.graph
def message_graph():
    messages = adapter.subscribe(
        channels={"operations", "C0123"},
        skip_own=True,
        skip_history=True,
    )
    csp.print("messages", messages)

subscribe produces a time series of message lists. Channel names are resolved when the backend connects.

Publish messages and presence

@csp.graph
def publish_graph():
    outgoing = csp.const(message)
    adapter.publish(outgoing)

    presence = csp.const("available")
    adapter.publish_presence(presence)

The lower-level chatom.csp.message_reader(), chatom.csp.message_writer(), and chatom.csp.interaction_reader() functions are available when graph composition does not need the wrapper.