Skip to content

Messaging

Marcello Bachechi edited this page Aug 5, 2019 · 2 revisions

Sending a Message

Sending a message is easy, there are several ways we allow you to send messages.

Send a message to one person

MessagesActions.SendMessage("Hello John, you have an appointment at 3PM today.", "7195552656");

Send a message to multiple people

MessagesActions.SendMessage("Flash sale today! All products 10% off!", "7195559696", "7195554752");

Send a message at a certain time

NOTE YOU MUST USE DateTime.UtcNow NOT DateTime.Now

MessagesActions.SendMessage("Hello Mary, is your refigrator running?", DateTime.UtcNow.AddMinutes(10), "7195554752");

Send a message at a certain time to many people

NOTE YOU MUST USE DateTime.UtcNow NOT DateTime.Now

MessagesActions.SendMessage("Office meeting at 3:30 Friday. Get ready for layoffs!", DateTime.UtcNow.AddMinutes(10), "7195554752", "17195553382");

Sending a single message, prevent exceptions from being thrown

Sometimes we don't want an exception to be thrown if the message does not go through. If you want to disable exceptions for sending a single message you can set the DisableExceptions property to false in the message actions class

MessagesActions.DisableExceptions = true;

We strongly suggest that if you do this, you also verify the message went through by checking the .Accepted property of the SendMessageStatus class or by checking the .error property.

Advanced sending a message via Models.Message class

ClickATel.Models.Message ViaMsgCls = new ClickATel.Models.Message
{
    To = new List<string> { "9705552141", "7195552297", "7195556630", "7195553021" },
    DeliverAt = DateTime.UtcNow.AddMinutes(5),
    Message_Text = "You won a Free iPad! Send your SSN now!",
    From = "19702817674"
};

MessagesActions.SendMessage(ViaMsgCls);

See if a message was accepted

By default the SendMessage() function will either return SendMessageStatus for single messages or SendMessagesStatus for multiple messages.

If you are sending a single message you can simply add .Accepted to see if the message was accepted

bool sent = MessagesActions.SendMessage("Hello John, you have an appointment at 3PM today.", "7195552656").Accepted;

or you can assign it to a variable and see if it was accepted here

SendMessagesStatus msgs = MessagesActions.SendMessage("Hello, sale starts today!", "7195559696", "7195554752");
foreach(SendMessageStatus m in msgs)
{
    Console.WriteLine("{0,-16} Accepted: {1}", m.toNumber , m.Accepted);
}

If the message was not accepted you can check to see why it was rejected by retrieving the .errorDescription property

if (msg.Accepted)
    Console.WriteLine("Message Accepted! {0}", msg.MessageID);
else
    Console.WriteLine("Message Was not accepted {0}", msg.errorDescription);

Get Message ID

By default the SendMessage() function will either return SendMessageStatus for single messages or SendMessagesStatus for multiple messages.

If you are sending a single message you can simply add .MessageID to get the MessageID from click-a-tell

string sent_ID = MessagesActions.SendMessage("Hello John, you have an appointment at 3PM today.", "7195552656").MessageID;

or you can assign it to a variable and see if it was accepted here

SendMessagesStatus msgs = MessagesActions.SendMessage("Bear seen in your backyard!", "7195559696", "7195554752");
foreach(SendMessageStatus m in msgs)
{
    Console.WriteLine("{0,-16} Message ID: {1}", m.toNumber , m.MessageID);
}

Getting a message status from the server

In order to see what the status of your message is through the Click-A-Tel gateway, you can call MessagesActions.GetMessageStatus(SendMessageStatus) or MessagesActions.GetMessageStatus(String MessageID)

foreach (SendMessageStatus singlemsg in msgs.Message)
{
    Console.WriteLine(MessagesActions.GetMessageStatus(singlemsg));
    Console.WriteLine(MessagesActions.GetMessageStatus(singlemsg.MessageID));
}