Skip to content

Rule.io SDK


Rule.io SDK / rcml/src / smsRfmToJson

Function: smsRfmToJson()

smsRfmToJson(input): SmsContentJson

Defined in: rcml/src/sms/sms-rfm-to-json.ts:41

Convert an SMS RFM string into an SmsContentJson document.

SMS RFM uses markdown-directive syntax:

  • :link[url]{track="true|false" shorten="true|false"} → top-level link node
  • ::placeholder{type="..." original="..." name="..." value="..." max-length="..."}placeholder node
  • [Type:Name] shorthand (e.g. [Subscriber:email]) — backward-compatible alias for ::placeholder{...}
  • Plain text (including embedded \n) → message node

Throws RcmlValidationError if the input contains unsupported constructs.

Parameters

input

string

SMS RFM source string.

Returns

SmsContentJson

Typed SMS content JSON ({ type: 'sms', content: [...] }).

Example

ts
// Shorthand placeholder
const json = smsRfmToJson('Account: [Subscriber:email]\nYour order has shipped.')
// { type: 'sms', content: [
//   { type: 'message', text: 'Account: ' },
//   { type: 'placeholder', attrs: { type: 'Subscriber', original: '[Subscriber:email]',
//       name: 'email', value: null } },
//   { type: 'message', text: '\nYour order has shipped.' },
// ] }

// Link directive
const json2 = smsRfmToJson(':link[https://example.com]{track="true" shorten="true"}')
// { type: 'sms', content: [
//   { type: 'link', text: 'https://example.com', attrs: { track: true, shorten: true } },
// ] }