Programmable Voice

  1. Home
  2. Docs
  3. Programmable Voice
  4. How do I
  5. Write Outbound Dialer Applications in C#

Write Outbound Dialer Applications in C#

A common use for Telephony Software is to create Dialer applications. Here are a few examples of outbound applications:

  • Survey Software
  • Appointment Reminders
  • Market Research
  • Political Polling
  • Alerts / Notifications
  • Lead Generation
  • Predictive Dialers

Using Voice Elements it’s easy to write any type of outbound application. Below is an example of a simple application.

        
public void RunSript()
{
    try
    {
        try
        {
            ChannelResource = TelephonyServer.GetChannel();
            DeviceName = ChannelResource.DeviceName;
            VoiceResource = ChannelResource.VoiceResource;
        }
        catch (Exception ex)
        {
            Log.Write("Could not get Channel Resource");
        }
 
        // When set to analyze call it will use CPA
        ChannelResource.CallProgress = CallProgress.AnalyzeCall;
 
        // The Phone Number is passed in prior to dialing
        DialResult dr = ChannelResource.Dial(PhoneNumber);
        switch (dr)
        {
            case DialResult.HumanDetected:
                VoiceResource.PlayTTS("This is a message for a human");
                break;
            case DialResult.MachineDetected:
                VoiceResource.PlayTTS("This is a message for a machine");
                break;
        }
        Log.WriteWithId(DeviceName, "Done with Outbound Call");
    }
    catch (HangupException hex)
    {
        Log.WriteWithId(DeviceName, "Caller Hungup!");
    }
    catch (Exception ex)
    {
        Log.WriteException(ex, "Unexpected exception: {0}", DeviceName);
    }
    finally
    {
        if (ChannelResource != null)
        {
            try
            {
                ChannelResource.Disconnect();
            }
            catch { }
 
            try
            {
                ChannelResource.Dispose();
            }
            catch { }
        }
    }
}

 

A Few Key Points

There are a couple of different Dial Modes: AnalyzeCall, and WaitForConnect.

AnalyzeCall will analyze the first second or two of audio to determine what answered the phone call (Machine, Human, FaxMachine, etc). This is known as CallProgress. Voice Elements has industry leading Call Progress capabilities.

Alternatively, you can use WaitForConnect mode that will return as soon as HMP Elements gets a Connected message back from the carrier. This can be especially useful when using our Beep Detector. In our tests we’ve seen 98.5% accuracy when using our Beep Deteector.

More Information On Placing More Than One Call At A Time

You will want to use a different thread for each instance of an outbound call that you would like to make. Here’s some mock code that shows how to start a thread for each individual outbound call:

            
while (true)
{
    List<string> phoneNumbers = GetPhoneNumbers(); // Pull these from a database
    if (phoneNumbers.Count == 0)
    {
        System.Threading.Thread.Sleep(1000);
        break;
    }
    foreach(string phoneNumber in phoneNumbers)
    {
        OutboundIVR instance = new OutboundIVR(IvrApplication.s_TelephonyServer, IvrApplication.Log);
        instance.PhoneNumber = phoneNumber;
        Thread oThread = new Thread(instance.RunSript);
        oThread.Start();
    }
}

 

As shown in the example, above you’ll want to make sure that each call uses its own thread. If you aren’t comfortable creating your own threads, we’ve built some additional features into Voice Elements that handle this for you. In addition, you may want to consider using a ThreadPool to minimize the overhead associated with starting up a new thread.

Other Thoughts

We also include some helper classes that make dialing even easier.

Voice Elements is an excellent platform for building your dialer software, for the following reasons:

Robust — Customers using our software make millions of calls a year. Scalable — A single server can handle up to 1000 concurrent calls Excellent Pricing — Our pricing is extremely competitive, with prices beginning at $40 a port for our SIP stack, and toolkit and becomes cheaper as you buy more ports. Excellent Support — We’re here to help you every step of the way with your Voice Application. Experience — Our team has built hundreds of Voice Applications and are willing to share with you their expertise as you develop your application.

Was this article helpful to you? Yes 8 No

How can we help?