Function asString

  • Coercion helpers for flow submission values.

    A flow.completed payload's submission is Record<string, unknown> — WhatsApp delivers everything as strings/arrays/objects and validation happened server-side, but the static type can't know each field's shape. These helpers coerce a single value safely (returning undefined when absent or unparseable), and coerceSubmission applies a field-type map across a whole submission.

    Parameters

    • value: unknown

    Returns undefined | string

    const budget = asNumber(event.payload.submission.budget);   // number | undefined
    const when = asDate(event.payload.submission.preferred_date); // Date | undefined