Getting started with the debugger

From SoftIVR

Jump to: navigation, search

Getting started with the SoftIVR debugger

While a simple service like the one you've just created can be expected to just work, anything more complex may need development and debugging. SoftIVR includes a real-time code execution monitor, which allows you to see how your code executes, track the values of variables, see log messages and so on. To turn debugging on for the script you've just written, add a comment to the start of the script as follows:

//DEBUG=1

so that the script now looks like this:

//DEBUG=1
// Answer the incoming call
answer();
// This causes the following block of code to repeat forever
while (1) {
	// Play a tone at 800Hz (a medium-pitched beep) for 0.2 seconds
	playtone(800, 0.2);
	// Do nothing for 0.8 seconds
	sleep(0.8);
}

Select the 'debug' tab, call the service again, and you'll see the code appear, along with a moving indicator to show which line is currently being executed. The debugger can also track variables: to see this in action, we'll modify the script to only beep 20 times and then terminate, and add a watch to the variable used to count the 20 beeps.

//DEBUG=1
// Answer the incoming call
answer();
// Beep 20 times
i = 20;
varWatch("i"); // Watch this variable in the debugger
while (i > 0) {
	// Play a tone at 800Hz (a medium-pitched beep) for 0.2 seconds
	playtone(800, 0.2);
	// Do nothing for 0.8 seconds
	sleep(0.8);
	i = i-1;
}

Call again, and you should see the variable appear in the watch list, and be able to see how it changes. Lastly, the IVR has a log, which can be used for debugging or simply to keep track of what's going on. Edit the code further so that it now reads:

//DEBUG=1
// Answer the incoming call
answer();
log("Inbound call answered - beep at the caller");
// Beep 20 times
i = 20;
varWatch("i"); // Watch this variable in the debugger
while (i > 0) {
	// Play a tone at 800Hz (a medium-pitched beep) for 0.2 seconds
	playtone(800, 0.2);
	// Do nothing for 0.8 seconds
	sleep(0.8);
	i = i-1;
}
log("20 beeps is enough.");

Call in again, and you'll see the log messages appear. At the end of the call, the debug information will disappear but, if you select the 'log' tab, you'll see the last 50 entries in the IVR log.

Next: extensions.