Contexts
As we’ve already learned, contexts in Asterisk are used to keep different parts of the dialplan from interacting with each other. An extension defined in one context is isolated from extensions in any other context (unless the interaction is specifically enabled using the Goto application). Contexts are used to separate out Asterisk functionality and features, enforce security boundaries between the various parts of the dialplan, and provide different classes of service to different groups of users. For example, calls coming from the outside usually reside in a different context than the calls initiated from our internal network.
It is important to remember that a context in Asterisk is the point in the dialplan where connections from that channel will begin. The context setting defined in the channel configuration file (e.g. sip.conf) specifies how you plug the channel into the dialplan. Here is a graphical representation of this process:
Contexts are defined in the extensions.conf file, which is usually located in /etc/asterisk. They are defined inside the square brackets ([]). The name of a context can be made up of the letters A to Z (upper- and lowercase), the numbers 0 through 9, the hyphen and underscore. For example, [from-internal] is a valid name for a context.