Documents with a $messages key at the first level are inbox documents, and accept messages:
Messages are sent using the write token of the document. For that purpose, the write token of an inbox document is shared with all potential senders. The read token is kept secret by the owner.
Messages are small JSON documents of up to 4096 bytes. They may contain some data, or refer to other documents or blobs.
Every message has an 16-hexdigit message ID, which is randomly generated by the sender. Messages can be updated by sending a message with the same ID, and a newer revision field (a number). If no revision field is present, the revision is assumed to be 0.
The owner can use an inbox document like any other document. To read the messages, it loads the document, and typically removes all processed messages from the list.
Adds or updates a message on an inbox document. ID is a 16-hexdigit token, randomly generated by the sender.
If a message with the same ID exists, the message with the larger revision number is kept.
Removes a message. Note that the message may already have been read by the recipient.
Using GenericBackend.js, a message can be sent as follows:
const backend = new GenericBackend('https://viereck.ch/backend');
const writeToken = '1b599fd0...';
const messageId = backend.randomMessageid();
const message = {
revision: new Date().getTime(),
type: 'temperature',
value: 21.1
};
backend.sendMessage(writeToken, messageId, message, onDone, onError);
function onDone(request) {
...
}
function onError(errorCode, request) {
...
}