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
| Name | Type | Required | Description |
|---|---|---|---|
to | string | Yes | Recipient phone number in E.164 format (e.g. "+15551234567") |
contentSid | string | Yes | Twilio Content API template SID (e.g. "HXabc123...") |
contentVariables | Record<string, string> | No | Variable 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— noaccountSid/authToken[xRCS] messagingServiceSid required to send messages— nomessagingServiceSidin options[xRCS] 'to' must be a non-empty string— missing or invalidto[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
- createTemplate(builder, register?) — register a template to get a SID
- sendCard(to, card, friendlyName?) — create and send a card in one step
- getMessageStatus(messageSid) — check delivery status after sending
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
