ASPbee

ASPbee

  • NA
  • 40
  • 35.4k

Check Replies

Aug 1 2011 12:27 AM
Hi,

       i am trying to create a service which automatically connects to the SMS Gateway account and goes through the inbox and checks if there any existing replies from the user and sends out a series of default messages in a time interval of 60 seconds each.

The following is what i got as a code together but unfortunately even when there are replies sitting on the SMS Gateway account my function says that there are "No replies currently" could someone help where i am missing.

private void CheckRepliesButton_Click(object sender, EventArgs e) 
        {
            //Messaging.MessageController.Settings.Logger.WriteLine(LogEntryType.Info, "Check replies button clicked.");


            // Validate the connection details before checking for replies.
            if (ValidateConnectionDetails())
                CollectFormData();
            else
                return;


            // Check for replies.
            if (!Messaging.MessageController.CheckReplies())
            {
                // Check replies was denied. Check replies can be called at a maximum rate of once per minute.
                // Display a message box with the amount of time the user must wait for replies can be checked.
                string text = string.Format("Replies can be checked for at a maximum rate of once per minute per account.\n\n" +
                    "Amount of time to wait: {0} seconds.", Messaging.MessageController.GetCheckReplyTimeToWait().TotalSeconds);
                MessageBox.Show(this, text, "Check Replies Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }




private void MessageController_CheckRepliesComplete(object sender, CheckRepliesCompleteEventArgs e)
        {
           if (e.Success)
            {
                // Pop up a form to display each reply message.
               // MessageBox.Show("e.Sucess");


                MessageList ml = e.Messages;
                MessageBox.Show("Message Count" + ml.Count);


               foreach (MessageIn reply in e.Messages)
                {
                    ReplyForm replyForm = new ReplyForm(reply);
                    replyForm.Show();
                }


                // If delivery reports were received display a message box displaying the delivered messages.
                if (e.DeliveryReports.Count > 0)
                {
                    // Update the delivery status of sent messages that correspond to the received delivery reports.
                    UpdateSentItemsDeliveryStatus(e.DeliveryReports);


                    string text = "Delivery Reports Received:\n\n";
                    foreach (DeliveryReport report in e.DeliveryReports)
                    {
                        // Get the sent message that corresponds to the delivery report.
                        MessageOut deliveredMessage = this.SentItems.Find(delegate(MessageOut sentItem) { return sentItem.MessageID == report.MessageID; });


                        if (deliveredMessage != null)
                        {
                            text += string.Format("ID: {0}\nRecipient: {1}\nDelivery Status: {2}\nDelivery Time: {3:dd/MM/yyyy HH:mm:ss}\nMessage: {4}\n\n",
                                deliveredMessage.MessageID, deliveredMessage.PhoneNumber, deliveredMessage.DeliveryStatus.ToString(), deliveredMessage.DeliveryTime, deliveredMessage.MessageText);
                        }
                        else
                        {
                            // The sent item corresponding to the delivery report could not be found in SentItems. This will
                            // happen if the application is restarted between the message being sent and the delivery report arriving.
                            text += string.Format("ID: {0}\nDelivery Report: {1}\n(Message Contents Not Found In SentItems)\n\n", report.MessageID, report.MessageText);
                        }
                    }
                    MessageBox.Show(this, text, "Messages Delivered", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }


                // If no new replies or delivery reports were received display a message box to notify the user.
                if (e.Messages.Count == 0 && e.DeliveryReports.Count == 0)
                {
                    MessageBox.Show(this, "No new replies or delivery reports were received.", "No Messages Received", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                }
            }
            else
            {
                string text = string.Format("The following error occurred when checking for replies:\n\n{0}", (e.Exception != null) ? e.Exception.ToString() : "Unknown");
                MessageBox.Show(this, text, "Check Replies Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
            }
        }
       
 Messaging.MessageController.CheckRepliesComplete += new CheckRepliesCompleteEventHandler(MessageController_CheckRepliesComplete);
           

Answers (1)