Click or drag to resize
ZenophSMSaddRecipient Method (String, String, Boolean)
Adds a phone number and its personalised values to the destinations list. If the phone number already exists, the values specified for this method call will replace the already existing values.

Namespace: Zenoph.SMSLib
Assembly: Zenoph.SMSLib (in Zenoph.SMSLib.dll) Version: 2015.9.30.0 (2015.09.30.0)
Syntax
public bool addRecipient(
	string phonenum,
	string[] values,
	bool igninv
)

Parameters

phonenum
Type: SystemString
The phone number to be added to the destinations list.
values
Type: SystemString
The personalised values for the destination.
igninv
Type: SystemBoolean
Indicates whether or not the method should throw Exception if either the phone number or personalised values is invalid.

Return Value

Type: Boolean
Returns true if phonenum is added to the destinations list, otherwise it returns false.
Exceptions
ExceptionCondition
Exception Thrown if the message has not already been set or when there are no personalised values. Additionally, if phonenum is invalid or not allowed on user routes and igninv is set to false, Exception will be thrown otherwise the throwing of Exception will be ignored.
Remarks

The method adds a phone number and its personalised values to the destinations list. When adding personalised values for destination, the message must already be set and contain variables. The total number of values must be equal to the number of variables defined in the set message. Additionally, the values must be ordered to match each variable defined in the message.

Examples
// set the message with variables for personalisation.
sms.setMessage("Hello {$name}, meet me at the {$location}.");

// add phone numbers and personalised values.
sms.addRecipient(false, "233207777777", "Daniel", "zoo");
sms.addRecipient(false, "233246111111", "Oppong", "hospital");

Each value must have a matching variable in the message as demonstrated above. The values will be substituted in the message for submission to each destination.

The following is a complete example that sends personalised message. It demonstrates how to add destinations and personalised values matching each variable defined in the message.

using System;
using System.Collections.Generic;
using Zenoph.SMSLib;
using Zenoph.SMSLib.Enums;

namespace SMSTest
{
    class Program
    {
        public static void Main(string[] args)
        {
            try
            {
                // Initialise the SMS object and perform authentication
                ZenophSMS sms = new ZenophSMS();
                sms.setUser("account_login");
                sms.setPassword("account_password");
                sms.authenticate();

                // set the message with variables.
                sms.setMessage("Hello {$name}, the balance in your account is ${$balance}.");

                // add destinations.
                sms.addRecipient("233206111222", new string[] {"Daniel", "540.56"}, false);
                sms.addRecipient("233207222333", new string[] {"Philip", "784.21"}, false);
                sms.addRecipient("233266449999", new string[] {"Mavis", "925.80"}, false);

                // submit the message. For personalised messages, the SMS server will always
                // return a token which can be used to query the submit status of the destinations
                List<string[]> resp = sms.submit();

                // Write the token on screen.
                Console.WriteLine(string.Format("The token for the submitted message is '{0}'.", resp[0][0]));
            }

            catch (SMSException sex)
            {
                // If you are interested in the specific cause of the error
                // use sex.getRequestStatus() to know the specific cause.
                Console.WriteLine("Error: '{0}'.", sex.Message);
            }

            catch (Exception ex)
            {
                Console.WriteLine("Error: '{0}'.", ex.Message);
            }
        }
    }
}

It must be noted from the above code that the message contains three variables and that for each destination added, there are three values specified, each for a variable in the message in the same order. Each destination separately receives a personalised message:

Hello Daniel, the balance in your account is $540.56.

Hello Philip, the balance in your account is $784.21.

Hello Mavis, the balance in your account is $925.80.

See Also