System information

If ${Result} is not null, the next steps will clean up ${Result} in order to extract the
extension number
*
of the user with the name passed in ${ARG1}:
Set(LOCAL(ExtensionToDial)=${CUT(${LOCAL(Result)},=,1)})
The CUT() function will use the = symbol as the field delimiter and will assign the value
from the first field found in ${Result} to the new variable ExtensionToDial. From there,
we simply need to trim any trailing spaces by filtering all nonnumeric characters:
Set(LOCAL(ExtensionToDial)=${FILTER(0-9,${LOCAL(ExtensionToDial)})})
We can now return the extension number of the name we received:
Return(${LOCAL(ExtensionToDial)})
This example was something we whipped up for the purposes of illustrating some
methods you can employ in order to easily match names to extension numbers for the
purposes of SIP URI dialing. This is by no means the best way of doing this, but it is
fairly simple to implement, and in many cases may be all that you need.
Database lookup
Using a database is by far the best way to handle user information on larger, more
complex systems. We will discuss integrating Asterisk with databases in more detail in
Chapter 16, but it is useful to introduce the concept here.
A database is ideal for handling name lookup, as it makes maintenance of user data
(and integration with external systems such as web interfaces) far simpler. However, it
does require a bit more effort to design and implement.
The example we will use in this chapter will work, but for a production environment
it is probably too simplistic. Our goal here is simply to give you enough information to
understand the concept; a tighter integration is part of what is covered in Chapter 16.
First, we’ll need a table to handle our name-to-extension mapping. This could be a
separate table from the main user table, or it could be handled in the main user table,
provided that that table contains a field that will contain the exact strings that users
will publish as their SIP URIs (as an example, some companies have rules regarding
how email addresses look, so Leif might have a URI such as lmadsen@shifteight.org,
or leif.madsen@shifteight.org).
If you are serious about implementing this example in a production
system, make sure you are familiar with the material in Chapter 16, as
some key concepts are covered there that we omit here.
Our sample NameMapping table looks like Table 12-2.
* In actual fact, what we are extracting is the voicemail box number; however, this number is generally going
to be the same as the user’s dialable internal extension number. If it is not the same, this particular technique
will not accomplish name-to-extension lookups, and another way will have to be found.
244 | Chapter 12:Internet Call Routing