/// <summary> /// Processes the incoming message. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="smsPipelineId"> /// The SMS pipeline identifier. When null the active pipeline with the lowest SmsPipelineId will be used. /// </param> /// <returns></returns> static public List <SmsActionOutcome> ProcessIncomingMessage(SmsMessage message, int?smsPipelineId) { if (smsPipelineId == null) { var minSmsPipelineId = new SmsPipelineService(new RockContext()) .Queryable() .Where(p => p.IsActive) .Select(p => ( int? )p.Id) .Min(p => p); if (minSmsPipelineId == null) { var errorMessage = string.Format("No default SMS Pipeline could be found."); return(CreateErrorOutcomesWithLogging(errorMessage)); } smsPipelineId = minSmsPipelineId; } return(ProcessIncomingMessage(message, smsPipelineId.Value)); }
/// <summary> /// Processes the incoming message. /// </summary> /// <param name="message">The message received by the communications component.</param> /// <param name="smsPipelineId">The SMS pipeline identifier.</param> /// <returns> /// If not null, identifies the response that should be sent back to the sender. /// </returns> static public List <SmsActionOutcome> ProcessIncomingMessage(SmsMessage message, int smsPipelineId) { var errorMessage = string.Empty; var outcomes = new List <SmsActionOutcome>(); var smsPipelineService = new SmsPipelineService(new RockContext()); var smsPipeline = smsPipelineService.Get(smsPipelineId); if (smsPipeline == null) { errorMessage = string.Format("The SMS Pipeline for SMS Pipeline Id {0} was null.", smsPipelineId); return(CreateErrorOutcomesWithLogging(errorMessage)); } if (!smsPipeline.IsActive) { errorMessage = string.Format("The SMS Pipeline for SMS Pipeline Id {0} was inactive.", smsPipelineId); return(CreateErrorOutcomesWithLogging(errorMessage)); } var smsActions = SmsActionCache.All() .Where(a => a.IsActive) .Where(a => a.SmsPipelineId == smsPipelineId) .OrderBy(a => a.Order) .ThenBy(a => a.Id); foreach (var smsAction in smsActions) { if (smsAction.SmsActionComponent == null) { LogIfError(string.Format("The SmsActionComponent for {0} was null", smsAction.Name)); continue; } var outcome = new SmsActionOutcome { ActionName = smsAction.Name }; outcomes.Add(outcome); try { // // Check if the action wants to process this message. // outcome.ShouldProcess = smsAction.SmsActionComponent.ShouldProcessMessage(smsAction, message, out errorMessage); outcome.ErrorMessage = errorMessage; LogIfError(errorMessage); if (!outcome.ShouldProcess) { continue; } // // Process the message and use either the response returned by the action // or the previous response we already had. // outcome.Response = smsAction.SmsActionComponent.ProcessMessage(smsAction, message, out errorMessage); outcome.ErrorMessage = errorMessage; LogIfError(errorMessage); if (outcome.Response != null) { LogIfError(errorMessage); } } catch (Exception exception) { outcome.Exception = exception; LogIfError(exception); } // // If the action is set to not continue after processing then stop. // if (outcome.ShouldProcess && !smsAction.ContinueAfterProcessing) { break; } } return(outcomes); }