X Enterprises
fastify-xrcs

sendCard

Create a card content template and send it to a recipient in one step.

sendCard

Convenience method that creates a twilio/card content template, registers it with Twilio, and sends it to the recipient — all in one call. Internally calls createTemplate then sendMessage.

Signature

fastify.xrcs.sendCard(
  to: string,
  card: CardBuilder | object,
  friendlyName?: string
): Promise<SentMessage>

Params

NameTypeRequiredDescription
tostringYesRecipient phone number in E.164 format
cardCardBuilder | objectYesA CardBuilder instance or a pre-built card object
friendlyNamestringNoFriendly name for the template in Twilio. Defaults to "Card {timestamp}"

Returns

{
  sid: string,
  to: string,
  status: string,
  dateCreated: Date
}

Throws

  • [xRCS] 'to' must be a non-empty string — invalid recipient
  • [xRCS] Twilio credentials required to register templates — no credentials
  • [xRCS] messagingServiceSid required to send messages — no messaging service SID
  • [xRCS] Failed to create template: {message} — Twilio Content API error
  • [xRCS] Failed to send message: {message} — Twilio Messages API error

Examples

Appointment reminder card

fastify.post("/reminders/send", async (request) => {
  const { phone, name, date, location } = request.body;

  const card = fastify.xrcs.card()
    .title(`Appointment: ${date}`)
    .body(`Hi ${name}, your appointment at ${location} is confirmed.`)
    .quickReply("Confirm", "confirm")
    .quickReply("Reschedule", "reschedule");

  return fastify.xrcs.sendCard(`+1${phone}`, card, "Appointment Reminder");
});

Card with media and URL button

const card = fastify.xrcs.card()
  .title("New Arrival")
  .body("Check out our latest product!")
  .media("https://cdn.example.com/product.jpg", "tall")
  .urlButton("View Product", "https://example.com/product/42");

await fastify.xrcs.sendCard("+15551234567", card);

See Also

AI Context

package: "@xenterprises/fastify-xrcs"
method: fastify.xrcs.sendCard(to, card, friendlyName?)
use-when: Create a card template and send it in one step — convenience wrapper over createTemplate + sendMessage
params: to (phone E.164), card (built card object), friendlyName (optional)
returns: { messageSid, contentSid }
requires: Twilio credentials + messagingServiceSid
Copyright © 2026