Click or drag to resize
ZenophSMSsubmit Method
Submits the composed message to the SMS server for submission to the added destinations.

Namespace: Zenoph.SMSLib
Assembly: Zenoph.SMSLib (in Zenoph.SMSLib.dll) Version: 2015.9.30.0 (2015.09.30.0)
Syntax
public List<string[]> submit()

Return Value

Type: ListString
Returns either the submit responses for each destination or a token to be used for querying submit status.
Exceptions
ExceptionCondition
SMSException Thrown when the SMS server returns with an error.
Exception Thrown for any other non-caught exceptions
Remarks

The value returned from this method is dependent on the type of message submitted as well as the total number of destinations submitted.

When sending non-personalised messages, the method returns either the submit status of the destinations or a token that can be used to query the submit status of the destinations. What is returned depends the total number of destinations submitted. If the total number of destinations submitted is less than the maximum submit value that is returned by getBatchSubmitMax, the submit status of destinations will be returned in a List of System.String[] of length 2 with the submit status in the first index (0) and the destination in the second index (1).

// Initialise the SMS object and perform authentication
ZenophSMS sms = new ZenophSMS();
sms.setUser("account_login");
sms.setPassword("account_password");
sms.authenticate();

// set message parameters.
sms.setMessage("Hello there!");
sms.setSenderId("SMSTEST");
sms.setMessageType(MSGTYPE.TEXT);

// add destinations, (assuming the default international dial code set is +233)
sms.addRecipient("0209665544"); // exception will be thrown if destination is invalid.
sms.addRecipient("0591324522", true);   // throwing of exception will be ignored if destination is invalid.
sms.addRecipient("0801435621", false);  // exception will be thrown if destination is invalid.

// submit the message
List<string[]> resp = sms.submit();

/*
 * supposing the total destinations submitted is less than the maximum submit value
 * in order to immediately obtain submit status of the destinations, then the submit
 * status of the destinations were returned and we can access and print them on screen
 */
foreach (string[] status in resp)
    Console.WriteLine(string.Format("Phone Number: {0},  Status: {1}", status[1], status[0]));

The output of the above code will be as follows:

Phone Number: 233209665544, Status: 1400

Phone Number: 233591324522, Status: 1400

Phone Number: 233801435621, Status: 1400

Status will be a value that corresponds to the REQSTATUS enumeration and can be used to check whether message was submitted to a destination or not.

For total destinations greater than the maximum submit value required for immediately obtaining submit status of destinations as well as personalised messages submitted, the method always returns a token that can be used to query the submit status of the destinations. Since the method returns a list of array of System.String, the token is placed in the first index of the array in the first item of the list.

// submit the message.
List<string[]> resp = sms.submit();

// get the token
string token = resp[0][0];

If an application is interested in the submit status of destinations in this case, getSubmitStatus(String, STATUSQUERY) can be called with the obtained token at some intervals to obtain the submit status of the destinations. For full details on how to implement this, see the discussion on getSubmitStatus(String, STATUSQUERY).

For non-personalised messages, the correct way to handle submit responses is to compare the total number of destinations submitted with the maximum submit value for immediately obtaining the submit status of the destinations as shown below:

// submit the message.
List<string[]> resp = sms.submit();

// we should know how we will handle the response.
if (sms.getRecipientsCount() > ZenophSMS.getBatchSubmitMax())    // a token was returned
{
    string token = resp[0][0];

    // querying of the submit status can be done at some intervals with the token
}

else    // submit status of the destinations were returned.
{
    // processing can be done. let's print the submit status
    foreach (string[] status in resp)
        Console.WriteLine(string.Format("Phone Number: {0},  Status: {1}", status[1], status[0]));
}

Examples
The following example sends non-personalised message and demonstrates how to process submit response.
using System;
using System.Threading;
using System.Collections.Generic;
using Zenoph.SMSLib;
using Zenoph.SMSLib.Enums;

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

            // set the non-personalised message.
            sms.setMessage("Hello there!");
            sms.setSenderId("SMSTEST");
            sms.setMessageType(MSGTYPE.TEXT);

            // add destinations.
            sms.addRecipient("0207711111");
            sms.addRecipient("233240999999");

            // we can even extract destinations from a string that contains phone numbers.
            string str = "P.O.Box 13, Kumasi, Tel: 0206199999; P.O.Box U.P. 871, Kumasi, Tel: 233291888222";

            // the following will return the numbers 233206199999, 233291888222 
            // (assuming the default international dial code set is +233)
            List<string> dest = sms.extractPhoneNumbers(str);

            foreach (string num in dest)
                sms.addRecipient(num, true);  // ignore throwing of exception if number is invalid or not allowed.

            // we can submit the destinations.
            List<string[]> resp = sms.submit();

            // see how we are to process the response
            if (sms.getRecipientsCount() > ZenophSMS.getBatchSubmitMax())  // a token was returned.
            {
                string token = resp[0][0];

                // request for submit status at some intervals.
                requestStatus(token, sms);
            }

            else  // status of the destinations were returned.
            {
                // print them on screen.
                foreach (string[] state in resp)
                    Console.WriteLine(string.Format("Phone Number: {0},  Status: {1}", state[1], state[0]));
            }
        }

        // the processing can be setup to run at some intervals. Here it is not done so.
        static void requestStatus(string token, ZenophSMS sms)
        {
            // The STATUSQUERY enumeration can be used to define which status we are interested in
            // Let's assume we want those submitted and those pending submission. We can separate each with a comma
            Dictionary<STATUSQUERY, List<string>> st = null;

            do
            {
                Thread.Sleep(5000);
                st = sms.getSubmitStatus(token, STATUSQUERY.PENDING);   // only want to know if some are pending.
            } while (Convert.ToInt32(st[STATUSQUERY.PENDING][0]) > 0);

            // at this point all message has been submitted to all destinations.
            // If we are interested in the destinations and their states, we can do that below
            st = sms.getSubmitStatus(token, true, STATUSQUERY.SUBMITTED, STATUSQUERY.REJECTED);

            // we can obtain them separately.
            List<string> submitted = st[STATUSQUERY.SUBMITTED];
            List<string> rejected  = st[STATUSQUERY.REJECTED];

            // we can do what we want to do with the returned data.

        }
    }
}
See Also