Session collectInput

From FreeSWITCH Wiki
Jump to: navigation, search

Blocks the channel and collects input such as DTMF digits.


session.collectInput( ) blocks the channel. As input happens, the listed callback function is executed passing the input (among other things) as arguments. The call blocks until either the function returns "false" or the timeout (given in milliseconds) has expired.

Note: If you want to play something to the user while waiting for input, use Session_streamFile instead.


session.collectInput( callbackFunction, callbackArguments, digitTimeoutInMilliseconds, absoluteTimeoutInMilliseconds );


Here, the function "mycb" is called every time input happens. If it is a DTMF digit, it is appended to the dtmf variable. (in dtmf.digits) After either 10 digits are collected or the 8000 millisecond (8 second) timeout expires, the result is printed to the console log and the call ends.

function mycb( session, type, data, arg ) {
  if ( type == "dtmf" ) {
    arg.digits += data.digit;
    if ( arg.digits.length >= 10 ) {
      return( true );

  return( true );


var dtmf = new Object( );
dtmf.digits = "";

if ( session.ready( ) ) {
  session.answer( );
  session.streamFile( "sounds/typeSomeDigits.wav" );
  session.collectInput( mycb, "dtmf", 3000, 0);
  console_log( "info", "Got " + dtmf.digits + "\n" );
  session.streamFile( "sounds/thanksBye.wav" );
  session.hangup( );


See Also: Session_streamFile