Page 184 - Asterisk™: The Future of Telephony
P. 184

Next, let’s add an unavailable message that the caller will be played if John doesn’t
               answer the phone within 10 seconds. Remember, the second argument to the Dial()
               application is a timeout. If the call is not answered before the timeout expires, the call
               is sent to the next priority. Let’s add a 10-second timeout, and a priority to send the
               caller to voicemail if John doesn’t answer in time:
                   exten => 101,1,Dial(${JOHN},10)
                   exten => 101,n,VoiceMail(101@default,u)
               Now, let’s change it so that if John is busy (on another call), it’ll send us to his voicemail,
               where we’ll hear his busy message. To do this, we will make use of the ${DIALSTATUS}
               variable which contains one of several status values (see core show application dial
               at the Asterisk console for a listing of all the possible values):
                   exten => 101,1,Dial(${JOHN},10)
                   exten => 101,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavail)
                   exten => 101,n(unavail),Voicemail(101@default,u)
                   exten => 101,n,Hangup()
                   exten => 101,n(busy),VoiceMail(101@default,b)
                   exten => 101,n,Hangup()
               Now callers will get John’s voicemail (with the appropriate greeting) if John is either
               busy or unavailable. A slight problem remains, however, in that John has no way of
               retrieving his messages. Let’s remedy that.

               Accessing Voicemail

               Users can retrieve their voicemail messages, change their voicemail options, and record
               their voicemail greetings by using the VoiceMailMain() application. In its typical form,
               VoiceMailMain()  is  called  without  any  arguments.  Let’s  add  extension  700  to  the
               [internal] context of our dialplan so that internal users can dial it to access their voi-
               cemail messages:
                   exten => 700,1,VoiceMailMain()

               Creating a Dial-by-Name Directory

               One last feature of the Asterisk voicemail system we should cover is the dial-by-name
               directory. This is created with the Directory() application. This application uses the
               names defined in the mailboxes in voicemail.conf to present the caller with a dial-by-
               name directory of the users.

               Directory() takes up to three arguments: the voicemail context from which to read the
               names, the optional dialplan context in which to dial the user, and an option string
               (which is also optional). By default, Directory() searches for the user by last name, but
               passing the f option forces it to search by first name instead. Let’s add two dial-by-
               name directories to the [incoming] context of our sample dialplan, so that callers can
               search by either first or last name:




               156 | Chapter 6: More Dialplan Concepts
   179   180   181   182   183   184   185   186   187   188   189