Welcome to GotSpeech.NET Sign in | Help

Marshall Harrison - "the gotspeech guy"

Site news, Speech Server insight and assorted ramblings
Preparing the phone number for dialing

A question came up recently concerning adding the long distance dialing prefix to a phone number. I’ve developed a standard method of setting the outbound phone number. In my application the number to dial as well as the ANI value to use are passed in as part of the URL. I do this mainly because I make over 30,000 calls a day and I didn’t want to slow things down by doing a database lookup to get the phone numbers. I believe that the IVR should be a black box. It makes a call and reports the status – nothing more. No business logic and no database lookups to slow things down or require changes if the business logic changes. But that may be the subject of a future blog so I’ll pass on that for now.

 

 In my applications I set the MakeCall to the value returnd from GetPhoneNUmber() as shown below.

 

            MainMakeCall.CalledDirectoryNumber = GetPhoneNumber();

  

In GetPhoneNumber() I create the number to be dialed by a combination of what I spassed in and the configurations settings found in the web.config. The code below should be fairly easy to follow.

 

            private string GetPhoneNumber()

           {

                 // Get the number from the query string

                string phoneNumber = (string)GetQueryStringValue("PhoneNumber", true);

 

                // Use the outside dialing prefix if one is set

                string outsideLinePrefix = "";

                if (null != ConfigurationSettings.AppSettings["outsideLinePrefix"])

                {

                     outsideLinePrefix = ConfigurationSettings.AppSettings["outsideLinePrefix"];

                }

                 // If there is a hard-coded number in the web.config file, use that

                if (null != ConfigurationSettings.AppSettings["hardCodedNumberToDial"])

                {

                     return(ConfigurationSettings.AppSettings["hardCodedNumberToDial"]);

                }

 

                // Now get the local area code

                string localAreaCode = "";

                if (null != ConfigurationSettings.AppSettings["localAreaCode"])

                {

                     localAreaCode = ConfigurationSettings.AppSettings["localAreaCode"];

                }

                 // Strip anything other than digits from the phone number

                phoneNumber = new Regex("[\\D]").Replace(phoneNumber, "");

                 // If we have 10 digits

                if (phoneNumber.Length == 10)

                {

                     // Remove the area code, if it's the same, otherwise add the long-distance prefix

                     if (0 != localAreaCode.Length &&

                           phoneNumber.StartsWith(localAreaCode))

                     {

                           phoneNumber = phoneNumber.Substring(localAreaCode.Length);

                     }

                     else

                     {                   

// Add the long distance dialing prefix

                           phoneNumber = String.Format("1{0}", phoneNumber);

                     }

                }

                 // If this is an external number (7 digits or more), add the outside line prefix

                if (phoneNumber.Length >= 7)

                     phoneNumber = String.Format("{0}{1}", outsideLinePrefix, phoneNumber);

                 return phoneNumber;

           }

 

 I use the following method for getting parameters off of the URL. If the parameter is required but missing then I throw an exception and the application aborts the call. I’m including this here as it is referenced in the GetPhoneNumber method shown above. If you examine the method above you will see that the number to dial is required – that makes sense huh?

 

 

           internal string GetQueryStringValue(string queryStringKey, bool isRequired)

           {

                string queryStringValue = Server.UrlDecode(Request.QueryString.Get(queryStringKey));

                if (null == queryStringValue)

                {

                     if (isRequired)

                     {

                           throw new ApplicationException(

                                string.Format("Query string does not contain a value for required key \"{1}\".",

                                queryStringKey));

                     }

                     else

                     {

                           queryStringValue = "";

                     }

                }

                return queryStringValue;

           }

 

The web.config looks something like what is shown below. My application normally spoofs the ANI as we are making the calls for someone else and the ANI can change with each call. However, there are times when I want to hard code the ANI for testing purposes so I have a hardCodedANI value that I can set to whatever I need. The outsideLinePrefix only has a value when calls need to go through the PBX. For other calls (i.e. production calls) the prefix is not set. And finally I have a localAreaCode that is set to the area code of wherever the app is running so that I can add the ‘1’ dialing prefix if necessary.

 

     <appSettings>

          <add key="outsideLinePrefix" value="9"/>

          <!--

          <add key="hardCodedANI" value="5555555555"/>

          -->

           <add key="localAreaCode" value="904”/>             

     </appSettings>

 

If you have any questions or a better way of doing this then don’t hesitate to email me or post comments.

 

Posted: Thursday, October 19, 2006 6:02 PM by marshallharrison

Comments

No Comments

Anonymous comments are disabled