What are Contexts and Extensions

Contexts and Extensions

After the [general] and [globals] categories, the remainder of the extensions.conf file is taken up by the definition of the Dialplan. The Dialplan consists of a collection of contexts. Each context consists of a collection of extensions. For an introduction to these topics:.

    • Introducing Contexts and Extensions

The Dialplan consists of a collection of contexts. These context definitions are the most important part of the extensions.conf file and are the most important part of Asterisk configuration.

A context is just a collection of extensions. Here is a diagrammatic representation (i.e. not something you’d type into your extensions.conf file!) of a simple example context:

Context “default”:

Extension Description

101 Mark Spencer

102 Wil Meadows

103 Greg Vance

104 Check voicemail

105 Conference Room

0 Operator

In this example context, which has been given the name “default”, the first three extensions (101 to 103) all would be associated with ringing phones belonging to various employees. The fourth extension (104) would be associated with allowing someone to check their voicemail. The fifth extension (105) would be associated with a conference room. Finally, the “0” extension would be associated with the operator.

Here is another simple example of a context:

Context “mainmenu”:

Extension Description

s Welcome message and instructions

1 Sales

2 Support

3 Accounting

9 Directory

Hangup

This example context, given the name “mainmenu”, has only single-digit extensions. The “s” extension is the start extension, where the caller begins. This extension would play a message along the lines of “Thank you for calling OurCompany. Press 1 for sales, 2 for support, 3 for accounting, 9 for a company directory, or # to hangup.” Each menu option is, in fact, an extension and could either dial someone’s real extension or could do something like sending the caller to another menu.

Contexts can be used to implement a number of important features including:

    • Security: Permit long distance calls from certain phones only
    • Routing: Route calls based on extension
    • Autoattendant: Greet callers and ask them to enter extensions
    • Multilevel menus: Menus for sales, support, etc.
    • Authentication: Ask for passwords for certain extensions
    • Callback: Reduce long distance charges
    • Privacy: Blacklist annoying callers from contacting you
    • PBX Multihosting: Yes, you can have “virtual hosts” on your PBX
    • Daytime/Nighttime: You can vary behavior after hours
    • Macros: Create scripts for commonly used functions

How Are Contexts Used?

When Asterisk receives a call connection, whether an incoming call from outside, or from an internal extension, that call belongs to a context. Which context the call belongs to depends on what channel the call came in on. When you configured the channels that you have on your Asterisk PBX, one of the things you had to do was to define what context an incoming connection on that channel would be put into, using a definition like:

context=incoming

So the first way contexts are used is to make Asterisk do different things depending on where a call is coming from. You most likely will have at least one context defined for how Asterisk handles an incoming call on your telephone line: it might ring some of your extensions or play an announcement and record a voicemail message. You want Asterisk to handle connections from your internal extensions differently — they will be permitted to dial a different extension, or make an outgoing call — so you define that calls from those different channels go into different contexts.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.