Click or drag to resize
ZenophSMSsetMessage Method
Sets the message that will be submitted to the recipients.

Namespace: Zenoph.SMSLib
Assembly: Zenoph.SMSLib (in Zenoph.SMSLib.dll) Version: 2015.9.30.0 (2015.09.30.0)
Syntax
public void setMessage(
	string msg
)

Parameters

msg
Type: SystemString
The message to be submitted to the recipients.
Exceptions
ExceptionCondition
Exception Thrown if msg is null or empty.
Remarks

The method sets the message that will be delivered to mobile destinations added to the destinations list. There are certain issues that must be clearly understood when calling this method.

When overwriting a previously set message, the method checks whether the set message contains variables for personalising message. If the previously set message has one or more variables defined in it, the method will clear the destinations list without notice before setting the new message. Again, if the new message to be set has variables defined in it, the destinations list will be cleared without notice and the new message will be set to replace the previous one.

Thus, when overwriting a previously set message, the destinations list will be maintained only if both the new message and the previously set message do not have variables defined in them. Contrary to this, the added destinations will be cleared for the new message to replace the previously set one.

Another important issue is that when sending personalised SMS, the message must be set before any phone numbers are added to the destinations list. For personalised messaging, if addRecipient(String, String) or addRecipient(String, String, Boolean) is called to add a destination before the message is set, Exception will be thrown.

Examples

The following code demonstrates the discussion above.

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

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

            // set message and add destinations.
            sms.setMessage("Hello there!");
            sms.addRecipient("233206111999");
            sms.addRecipient("233238778854");

            // show the added destinations on screen.
            foreach (string phonenum in sms.getRecipients())
                Console.WriteLine(phonenum);

            // overwrite the previously set message. For this message, the destinations list 
            // will not be cleared since there is no variable defined in the message.
            Console.WriteLine("\nOverwriting previously set message with non-personalised one.");
            sms.setMessage("Overwrite previously set message.");

            Console.WriteLine("\nDestinations added...");
            foreach (string phonenum in sms.getRecipients())
              Console.WriteLine(phonenum);

            // overwrite the previously set message with one that contains variables for personalisation.
            // With this, the previously added destinations will be cleared.
            Console.WriteLine("\nOverwriting previously set message with a personalised one.");
            sms.setMessage("Hello {$name}, your balance is ${$balance}.");
            sms.addRecipient("233201999998", "Daniel", "4,500.85");

            // show the added destinations on screen.
            Console.WriteLine("Destinations added..."); 
            foreach (string phonenum in sms.getRecipients())
                Console.WriteLine(phonenum);


            // overwrite the previously personalised message with non-personalised one.
            Console.WriteLine("\nOverwriting previously set personalised message with non-personalised one.");
            sms.setMessage("Meet me in Kumasi.");
            sms.addRecipient("233560874532");

            // show the added destinations on screen.
            Console.WriteLine("Destinations added...");
            foreach (string phonenum in sms.getRecipients())
                Console.WriteLine(phonenum);
        }

        catch (SMSException sex)
        {
            Console.WriteLine("Error: " + sex.Message);
        }

        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }
    }
}
See Also