Values

XML_DECLARATION

XML_DECLARATION: Str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"

Functions

attr-value

fn (value: Any): Str

attrs-string

fn (attrs: Map): Str

Render an attribute Map as name="value" pairs in key order. Nulls are omitted. Exposed for testing.

body

fn (text: Str): Str

<Body> noun inside message: the text of an MMS reply.

client

fn (identity: Str): Str
fn (identity: Str, attrs: Map): Str

<Client> noun inside dial: a Twilio Voice SDK identity. Attributes: url, method, statusCallback, statusCallbackEvent.

conference

fn (name: Str): Str
fn (name: Str, attrs: Map): Str

<Conference> noun inside dial: join a named room. Attributes: startConferenceOnEnter, endConferenceOnExit, muted, beep, record, waitUrl, maxParticipants, statusCallback, statusCallbackEvent.

dial

fn (target: Any): Str
fn (target: Any, attrs: Map): Str

<Dial>: connect the caller to another party. target is a phone number or SIP/client text, or a Vec of noun fragments (number, client, sip, conference, queue) to ring at once. Attributes: callerId, action, method, timeout, timeLimit, record, recordingStatusCallback, answerOnBridge, hangupOnStar, ringTone, trim, sequential.

Example

::twiml ::twilio::twiml

::twiml/dial("+15558675310", {callerId: "+15017122661", timeout: 20})
::twiml/dial([::twiml/number("+15558675310"), ::twiml/client("alice")])

element

fn (tag: Str, attrs: Map, content: Any): Str

Build one TwiML element. content is text (escaped), a Vec of nested fragments (inserted as-is), or null/empty for a self-closing element. The building block of every verb here, and the way to emit a verb or noun this module doesn't wrap (e.g. <Stream>, <Pay>).

Example

::twilio::twiml/element("Leave", {}, null)  // => "<Leave/>"

enqueue

fn (name: Str): Str
fn (name: Str, attrs: Map): Str

<Enqueue>: place the caller in a named queue. Attributes: action, method, waitUrl, waitUrlMethod, maxQueueSize, workflowSid.

escape-xml

fn (value: Any): Str

Escape text for XML content or attribute values: &, <, >, ", and '.

Example

::twilio::twiml/escape-xml("Tom & Jerry <3")  // => "Tom &amp; Jerry &lt;3"

gather

fn (attrs: Map): Str
fn (attrs: Map, nested: Vec<Str>): Str

<Gather>: collect DTMF digits or speech, then POST them (Digits / SpeechResult) to action. Attributes: input ("dtmf", "speech", or "dtmf speech"), action, method, timeout, numDigits, finishOnKey, speechTimeout, speechModel, language, hints, actionOnEmptyResult, partialResultCallback, profanityFilter, bargeIn. nested holds the say/play/pause prompts.

hangup

fn (): Str

<Hangup>: end the call.

http-response

fn (twiml: Str): ::hot::http/HttpResponse

Wrap a TwiML document as the webhook's HttpResponse (status 200, Content-Type: text/xml).

Example

::twiml ::twilio::twiml

on-sms
meta {webhook: {service: "twilio", path: "/sms"}}
fn (request: ::hot::http/HttpRequest): ::hot::http/HttpResponse {
  reply ::twiml/message(`You said: ${or(request.body.Body, "")}`)
  ::twiml/http-response(::twiml/messaging-response([reply]))
}

media

fn (url: Str): Str

<Media> noun inside message: a public URL of an image or file to attach (up to 10).

message

fn (content: Any): Str
fn (content: Any, attrs: Map): Str

<Message>: reply to an inbound SMS/MMS/WhatsApp. content is the reply text, or a Vec of body / media fragments for MMS. Attributes: to, from, action, method, statusCallback.

Example

::twiml ::twilio::twiml

::twiml/message("Thanks!")
::twiml/message([::twiml/body("Here's the map"), ::twiml/media("https://example.com/map.png")])

messaging-response

fn (verbs: Vec<Str>): Str

A messaging TwiML document around message/redirect fragments. An empty Vec answers without replying.

Example

::twiml ::twilio::twiml

xml ::twiml/messaging-response([::twiml/message("Got it, thanks!")])

number

fn (phone: Str): Str
fn (phone: Str, attrs: Map): Str

<Number> noun inside dial. Attributes: sendDigits, url, method, statusCallback, statusCallbackEvent, machineDetection.

pause

fn (): Str
fn (length: Int): Str

<Pause>: wait silently for length seconds (default 1).

play

fn (url: Str): Str
fn (url: Str, attrs: Map): Str

<Play>: play an audio URL. Attributes: loop, digits (send DTMF instead; pass "" as the URL).

queue

fn (name: Str): Str
fn (name: Str, attrs: Map): Str

<Queue> noun inside dial: take the next caller from a queue. Attributes: url, method.

record

fn (): Str
fn (attrs: Map): Str

<Record>: record the caller (voicemail). The recording URL is POSTed to action. Attributes: action, method, timeout, finishOnKey, maxLength, playBeep, trim, recordingStatusCallback, recordingStatusCallbackEvent, transcribe, transcribeCallback.

redirect

fn (url: Str): Str
fn (url: Str, attrs: Map): Str

<Redirect>: continue with the TwiML at another URL (voice or messaging). Attribute method (default POST).

reject

fn (): Str
fn (attrs: Map): Str

<Reject>: decline an incoming call without billing it. Attribute reason: "rejected" (default) or "busy".

say

fn (text: Str): Str
fn (text: Str, attrs: Map): Str

<Say>: speak text. Attributes: voice (e.g. "Polly.Joanna", "Google.en-US-Neural2-F"), language, loop.

sip

fn (uri: Str): Str
fn (uri: Str, attrs: Map): Str

<Sip> noun inside dial: a SIP URI. Attributes: username, password, url, method, statusCallback.

voice-response

fn (verbs: Vec<Str>): Str

A voice TwiML document: <?xml ...?><Response>...</Response> around the given verb fragments.

Example

::twiml ::twilio::twiml

xml ::twiml/voice-response([
  ::twiml/say("Thanks for calling.", {voice: "Polly.Joanna"}),
  ::twiml/gather({input: "dtmf speech", numDigits: 1, action: "/twilio/menu"}, [
    ::twiml/say("Press 1 for sales, 2 for support.")
  ]),
  ::twiml/say("We didn't get that. Goodbye."),
  ::twiml/hangup()
])