ctx

ctx

A class 5 real-time interface

Example

async function main(data, ctx) {
	 await ctx.answer();
	 await ctx.tts('Call was successful. Hello World!');
	 await ctx.hangup();
}

Methods

(static) answer() → {Promise}

Source:

Answer Call

Example
await ctx.answer()
Returns:
Type
Promise

(static) blockDtmf() → {Promise}

Source:

Block DTMF

Example
await ctx.blockDtmf()
Returns:
Type
Promise

(static) bridge(destination, continue_on) → {Promise}

Source:

Bridges the call with another destination, returns a promise when complete containing the bleg context.

Examples
await ctx.bridge('160')
await ctx.bridge('441234567890')
Parameters:
Name Type Description
destination string
continue_on string

Continue on true, false, 'fail', 'completed'

Returns:
Type
Promise

(static) echo(delayopt) → {Promise}

Source:

Echo

Examples
await ctx.echo()
await ctx.echo(500)
Parameters:
Name Type Attributes Description
delay number <optional>

Value in milliseconds

Returns:
Type
Promise

(static) get(Key) → {string}

Source:

Get Variable

Example
ctx.get('myVar')
Parameters:
Name Type Description
Key string
Returns:

Value

Type
string

(static) hangup() → {Promise}

Source:

Hang Up

Example
await ctx.hangup()
Returns:
Type
Promise

(static) header(Key, Value)

Source:

Get / Set Header

Examples
header('X-My-Header', 'myVal')
var value = ctx.header('X-My-Header')
Parameters:
Name Type Description
Key string
Value string

(static) ivr(file, timeout, min, max, terminators, opts) → {Promise.<Object>}

Source:

Interactive Voice Response - IVR

Examples
var {status, value} = await ctx.ivr('user/myGreeting.wav', 1, 5, 10)
var {status, value} = await ctx.ivr('ivr/ivr-aint_nobody_got_time_for_that.wav', 10, 10, 5)
Parameters:
Name Type Description
file string

Audio Filename

timeout number

How many seconds to wait (after audio is completed)

min number

Minimum Digits to be captured

max number

Maximum Digits to be captured

terminators string

Characters to end input such as #

opts Object

Additional Options

Properties
Name Type Description
tries number

How many attempts to allow

invalid_file string

Invalid file

regexp string

Regular Expression to validate input

transfer_on_failure string

Destination to transfer to for failure

Returns:
Type
Promise.<Object>

(static) log(Text)

Source:

Log Information

Example
ctx.log('Hello World!')
Parameters:
Name Type Description
Text string
Returns:

null

(static) play(file) → {Promise}

Source:

Play

Examples
await ctx.play('user/myGreeting.wav')
await ctx.play('ivr/ivr-aint_nobody_got_time_for_that.wav')
Parameters:
Name Type Description
file string
Returns:
Type
Promise

(static) record(filename) → {Promise}

Source:

Record Call

Parameters:
Name Type Description
filename string

Filename without extension

Returns:

Promise returns after call recording has successfully started

Type
Promise

(static) set(Key, Value)

Source:

Set Variable

Example
ctx.set('myVar', 'myVal')
Parameters:
Name Type Description
Key string
Value string

(static) tts(text) → {Promise}

Source:

Text-To-Speech

Example
ctx.await tts('Thank you for calling.')
Parameters:
Name Type Description
text string
Returns:
Type
Promise

(static) waitFor(match, failMatch) → {Promise}

Source:

Wait For (DTMF Sequence)

Examples
try {
  var keys = await ctx.waitFor('\d{4}' '*', 3000);
  process(keys)
} catch (err) {
  // Continue
}
function fn(value) {
  return value > 1000;
  // You can fail a match by throw new Error('fail');
}
try {
  var keys = await ctx.waitFor(fn, '*');
  process(keys);
} catch (err) {
  // Continue
}
// Ignore any previously entered numbers, just capture look at the last part with a Regular Expression
try {
  var keys = await ctx.waitFor(/00$/, '*');
  process(keys);
} catch (err) {
  // Continue
}
// Wait for multiple events
ctx.waitFor(/00$/, '*').then(keys => { // Do Stuff});
ctx.waitFor(/11$/, '*').then(keys => { // Do Stuff});
Parameters:
Name Type Description
match string | RegExp | waitForMatch

Positive Match

failMatch string | RegExp | waitForMatch

Negative Match (How to escape menu)

Returns:

String or RegEx in match, will return string, will return truthy result for match as a function

Type
Promise

(static) waitForHangup() → {Promise}

Source:

Wait For Hang Up

Returns:

Promise returns after the call has completed

Type
Promise

Type Definitions

waitForMatch(match) → {*}

Source:

Call back function waitForMatch to be used as match in waitFor

Parameters:
Name Type Description
match string

Text to be matched against

Returns:

result Truthy will match

Type
*