X Enterprises
fastify-xrcs

sendMessage

Send an RCS/WhatsApp message using an existing Twilio Content API template SID.

sendMessage

Sends a message to a phone number using a pre-registered Twilio Content API template SID. Supports template variable substitution via contentVariables. Requires Twilio credentials and a messagingServiceSid.

Signature

fastify.xrcs.sendMessage(
  to: string,
  contentSid: string,
  contentVariables?: Record<string, string>
): Promise<SentMessage>

Params

NameTypeRequiredDescription
tostringYesRecipient phone number in E.164 format (e.g. "+15551234567")
contentSidstringYesTwilio Content API template SID (e.g. "HXabc123...")
contentVariablesRecord<string, string>NoVariable substitutions for the template (keys are positional strings "1", "2", ...)

Returns

{
  sid: string,
  to: string,
  status: string,      // e.g. "queued", "sent", "delivered"
  dateCreated: Date
}

Throws

  • [xRCS] Twilio credentials required to send messages — no accountSid/authToken
  • [xRCS] messagingServiceSid required to send messages — no messagingServiceSid in options
  • [xRCS] 'to' must be a non-empty string — missing or invalid to
  • [xRCS] 'contentSid' must be a non-empty string — missing or invalid SID
  • [xRCS] Failed to send message: {message} — Twilio API error

Examples

Send a static template

fastify.post("/notify", async (request) => {
  const { phone, templateSid } = request.body;

  const result = await fastify.xrcs.sendMessage(`+1${phone}`, templateSid);

  return { messageSid: result.sid, status: result.status };
});

Send with variable substitution

// Template text: "Hi {{1}}, your order {{2}} ships on {{3}}."
const result = await fastify.xrcs.sendMessage(
  "+15551234567",
  "HXabc123orderConfirm",
  { "1": "Alice", "2": "#4821", "3": "Thursday" }
);

See Also

AI Context

package: "@xenterprises/fastify-xrcs"
method: fastify.xrcs.sendMessage(to, contentSid, vars?)
use-when: Send a message using an existing Twilio Content API template SID — lowest-level send method
params: to (phone E.164), contentSid (string), vars (template variable map)
returns: { messageSid }
requires: Twilio credentials + messagingServiceSid
Copyright © 2026