public static void Execute() { // Configure in the 'app.config' which Logger levels are enabled(all levels are enabled in the example) // Check http://logging.apache.org/log4net/release/manual/configuration.html for more informations about the log4net configuration XmlConfigurator.Configure(new FileInfo("OneApiExamples.exe.config")); // example:initialize-sms-client Configuration configuration = new Configuration(System.Configuration.ConfigurationManager.AppSettings.Get("Username"), System.Configuration.ConfigurationManager.AppSettings.Get("Password")); SMSClient smsClient = new SMSClient(configuration); // ---------------------------------------------------------------------------------------------------- // example:prepare-message-without-notify-url SMSRequest smsRequest = new SMSRequest(senderAddress, message, recipientAddress); // ---------------------------------------------------------------------------------------------------- // example:send-message // Store request id because we can later query for the delivery status with it: SendMessageResult sendMessageResult = smsClient.SmsMessagingClient.SendSMS(smsRequest); // ---------------------------------------------------------------------------------------------------- // Few seconds later we can check for the sending status System.Threading.Thread.Sleep(10000); // example:query-for-delivery-status DeliveryInfoList deliveryInfoList = smsClient.SmsMessagingClient.QueryDeliveryStatus(senderAddress, sendMessageResult.ClientCorrelator); string deliveryStatus = deliveryInfoList.DeliveryInfos[0].DeliveryStatus; // ---------------------------------------------------------------------------------------------------- Console.WriteLine(deliveryStatus); }
/// <summary> /// Gets sent MMS message delivery status. /// </summary> /// <param name="mmsId">Message identifier.</param> /// <returns>Current message delivery status.</returns> /// <exception cref="System.ArgumentNullException">mmsId is null.</exception> public async Task <MessageDeliveryStatus> GetMmsStatus(string mmsId) { Argument.ExpectNotNull(() => mmsId); DeliveryInfoList resp = await _mmsServiceWrapper.GetMmsStatus(mmsId); // AT&T service returns message delivery status as string - cast it to enum with all possible delivery statuses return((MessageDeliveryStatus)Enum.Parse(typeof(MessageDeliveryStatus), resp.DeliveryStatus.DeliveryInfoList.First().DeliveryStatus)); }
/// <summary> /// This method will be called when user clicks on get status button /// </summary> /// <param name="sender">object, that caused this event</param> /// <param name="e">Event that invoked this function</param> protected void StatusButton_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(msgIdLabel.Text)) { return; } if (this.ReadAndGetAccessToken() == false) { return; } string mmsId = msgIdLabel.Text; string mmsDeliveryStatus; HttpWebRequest mmsStatusRequestObject = (HttpWebRequest)System.Net.WebRequest.Create(string.Empty + this.endPoint + "/rest/mms/2/messaging/outbox/" + mmsId); mmsStatusRequestObject.Headers.Add("Authorization", "Bearer " + this.accessToken); mmsStatusRequestObject.Method = "GET"; HttpWebResponse mmsStatusResponseObject = (HttpWebResponse)mmsStatusRequestObject.GetResponse(); using (StreamReader mmsStatusResponseStream = new StreamReader(mmsStatusResponseObject.GetResponseStream())) { mmsDeliveryStatus = mmsStatusResponseStream.ReadToEnd(); mmsDeliveryStatus = mmsDeliveryStatus.Replace("-", string.Empty); JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer(); GetDeliveryStatus status = (GetDeliveryStatus)deserializeJsonObject.Deserialize(mmsDeliveryStatus, typeof(GetDeliveryStatus)); DeliveryInfoList dinfoList = status.DeliveryInfoList; this.DrawPanelForGetStatusResult(null, null, null, true); foreach (DeliveryInfoRaw deliveryInfo in dinfoList.DeliveryInfo) { this.DrawPanelForGetStatusResult(deliveryInfo.Id, deliveryInfo.Address, deliveryInfo.DeliveryStatus, false); } msgIdLabel.Text = string.Empty; mmsStatusResponseStream.Close(); } } catch (WebException we) { string errorResponse = string.Empty; try { using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream())) { errorResponse = sr2.ReadToEnd(); sr2.Close(); } } catch { errorResponse = "Unable to get response"; } this.DrawPanelForFailure(statusPanel, errorResponse + Environment.NewLine + we.Message); } catch (Exception ex) { this.DrawPanelForFailure(statusPanel, ex.ToString()); } }