Skip to content

CsrpMessage

A CsrpMessage object represents a message that uses the CSRP specification.

Constructors

CsrpMessage new

CsrpMessage.new = function(sender: string?, recipients: {string} | string?, interactionId: string, options: {[string]: any} | string?, body: string?): CsrpMessage

Returns a CsrpMessage. Throws an error if an argument is invalid.

Arguments:

  1. string? sender - The message sender's JobId.
  2. {string} or string? recipients - The message recipients' JobIds.
  3. string interactionId - The message interaction ID. Required for fragmented messages.
  4. {[string]: any} or string? options - The message options.
  5. string? body - The message body.

Note

The first 4 arguments that form the message header must not contain semicolons (;). Additionally, the options argument must not contain equals signs (=) or commas (,). The message body can contain any characters.

Breaking change from 1.0.0

The fragment and fragmentCount arguments have been removed in release 2.0.0. Fragmentation is now handled using the CsrpMessageFragment class using the CSRPv2 specification.

CsrpMessage fromString

CsrpMessage.fromString = function(message: string): CsrpMessage

Parse a string into a CsrpMessage. Throws an error if the string is not a valid CSRP message.

Arguments:

  1. string message - The message string.

Properties

string? Sender

The message sender's JobId. Can be nil.

string? Recipients

A comma-separated list of the message recipients' JobIds. Can be nil. An empty string indicates that the message is broadcasted to all servers. Prefixing a recipient with a - indicates that the recipient should not process the message.

string InteractionId

The message interaction ID. Used to identify fragments of the same message. Can also be used to identify request-response pairs.

Breaking change from 1.0.0

The fragment and fragmentCount properties have been removed in release 2.0.0. Fragmentation is now handled using the CsrpMessageFragment class using the CSRPv2 specification.

string? Options

A comma-separated list of the message options. Can be nil. Each option is in the format key=value. Not used by Router, but can be used by the user to store additional information about the message.

string? Body

The message body. Can be nil and can contain any characters.


Serialization

A CsrpMessage object can be serialized into a string using the built-in tostring function.

local message = CsrpMessage.new("sender", "recipient", "interactionId", "option1=value1,option2=value2", "body")
print(tostring(message)) -- interactionId;sender;recipient;option1=value1,option2=value2;body

Breaking change from 1.0.0

The serialization order of some properties has changed since release 1.0.0 due to the upgrade to CSRPv2.