Handling script variables
Most VoipScript commands receive parameters as input and set script variables as output.
For instance, the command "get input" receives, among other parameters, a "prompt" to be played to the user. After it is executed, the "get input" command sets the script variable input_digits with the digits typed in.
$prompt = 'Please type your zip code after the beep';
$script->addGetInput($prompt);
$script->addSay("You typed %input_digits");
In the example above, note the % symbol in the string passed to the "say" command. Whenever VoIP Drupal finds the % symbol in a string, it tries to replace it by the contents of the script variable whose name immediately follows that symbol.
Similarly, using the t() function to translate the parameter strings:
$prompt = 'Please type your zip code after the beep';
$script->addGetInput($prompt);
$args = array('@input' => '%input_digits');
$script->addSay(t("You typed @input", $args));
The "set" command can be used to store values in script variables. For instance, in the code below
global $user;
$script->addSet('name', $user->name);
$script->addSet('password', '%input_digits');
the variable "name" will be set to the user's name, whereas the variable "password" will be set to the contents of "input_digits".
Script variables are created during the first time that they are "set". In order to remove them, use the "unset" command:
$script->addUnset('name');
$script->addUnset('password');
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion