The Tryton server listens on
POST requests on the routes matching
/<database_name>/bus and replies with JSON dictionary containing:
- The channel on which this message has been received.
A dictionary that is the message the client must handle. The specification of the message depends of its type.
All messages should at least content a unique identifier in the key
message_idand their type in the key of the same name.
Client sending their request on the route must be authenticated. The request must submit a JSON dictionary containing:
- A value identifying the last message received by the client. This value
- A list of strings denoting the channels the client is listening to.
The :class:Bus exposes two methods that are used by the framework:
Send a message to a specific channel.
Currently implemented messages are:
subscribe(database, channels[, last_message])¶
Subscribe a user client to some
message_idparameter defines the last message ID received by the client. It defaults to None when not provided.
The default implementation provides an helper method to construct the response:
Creates a dictionary suitable as a response from a message and a timestamp.
channelis the channel on which the message has been received.
messageis the content of the message sent to the client.
Please note that the implementation relies on the fact that the order of the messages received is consistent accros different trytond instances allowing to dispatch the request to any trytond server running.
Tryton provides a shortcut to send a notification with the
notify(title[, body[, priority[, user[, client]]]])¶
Send a text message to a user’s client to be displayed using a notification popup. The meaning of
priorityis defined in Notification message.
useris not set, the current
useris used. Otherwise
useris the user ID to notify.
clientis not set then every client of the user will receive the message. If
userare not set, the system will send the notification to the current user client. Otherwise the notification will be sent to the client whose ID matches
Notification messages are composed of four parts:
- The string ‘notification’.
- A string. A one-line summary of the message.
- A string. The short informative message for the user. It can span multiple lines but no markup is allowed.
- An integer between 0 (low priority) to 3 (urgent). The notification priority on the platform supporting it.