1. Home
  2. Docs
  3. Programmable SMS
  4. Voice Elements SMS

Voice Elements SMS

We understand how important SMS communication is in our industry.  We have two implementations to choose from to allow you complete control of how you can use SMS in your organization.

    • SMS using your VoiceElements Client – continue reading
    •  SMS via REST API – click here to navigate to this article

 

SMS Using Your VoiceElements Client


 

SMS From Within Your VoiceElements Application

Sending and receiving SMS from within VoiceElements is a snap. It requires version 8.6.3 of the VoiceElements Client which is available on NUGET:

https://www.nuget.org/packages/InventiveLabs.VoiceElementsClient/

Set Encryption Keys

Before you can use SMS, you must set the encryption keys. These keys are unique to your account and you can get the keys for your SMS enabled number(s) from our portal:

https://customer.voiceelements.com/

Setting the keys in code is done at startup:

                   
s_telephonyServer.SmsMyPrivateKeyXml = myCustomerKeyPairXml;
s_telephonyServer.SmsBorderElementsPublicKeyXml = myBorderKeyPairXml;

You should also subscribe to the SMS events to receive SMS messages and delivery reports:

                   
s_telephonyServer.SmsMessage += TelephonyServer_SmsMessage;
s_telephonyServer.SmsDeliveryReport += TelephonyServer_SmsDeliveryReport;

Outgoing SMS

After these are set, you can easily send an SMS message as in this example:

       
public static void SendSms(string number, string smsText)
{
    try
    {
        Guid messageGuid;
        string[] headers;
        string[] sdp;

        var sipStatusCode = s_telephonyServer.SmsSendMessage(smsText, number, fromNumber, null, out messageGuid, out headers, out sdp);
        Log.Write("SMS Result: {0}", sipStatusCode);
    }
    catch (Exception ex)
    {
        Log.WriteException(ex, "SendSms()");
    }
}

Incoming SMS

And then handle incoming SMS messages upon arrival:

       
private static void TelephonyServer_SmsMessage(object sender, SmsMessageEventArgs e)
{
    Log.Write($"Received SMS (From: {e.SmsFrom}, To: {e.SmsTo}): {e.SmsMessage}");
}

Delivery Reports

The system will also give you delivery reports for sent SMS messages:

       
private static void TelephonyServer_SmsDeliveryReport(object sender, SmsDeliveryReportEventArgs e)
{
    if (string.IsNullOrWhiteSpace(e.DeliveryDescription) && e.DeliveryState.ToLower() == "waiting")
    {
        Log.Write($"Received SMS Delivery Report (From: {e.SmsFrom}, To: {e.SmsTo}): Message delivery is pending...");
    }
    else
    {
        Log.Write($"Received SMS Delivery Report (From: {e.SmsFrom}, To: {e.SmsTo}): {e.DeliveryDescription}");
    }
}

Handling Undeliverable Messages

You can also request that any undelivered SMS messages be sent to you. These would be messages that may have arrived while your application was offline.

               
try
{
    string[] headers;
    string[] sdp;
  
    var result = s_telephonyServer.SmsRequestUndeliveredMessages(out headers, out sdp);
    Log.Write($"Requesting undelivered SMS messages.  Result: {result}");
}
catch { }

Interested in SMS Via REST API?

If you would like to know more about our REST API, please see our article SMS via REST API and SMS REST API Reference Guide.

Please contact us if you have any questions!

We invite you to schedule a free consultation with our Tech Team to explore your project goals and how we can help you get quickly into production.

Was this article helpful to you? Yes 18 No