Skip to content

Rule.io SDK


Rule.io SDK / rcml/src / sms

Variable: sms

const sms: object

Defined in: rcml/src/sms/builders/sms-namespace.ts:50

Namespace object grouping every SMS content-JSON builder.

Type Declaration

createContent

createContent: (opts) => SmsContentJson

Build an SmsContentJson root document — a doc node wrapping one or more paragraphs.

Parameters

opts

CreateSmsContentOptions

Returns

SmsContentJson

Example

ts
const content = sms.createContent({
  paragraphs: [
    sms.createParagraphNode({
      content: [sms.createTextNode({ text: 'Hello world' })],
    }),
  ],
})

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

SmsPlaceholderNode

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

SmsPlaceholderNode

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]'

createHardbreakNode

createHardbreakNode: () => SmsHardbreakNode

Build an SmsHardbreakNode — a forced line break that stays inside the current paragraph.

Returns

SmsHardbreakNode

Example

ts
sms.createHardbreakNode()
// → { type: 'hardbreak', attrs: { isInline: false } }

createLinkMark

createLinkMark: (opts) => SmsLinkMark

Build an SmsLinkMark — a link mark carrying a destination URL, a click-tracking flag, and a URL-shortening flag.

Parameters

opts

CreateSmsLinkMarkOptions

Returns

SmsLinkMark

Example

ts
sms.createLinkMark({
  href: 'https://example.com/orders/[CustomField:Order.Id]',
  track: true,
  shorten: true,
})

createLinkPlaceholder

createLinkPlaceholder: (opts) => SmsPlaceholderNode

Build a Link placeholder node — inserts a system-managed link URL as plain text in the message body. Use this when you want the raw URL visible in the message.

To produce a clickable link instead, use createLinkMark with href: '[Link:Unsubscribe]' (or another system link) on a text node.

Produces original = '[Link:<link>]' and name = '<link>'.

Parameters

opts

CreateSmsLinkPlaceholderOptions

Returns

SmsPlaceholderNode

Example

ts
sms.createLinkPlaceholder({ link: 'Unsubscribe' })
// original: '[Link:Unsubscribe]', name: 'Unsubscribe'

createParagraphNode

createParagraphNode: (opts) => SmsParagraphNode

Build an SmsParagraphNode — a block node holding a sequence of inline nodes.

Parameters

opts?

CreateSmsParagraphNodeOptions = {}

Returns

SmsParagraphNode

Example

ts
sms.createParagraphNode({
  content: [
    sms.createTextNode({ text: 'Hi ' }),
    sms.createSubscriberPlaceholder({ field: 'FirstName' }),
    sms.createTextNode({ text: '!' }),
  ],
})

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

SmsPlaceholderNode

Example

ts
sms.createPlaceholderNode({
  type: 'Subscriber',
  original: '[Subscriber:FirstName]',
  name: 'FirstName',
})

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

SmsPlaceholderNode

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

SmsPlaceholderNode

Example

ts
sms.createSubscriberPlaceholder({ field: 'FirstName' })
// → { type: 'placeholder', attrs: { type: 'Subscriber',
//     original: '[Subscriber:FirstName]', name: 'FirstName',
//     value: null, 'max-length': null } }

createTextNode

createTextNode: (opts) => SmsTextNode

Build an SmsTextNode — a leaf inline node carrying a string of text, optionally with one or more marks.

Parameters

opts

CreateSmsTextNodeOptions

Returns

SmsTextNode

Example

ts
sms.createTextNode({ text: 'Hello, ' })
// → { type: 'text', text: 'Hello, ' }

sms.createTextNode({
  text: 'click here',
  marks: [sms.createLinkMark({ href: 'https://example.com', track: true, shorten: false })],
})

createUserPlaceholder

createUserPlaceholder: (opts) => SmsPlaceholderNode

Build a User placeholder node.

Produces original = '[User:<field>]'.

Parameters

opts

CreateSmsUserPlaceholderOptions

Returns

SmsPlaceholderNode

Example

ts
sms.createUserPlaceholder({ field: 'CompanyName' })

Example

ts
import { sms, createSmsDocument } from '@rule/rcml';

const content = sms.createContent({
  paragraphs: [
    sms.createParagraphNode({
      content: [
        sms.createTextNode({ text: 'Hi ' }),
        sms.createSubscriberPlaceholder({ field: 'FirstName' }),
        sms.createTextNode({ text: '!' }),
      ],
    }),
  ],
});

const doc = createSmsDocument({ content });