Skip to main content

Session sayPhrase

About

Speaks a prompt macro using the FreeSwitch say macro API.

Macros should be placed in conf/lang_XX.xml.

Click here to expand Table of Contents

Synopsis

session.sayPhrase(macro_name [,macro_data] [,language] [,dtmf_callback] [,dtmf_callback_args]);
  • macro_name - (string) The name of the say macro to speak
  • macro_data - (string) Optional. Data to pass to the say macro
  • language - (string) Optional. Language to speak macro in (ie. "en" or "fr"). Defaults to "en".
  • dtmf_callback - (function) DTMF callback function name (don't enclose it in quotes!).
  • dtmf_callback_args - (string) Optional. DTMF callback args to pass to the callback function when it is called.

Callback return values and meanings:

  • true or "true" - Causes prompts to continue speaking.
  • Any other value interrupts the prompt and returns the value from the dtmf_callback function

Example

var dtmf_digits = "";

function on_dtmf(session, type, obj, arg)
{
if (type == "dtmf") {
console_log("on_dtmf got digit: " + obj.digit + "\n");
dtmf_digits += obj.digit;
}
return(true);
}

/* Speaks a menu and waits for a single digit press. If the user does not enter a selection */
/* then the menu is repeated up to 3 times. */
function sayivrmenu(ivrsession, menuname, validdigits, timeout) {
var repeat = 0;

console_log("sayivrmenu: menu=[" + menuname + "] validdigits=[" + validdigits + "]\n");

session.flushDigits();
dtmf_digits = "";

while (ivrsession.ready() && dtmf_digits == "" && repeat < 3) {
/* play phrase - if digit keyed while playing callback will catch them*/
ivrsession.sayPhrase(menuname, validdigits, "en", on_dtmf, "");

/* if caller still here and has not entered any selection yet - wait for a selection*/
if (ivrsession.ready() && dtmf_digits == "") {
dtmf_digits = ivrsession.getDigits(1, "", timeout);
/* if still no selection repeat menu */
if (dtmf_digits == "") {
repeat++;
}
}
}
return(dtmf_digits);
}


var menuselection = "";

/** Let's answer our call **/
session.answer();

/** Play our Main Menu prompt (options 0, 1, 2, 3 and #) **/
menuselection = sayivrmenu(session, "mainmenu", "0123#", 6000);

if (session.ready()) {
session.execute("phrase", "saydigits," + menuselection);
}

See Also