public async Task HandleInbound(InboundSms sms) { if (sms.Text.ToUpper().Contains("STOP")) { var donorsToOptOut = await _db.Donors.Where(d => d.PhoneNumber == sms.Msisdn).ToListAsync(); donorsToOptOut.ForEach(d => d.OptOut = true); await _db.SaveChangesAsync(); } }
/// <summary> /// Gets SMS messages received for a specific short code. /// </summary> /// <param name="shortCode">Short code to get SMS message for.</param> /// <returns>instance of <see cref="InboundSmsMessageList"/>Returns task as a result of asynchronous operation. Task result is list of inbound SMS messages.</returns> /// <exception cref="System.ArgumentNullException">shortCode is null.</exception> public async Task <InboundSmsMessageList> GetInboundSmsMessages(string shortCode) { Argument.ExpectNotNullOrWhiteSpace(() => shortCode); var accessToken = await GetClientCredential(); string relativeUri = String.Format(CultureInfo.InvariantCulture, GetSmsRelativeUrl, shortCode, accessToken); return(InboundSms.ParseJson(await SendRawRequest(HttpMethod.Get, relativeUri, null))); }
public async Task <IEnumerable <InboundSms> > GetInboundSmsMessages(string shortCode) { var result = new List <InboundSms>(); for (int i = _inboundSms.Count - 1; i >= 0; i--) { InboundSms sms = _inboundSms[i]; if (sms.SenderNumber.Number == shortCode) { result.Add(sms); _inboundSms.RemoveAt(i); } } await Task.Delay(10); return(result); }
/// <summary> /// Gets collection of inbound SMS messages sent to some short code /// </summary> /// <param name="shortCode">short code</param> public async Task <IEnumerable <InboundSms> > GetInboundSmsMessages(string shortCode) { var result = new List <InboundSms>(); int count = _rand.Next(5); // Number of sms for (int i = 0; i < count; i++) { var sms = new InboundSms(new Guid().ToString(), new PhoneNumber(shortCode), _msgKeys[_rand.Next(100) % 4]); result.Add(sms); } _inboundSms.Clear(); await Task.Delay(100); return(result); }