Skip to content

CsrpMessageBuilder

A utility class for creating valid CsrpMessage objects.

Constructors

CsrpMessageBuilder new

CsrpMessageBuilder.new = function()

Returns a new CsrpMessageBuilder object.


Properties

string Sender

The message sender's JobId. Defaults to the current server's JobId.

{string} Recipients

A table of the message recipients' JobIds. Defaults to an empty table.

string InteractionId

The message interaction ID. A random GUID will be generated when calling the constructor.

{[string]: any} Options

A table of additional message options. Defaults to an empty table.

string? Body

The message body. Defaults to nil.


Methods

CsrpMessageBuilder SetSender

CsrpMessageBuilder:SetSender(sender: string): CsrpMessageBuilder

Sets the message sender's JobId. Throws an error if the sender contains semicolons. Returns the CsrpMessageBuilder object for chaining.

CsrpMessageBuilder SetRecipients

CsrpMessageBuilder:SetRecipients(recipients: {string}): CsrpMessageBuilder

Sets the message recipients' JobIds. Throws an error if any of the recipients contain semicolons. Returns the CsrpMessageBuilder object for chaining.

CsrpMessageBuilder AddRecipient

CsrpMessageBuilder:AddRecipient(recipient: string, excludeCurrentForBroadcast: boolean?): CsrpMessageBuilder

Adds a recipient to the message. Throws an error if the recipient contains semicolons. Returns the CsrpMessageBuilder object for chaining.

If recipient is an empty string, the message will be broadcast to all servers. If excludeCurrentForBroadcast is true (default), the current server's JobId will be excluded from the broadcast. Setting excludeCurrentForBroadcast to false will cause the message to be broadcast to all servers, including the current server.

Warning

If excludeCurrentForBroadcast is set to false when broadcasting to all servers, the sender will also receive the message. Keep this in mind in order to avoid infinite loops.

CsrpMessageBuilder ExcludeRecipient

CsrpMessageBuilder:ExcludeRecipient(recipient: string): CsrpMessageBuilder

Excludes a recipient from the message by adding it to the Recipients list and prefixing the recipient with -. Throws an error if the recipient contains semicolons. Returns the CsrpMessageBuilder object for chaining.

CsrpMessageBuilder SetInteractionId

CsrpMessageBuilder:SetInteractionId(interactionId: string): CsrpMessageBuilder

Sets the message interaction ID. Throws an error if the interaction ID contains semicolons. Returns the CsrpMessageBuilder object for chaining.

CsrpMessageBuilder SetOption

CsrpMessageBuilder:SetOption(option: string, value: any): CsrpMessageBuilder

Sets an option on the message. Throws an error if the key or value contain semicolons, commas or equals signs. Returns the CsrpMessageBuilder object for chaining.

CsrpMessageBuilder SetBody

CsrpMessageBuilder:SetBody(body: string): CsrpMessageBuilder

Sets the message body. Returns the CsrpMessageBuilder object for chaining.

Note

The message body can contain any characters, including semicolons, commas and equals signs.

CsrpMessage Build

CsrpMessageBuilder:Build(): CsrpMessage

Builds the message. Returns the CsrpMessage object.