Пример #1
0
        /// <summary>
        /// This example demonstrates how to Schedule a message in the future
        /// </summary>
        /// <param name="from">From phone number - also known as Origin</param>
        /// <param name="to">To phone number</param>
        /// <param name="message">The content of the message</param>
        /// <param name="messageId">Your message identifier</param>
        /// / <param name="dateTime">Date time to be sent</param>
        /// <returns>SendMessagesResultType object.</returns>
        public SendMessagesResultType SendScheduledMessage(string from, string to, string message, uint messageId, DateTime dateTime)
        {
            // Construct the message
            MessageType messageType = new MessageType();

            messageType.content        = message;
            messageType.deliveryReport = true;
            messageType.format         = MessageFormatType.SMS;
            messageType.validityPeriod = 169;
            messageType.sequenceNumber = 1;
            if (dateTime == DateTime.Now)
            {
                messageType.scheduledSpecified = false;
            }
            else
            {
                messageType.scheduledSpecified = true;
            }
            messageType.scheduled = dateTime;

            if (!String.IsNullOrEmpty(from))
            {
                messageType.origin = from;
            }

            #region Message Tags
            // Add the tags - if supported by your account type
            //MessageTagType[] tags = new MessageTagType[1];
            //tags[0] = new MessageTagType { name = "My Tag Name", Value = "My Tag Value" };
            //messageType.tags = tags;
            #endregion

            // Add the recipients
            RecipientType[] recipientType = new RecipientType[1];
            recipientType[0] = new RecipientType {
                uid = (uint)messageId, Value = to
            };
            messageType.recipients = recipientType;

            // Create an array to store all the recipient messages.
            MessageType[] messages = new MessageType[1];
            messages[0] = messageType;

            // Setup the send message body
            SendMessagesBodyType sendMessageBody = new SendMessagesBodyType();
            sendMessageBody.messages          = new MessageListType();
            sendMessageBody.messages.sendMode = MessageSendModeType.normal;
            sendMessageBody.messages.message  = messages;

            return(messageMediaSoapService.sendMessages(authentication, sendMessageBody));
        }
        /// <summary>
        /// Example shows how to construct messages using MessageType and how to send to multiple recipients
        /// </summary>
        public static void ConstructAndSendBatchMessage()
        {
            System.Console.WriteLine("EXECUTING ConstructAndSendBatchMessage()\nConstruct a message and send to multiple recipients.");
            try
            {
                // Define how many messages you plan to send as this figure will be used to initialise various arrays.
                int totalMessagesBeingSent = 1;

                // Setup the various objects required to send a message.
                MessageMediaSoapClient client = new MessageMediaSoapClient(userId, password);

                // Create an array to store all the recipient messages.
                MessageType[] messages = new MessageType[totalMessagesBeingSent];

                MessageType message = new MessageType();

                #region Message Properties

                // (Optional) This attribute specifies a user-defined unique ID that is assigned to a message-recipient pair. The uid is an unsigned integer that uniquely identifies a message sent to a particular recipient.
                // uid values are used for three things: to identify a message-recipient in the case of an error; to match a reply message to the sent message it is in response to; and to match a delivery report to the sent message it is in response to.
                // If no uid value is specified a default value of zero is assigned.
                uint messageId = 123456789;
                // Note: This needs to be enabled for your account in order to send from a dedicated numberplease contact MessageMedia Support for details
                // (Optional) This element specifies the message source address. The specified address will be used wherever possible, however due to limitations with various carriers, legislation etc, the final message is not guaranteed to come from the specified address.
                message.origin = null;
                // Delivery reports when requested (TRUE) will allow customers to see if a message has been delivered.
                // Please note you can view the report within our MessageMedia Manager interface and requesting a deliveryReport incurs additional fees per message.
                message.deliveryReport = false;
                message.format         = MessageFormatType.SMS;
                message.validityPeriod = 1;
                // (Optional) This attribute specifies a sequence number that is assigned to the message and is used to identify the message if an error occurs. Each message error in the response will specify the sequence number of the message that caused the error. Sequence numbers should be unique within the request. 1 to 2147483647.
                message.sequenceNumber = 1;
                message.content        = "ConstructAndSendBatchMessage executed.\n";

                #endregion

                #region Add Message Recipients
                // Add the recipients
                // The RecipientType object is used to store the messageId and destination phone number.
                System.Console.Write("Sending to Recipient 1 and Recipient 2\n");
                int             numRecipients        = 2;
                RecipientType[] messageRecipientList = new RecipientType[numRecipients];
                messageRecipientList[0] = new RecipientType {
                    uid = messageId, Value = recipient1
                };
                messageRecipientList[1] = new RecipientType {
                    uid = messageId, Value = recipient2
                };
                message.recipients = messageRecipientList;

                #endregion

                #region Message Tags
                // It is possible to add Tags to an individual message; this might be useful if wanting to identify a particular campaign or cost centre.
                // Note: This needs to be enabled for the account, contact MessageMedia Support for more details

                // Add the tags - if supported by your account type
                //MessageTagType[] tags = new MessageTagType[1];
                //tags[0] = new MessageTagType { name = "My Tag Name", Value = "My Tag Value" };
                //message.tags = tags;
                #endregion

                #region Send Constructed Message and Display
                // Add the message to the messages array.
                messages[0] = message;

                // The batch of messages are sent using a SendMessagesBodyType object.
                SendMessagesBodyType sendMessageBody = new SendMessagesBodyType();
                // Initiate the messages list so that it is not null.
                sendMessageBody.messages = new MessageListType();
                // Define the send behaviour of the messages.
                // "dropAll" – to drop (not send) the requested messages, and return a result indicating that messages were sent / scheduled successfully or failed to send at random.
                // "dropAllWithErrors" – to drop (not send) the requested messages, and return a result indicating that all messages failed to send.
                // "dropAllWithSuccess" – to drop (not send) the requested messages, but return a result indicating all messages were sent / scheduled successfully.
                // "normal" – to send the requested messages as normal.
                sendMessageBody.messages.sendMode = MessageSendModeType.normal;
                // Attach the messages
                sendMessageBody.messages.message = messages;

                System.Console.WriteLine("Sending {0} message(s)", totalMessagesBeingSent);

                var result = client.SendMessage(sendMessageBody);

                DisplaySendMessageResult(result);
                #endregion
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Error: {0}", ex.Message);
            }
        }
Пример #3
0
 /// <summary>
 /// This method takes a batch of messages which have been consructed and sends them.
 /// </summary>
 /// <param name="sendMessageBody">The object which contains the batch of messages.</param>
 /// <returns>SendMessagesResultType</returns>
 public SendMessagesResultType SendMessage(SendMessagesBodyType sendMessageBody)
 {
     return(messageMediaSoapService.sendMessages(authentication, sendMessageBody));
 }