X Enterprises
fastify-xrcs

validate.carousel

Validate a carousel object against RCS constraints without throwing — returns { valid, errors }.

validate.carousel

Validates a plain carousel object against RCS constraints (card count 2–10, consistent button order across cards). Returns a result object with valid and errors — never throws.

Signature

fastify.xrcs.validate.carousel(carousel: object): { valid: boolean; errors: string[] }

Params

NameTypeRequiredDescription
carouselobjectYesA plain carousel object (typically from CarouselBuilder.build())

Returns

{ valid: boolean; errors: string[] }

errors is an empty array when valid: true.

Checks performed:

  • Carousel has at least 2 cards
  • Carousel has no more than 10 cards
  • All cards have buttons in the same order (same types, same positions)

Throws

Does not throw.

Examples

Validate before sending

fastify.post("/send-carousel", async (request, reply) => {
  const { phone, carousel } = request.body;

  const result = fastify.xrcs.validate.carousel(carousel);
  if (!result.valid) {
    return reply.code(422).send({ errors: result.errors });
  }

  return fastify.xrcs.sendCarousel(`+1${phone}`, carousel);
});

Pre-flight check before campaign blast

const carousels = buildCampaignCarousels(data);
const invalid = carousels
  .map((c, i) => ({ i, ...fastify.xrcs.validate.carousel(c) }))
  .filter((r) => !r.valid);

if (invalid.length > 0) {
  throw new Error(`${invalid.length} invalid carousels: ${JSON.stringify(invalid)}`);
}

for (const carousel of carousels) {
  await fastify.xrcs.sendCarousel(phone, carousel);
}

See Also

AI Context

package: "@xenterprises/fastify-xrcs"
method: fastify.xrcs.validate.carousel(carousel)
use-when: Validate a carousel object without throwing — returns { valid, errors } for pre-flight checks
returns: { valid: boolean, errors: string[] }
no-credentials: available in builder-only mode
Copyright © 2026