Appearance
Rule.io SDK / rcml/src / sms
Variable: sms
constsms:object
Defined in: rcml/src/sms/builders/sms-namespace.ts:40
Namespace object grouping every SMS content-JSON builder.
Type Declaration
createContent
createContent: (
opts) =>SmsContentJson
Build an SmsContentJson root document — the sms container that wraps all top-level nodes.
Parameters
opts
Returns
Example
ts
const content = sms.createContent({
nodes: [
sms.createMessageNode({ text: 'Hi ' }),
sms.createSubscriberPlaceholder({ field: 'email' }),
sms.createMessageNode({ text: ', your order has shipped!' }),
],
})createCustomFieldPlaceholder
createCustomFieldPlaceholder: (
opts) =>SmsPlaceholderNode
Build a CustomField placeholder node.
Produces original = '[CustomField:<group>.<name>]', or '[CustomField:<group>.<name>::<maxLength>]' when maxLength is given.
Parameters
opts
CreateSmsCustomFieldPlaceholderOptions
Returns
Example
ts
sms.createCustomFieldPlaceholder({ group: 'Order', name: 'Total' })
sms.createCustomFieldPlaceholder({ group: 'Order', name: 'Total', maxLength: 20 })createDatePlaceholder
createDatePlaceholder: (
opts) =>SmsPlaceholderNode
Build a Date placeholder node.
Produces original = '[Date:<source>::<format>]', where <source> is derived from SmsDateSource.
Parameters
opts
CreateSmsDatePlaceholderOptions
Returns
Example
ts
sms.createDatePlaceholder({ source: 'tomorrow', format: 'd.m.Y' })
// original: '[Date:tomorrow::d.m.Y]'
sms.createDatePlaceholder({
source: { kind: 'days-from-now', count: 7 },
format: 'Y-m-d',
})
// original: '[Date:in-7-days::Y-m-d]'
sms.createDatePlaceholder({
source: { kind: 'custom-field', group: 'Order', name: 'CreatedAt' },
format: 'Y-m-d',
})
// original: '[Date:[CustomField:Order.CreatedAt]::Y-m-d]'createLinkNode
createLinkNode: (
opts) =>SmsLinkNode
Build an SmsLinkNode — a hyperlink in the SMS body.
The URL is used as both the destination and the visible text. The Rule platform applies tracking and/or URL shortening at send time based on the track and shorten flags.
Parameters
opts
Returns
Example
ts
sms.createLinkNode({ url: 'https://example.com/orders/123', track: true, shorten: true })createMessageNode
createMessageNode: (
opts) =>SmsMessageNode
Build an SmsMessageNode — a text segment in the SMS body.
Text may contain \n characters: a single \n produces a line break, and \n at a paragraph boundary is also expressed inline in the same way.
Parameters
opts
Returns
Example
ts
sms.createMessageNode({ text: 'Your order has shipped!\nAccount: [Subscriber:email]' })createPlaceholderNode
createPlaceholderNode: (
opts) =>SmsPlaceholderNode
Build an SmsPlaceholderNode from raw attribute values. Most callers should reach for one of the typed convenience builders below instead — they compute original and name from domain inputs so the caller never has to assemble bracket-token strings by hand.
Parameters
opts
CreateSmsPlaceholderNodeOptions
Returns
Example
ts
sms.createPlaceholderNode({
type: 'Subscriber',
original: '[Subscriber:email]',
name: 'email',
})createRemoteContentPlaceholder
createRemoteContentPlaceholder: (
opts) =>SmsPlaceholderNode
Build a RemoteContent placeholder node.
Produces original = '[RemoteContent:<url>]'. The name attribute is always 'RemoteContent', matching what the SMS RFM parser produces.
Parameters
opts
CreateSmsRemoteContentPlaceholderOptions
Returns
Example
ts
sms.createRemoteContentPlaceholder({ url: 'https://api.example.com/promo' })createSubscriberPlaceholder
createSubscriberPlaceholder: (
opts) =>SmsPlaceholderNode
Build a Subscriber placeholder node.
Produces original = '[Subscriber:<field>]'.
Parameters
opts
CreateSmsSubscriberPlaceholderOptions
Returns
Example
ts
sms.createSubscriberPlaceholder({ field: 'email' })
// → { type: 'placeholder', attrs: { type: 'Subscriber',
// original: '[Subscriber:email]', name: 'email', value: null } }createUnsubscribeNodes
createUnsubscribeNodes: () => [
SmsMessageNode,SmsPlaceholderNode]
Build the two-node unsubscribe footer: a localised stop-word message followed by the system unsubscribe link placeholder.
Spread the result directly into a createContent({ nodes }) call:
Returns
[SmsMessageNode, SmsPlaceholderNode]
Example
ts
sms.createContent({
nodes: [
sms.createMessageNode({ text: 'Your order has shipped.' }),
...sms.createUnsubscribeNodes(),
],
})createUserPlaceholder
createUserPlaceholder: (
opts) =>SmsPlaceholderNode
Build a User placeholder node.
Produces original = '[User:<field>]'.
Parameters
opts
CreateSmsUserPlaceholderOptions
Returns
Example
ts
sms.createUserPlaceholder({ field: 'CompanyName' })Example
ts
import { sms, createSmsDocument } from '@rule/rcml';
const content = sms.createContent({
nodes: [
sms.createMessageNode({ text: 'Hi ' }),
sms.createSubscriberPlaceholder({ field: 'email' }),
sms.createMessageNode({ text: '!\n' }),
sms.createLinkNode({ url: 'https://example.com', track: true, shorten: true }),
],
});
const doc = createSmsDocument({ content });