Dialplans are broken into sections called contexts. Contexts are named groups of extensions, which serve several purposes.
1. Contexts keep different parts of the dialplan from interacting with one another.
2. An extension that is defined in one context is completely isolated from extensions in any other context, unless interaction is specifically allowed.
3. As a simple example, let’s imagine we have two companies sharing an Asterisk server.If we place each company’s voice menu in its own context, they are effectively separated from each other. This allows us to independently define what happens when, say, extension 0 is dialed: people pressing 0 at Company A’s voice menu will get Company A’s receptionist, and callers pressing 0 at Company B’s voice menu will get Company B’s receptionist. (This example assumes, of course, that we’ve told Asterisk to transfer the calls to the receptionists when callers press 0.)
Contexts are denoted by placing the name of the context inside square brackets ([ ]).
The name can be made up of the letters A through Z (upper- and lowercase), the numbers 0 through 9, and the hyphen and underscore.* For example, a context for incoming calls looks like this:
Please not New things about context
- Space is conspicuously absent from the list of allowed characters. Don’t use spaces in your context names
- Context names have a maximum length of 79 characters (80 characters –1 terminating null)
- All of the instructions placed after a context definition are part of that context, until the next context is defined. At the beginning of the dialplan, there are two special contexts named [general] and [globals]. The [general] section contains a list of general dialplan settings
- you may name your contexts anything you like.
When you define a channel (which is how you connect things to the system), one of the parameters that is defined in the channel definition is the context. In other words, the context is the point in the dialplan where connections from that channel will begin.
Another important use of contexts (perhaps the most important) is to provide security.
By using contexts correctly, you can give certain callers access to features (such as longdistance calling) that aren’t made available to others. If you don’t design your dialplan carefully, you may inadvertently allow others to fraudulently use your system. Please keep this in mind as you build your Asterisk system.