Invalid Entries and Timeouts

The code above will work just fine, until the user presses a key that is not in the range of 1 to 5 or does not press anything at all. If you followed along, you can try to dial 500 and press the extension that was not valid. The call will end immediately.

You can handle invalid entries by sending them to the i extension. If Asterisk can’t find an extension in the current context that matches the digits dialed (e.g. if you press 6 in our example), it will send the call to the i extension.

Let’s try this. Add the following code to the end of the dialplan (in the extensions.conf file):

exten => i,1,Playback(pbx-invalid)
 same => n,Hangup()

Now try to dial 500 again and press 6. You should hear the message informing you that the extension isn’t valid and the call will end.

We also need to handle timeouts – the situations when the caller doesn’t give input in time (the default timeout being 10 seconds). If the user doesn’t respond in time, the call will be sent to the t extension.

Add the following code to the end of the dialplan:

exten => t,1,Playback(press-button-again)
 same => n,Hangup()

Now, if the user doesn’t input anything in 10 seconds, the press-button-again sound will be played.


Geek University 2022