Skip to content

Telephony Resource

The run.telephony resource provides programmable call control that generates TwiML responses for Twilio webhooks. Supported actions: say, ask, menu, dial, record, hangup, reject, redirect, mute, and unmute.

Basic Usage

yaml
apiVersion: kdeps.io/v1
kind: Resource

metadata:
  actionId: greet
  name: Greet Caller

run:
  telephony:
    action: say
    say: "Hello! Welcome to our service."

Workflow Setup

Enable telephony input in the workflow settings:

yaml
settings:
  input:
    sources: [telephony]
    telephony:
      type: online
      provider: twilio

Actions

answer

Accept the inbound call. Usually the first resource in an IVR workflow.

yaml
run:
  telephony:
    action: answer

say

Speak text to the caller using text-to-speech.

OptionDescription
sayText to speak.
voiceTTS voice (e.g. alice, man, woman).
yaml
run:
  telephony:
    action: say
    say: "Your account balance is available."
    voice: alice

ask

Collect DTMF digits or speech from the caller.

OptionDescription
sayPrompt text.
modedtmf (default), speech, or both.
limitMax digits to collect.
grammarInline GRXML grammar string.
grammarUrlURL to a GRXML grammar file.
timeoutWait time for input (e.g. 5s).
interDigitTimeoutTimeout between digit presses.
terminatorKey that ends input early (e.g. #).
yaml
run:
  telephony:
    action: ask
    say: "Please enter your 4-digit PIN."
    limit: 4
    terminator: "#"
    timeout: 10s

Gather a single digit and branch based on the caller's selection.

OptionDescription
sayPrompt text.
audioAudio URL to play instead of TTS.
matchesList of {keys, invoke} branch descriptors.
onNoMatchAction ID to invoke when no branch matches.
onNoInputAction ID to invoke on timeout.
onFailureAction ID to invoke after max retries.
triesNumber of retry attempts before onFailure.
timeoutInput timeout (e.g. 8s).
yaml
run:
  telephony:
    action: menu
    say: "Press 1 for sales. Press 2 for support."
    timeout: 8s
    matches:
      - keys: ["1"]
        invoke: salesFlow
      - keys: ["2"]
        invoke: supportFlow
    onNoMatch: repeatMenu
    onNoInput: repeatMenu

dial

Transfer the call to one or more SIP URIs or PSTN numbers.

OptionDescription
toList of dial targets (SIP URIs or E.164 numbers).
fromCaller ID to present (optional).
forDial timeout (e.g. 30s).
yaml
run:
  telephony:
    action: dial
    to:
      - sip:agent@pbx.example.com
      - "+15005550001"
    for: 30s

record

Record the caller's audio.

OptionDescription
sayPrompt before recording.
maxDurationMax recording length (e.g. 60s).
interruptibleAllow the caller to press a key to stop recording.
formatAudio format (mp3, wav).
yaml
run:
  telephony:
    action: record
    say: "Leave your message after the beep."
    maxDuration: 60s
    interruptible: true

hangup

Terminate the call.

yaml
run:
  telephony:
    action: hangup

reject

Reject an inbound call before it is answered.

OptionDescription
reasonbusy or rejected (default: rejected).
yaml
run:
  telephony:
    action: reject
    reason: busy

redirect

Redirect the call to another TwiML URL.

OptionDescription
toList with one URL to redirect to.
yaml
run:
  telephony:
    action: redirect
    to:
      - https://example.com/after-hours-ivr

mute / unmute

Mute or unmute the caller's audio leg.

yaml
run:
  telephony:
    action: mute

Session Accessors in Expressions

After an ask or menu action, the session state is available in subsequent resource expressions:

KeyTypeDescription
callIdstringTwilio CallSid
fromstringCaller's number
tostringCalled number
statusstringmatch, nomatch, noinput, hangup, or stop
utterancestringDigits pressed or speech recognized
digitsstringRaw DTMF digits from current request
speechstringRaw speech result from current request
confidencefloat64ASR confidence score (0.0 - 1.0)
matchbooltrue when status == "match"
twimlstringAccumulated TwiML for the current call
yaml
run:
  telephony:
    action: say
    say: "You pressed {{ telephony.utterance }}. Thank you."

TwiML Accumulation

All run.telephony resources in a single workflow execution share one Session. Each action appends TwiML nodes to the same <Response> document. The complete TwiML is returned to Twilio as the HTTP response body at the end of the workflow.

Example: Full IVR

See examples/telephony-ivr/ for a complete IVR workflow with answer, menu, say, dial, record, and hangup.

Released under the Apache 2.0 License.