In the previous lesson we added the VoiceMail() application. In this lesson we will modify the dialplan to send busy calls to voicemail.
There is a variable named DIALSTATUS that is set after the Dial() application to determine the last status of it. We can use this to determine whether or not it was busy when the SIP account was dialed. To use the value of the variable it is written as ${DIALSTATUS}.
There is a conditional application called GotoIf() within Asterisk that allows us to code based on whether a condition is true of false. Using the DIALSTATUS variable combined with GotoIf() we can then direct Asterisk to a new extension if the line was busy.
Modify extension 100 to match the code below. It now has the GotoIf() application that checks to see if the DIALSTATUS variable is equal to BUSY. If it is, Asterisk them moves to a new extension we will call 100-busy, and it will go to the first line of code on that extension.
exten => 100,1,NoOp(Call for matthew)
same => n,Dial(SIP/matthew,5)
same => n,GotoIf($["${DIALSTATUS}" = "BUSY"]?100-busy,1)
same => n,VoiceMail(100@default)
same => n,Hangup
Now lets add extension 100-busy to the dialplan. Use the code below:
exten => 100-busy,1,VoiceMail(100@default)
same => n,Hangup
The dialplan will now need to be reloaded in the Asterisk console. After that it should now call the Voicemail() application after 5 seconds with no answer and also if the line is busy.