Пример #1
0
        /// <summary>
        /// Checks the attributes for this component and determines if the message
        /// should be processed.
        /// </summary>
        /// <param name="action">The action that contains the configuration for this component.</param>
        /// <param name="message">The message that is to be checked.</param>
        /// <param name="errorMessage">If there is a problem processing, this should be set</param>
        /// <returns>
        ///   <c>true</c> if the message should be processed.
        /// </returns>
        public override bool ShouldProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage)
        {
            //
            // Give the base class a chance to check it's own settings to see if we
            // should process this message.
            //
            if (!base.ShouldProcessMessage(action, message, out errorMessage))
            {
                return(false);
            }

            //
            // Check if we have a valid workflow type.
            //
            var workflowType = WorkflowTypeCache.Get(GetAttributeValue(action, AttributeKey.WorkflowType).AsGuid());

            if (workflowType == null)
            {
                return(false);
            }

            //
            // Get the filter expression for the message body.
            //
            var attribute = action.Attributes.ContainsKey(AttributeKey.Message) ? action.Attributes[AttributeKey.Message] : null;
            var msg       = GetAttributeValue(action, AttributeKey.Message);
            var filter    = ValueFilterFieldType.GetFilterExpression(attribute?.QualifierValues, msg);

            //
            // Evaluate the message against the filter and return the match state.
            //
            return(filter != null?filter.Evaluate(message, AttributeKey.Message) : true);
        }
Пример #2
0
        /// <summary>
        /// Processes the message that was received from the remote user.
        /// </summary>
        /// <param name="action">The action that contains the configuration for this component.</param>
        /// <param name="message">The message that was received by Rock.</param>
        /// <param name="errorMessage">If there is a problem processing, this should be set</param>
        /// <returns>An SmsMessage that will be sent as the response or null if no response should be sent.</returns>
        public override SmsMessage ProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage)
        {
            errorMessage = string.Empty;

            //
            // Process the message with lava to get the response that should be sent back.
            //
            var mergeObjects = new Dictionary <string, object>
            {
                { "Message", message }
            };
            var responseMessage = action.GetAttributeValue("Response").ResolveMergeFields(mergeObjects, message.FromPerson);

            //
            // If there is no response message then return null.
            //
            if (string.IsNullOrWhiteSpace(responseMessage))
            {
                return(null);
            }

            return(new SmsMessage
            {
                Message = responseMessage.Trim()
            });
        }
        /// <summary>
        /// Handles the Click event of the btnSaveActionSettings control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSaveActionSettings_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();
            var action      = new SmsActionService(rockContext).Get(hfEditActionId.Value.AsInteger());

            action.Name     = tbName.Text;
            action.IsActive = cbActive.Checked;
            action.ContinueAfterProcessing = cbContinue.Checked;
            action.ExpireDate = dpExpireDate.SelectedDate;

            avcFilters.GetEditValues(action);
            avcAttributes.GetEditValues(action);

            rockContext.WrapTransaction(() =>
            {
                rockContext.SaveChanges();

                action.SaveAttributeValues();
            });

            SmsActionCache.Clear();

            pnlEditAction.Visible = false;
            hfEditActionId.Value  = string.Empty;
            BindActions();
        }
Пример #4
0
        /// <summary>
        /// Processes the drag events.
        /// </summary>
        private void ProcessDragEvents()
        {
            string argument = Request["__EVENTARGUMENT"].ToStringSafe();
            var    segments = argument.SplitDelimitedValues();

            //
            // Check for the event to add a new action.
            //
            if (segments.Length == 3 && segments[0] == "add-action")
            {
                var actionComponent = SmsActionContainer.GetComponent(segments[1]);
                var order           = segments[2].AsInteger();

                var rockContext      = new RockContext();
                var smsActionService = new SmsActionService(rockContext);

                var action = new SmsAction
                {
                    SmsPipelineId = GetSmsPipelineId().Value,
                    Name          = actionComponent.Title,
                    IsActive      = true,
                    Order         = order,
                    SmsActionComponentEntityTypeId = actionComponent.TypeId
                };

                smsActionService.Queryable()
                .Where(a => a.Order >= order)
                .ToList()
                .ForEach(a => a.Order += 1);

                smsActionService.Add(action);

                rockContext.SaveChanges();

                BindActions();

                SmsActionCache.Clear();
            }

            //
            // Check for the event to drag-reorder actions.
            //
            else if (segments.Length == 3 && segments[0] == "reorder-action")
            {
                var rockContext      = new RockContext();
                var smsActionService = new SmsActionService(rockContext);

                var actions = smsActionService.Queryable()
                              .OrderBy(a => a.Order)
                              .ThenBy(a => a.Id)
                              .ToList();

                smsActionService.Reorder(actions, segments[1].AsInteger(), segments[2].AsInteger());
                rockContext.SaveChanges();

                BindActions();

                SmsActionCache.Clear();
            }
        }
Пример #5
0
        /// <summary>
        /// Checks the attributes for this component and determines if the message
        /// should be processed.
        /// </summary>
        /// <param name="action">The action that contains the configuration for this component.</param>
        /// <param name="message">The message that is to be checked.</param>
        /// /// <param name="errorMessage">If there is a problem, this should be set</param>
        /// <returns><c>true</c> if the message should be processed.</returns>
        public virtual bool ShouldProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage)
        {
            errorMessage = string.Empty;

            var attribute    = action.Attributes.ContainsKey("PhoneNumbers") ? action.Attributes["PhoneNumbers"] : null;
            var phoneNumbers = GetAttributeValue(action, "PhoneNumbers");
            var filter       = ValueFilterFieldType.GetFilterExpression(attribute?.QualifierValues, phoneNumbers);

            return(filter != null?filter.Evaluate(message, "ToNumber") : true);
        }
Пример #6
0
        /// <summary>
        /// Checks the attributes for this component and determines if the message
        /// should be processed.
        /// </summary>
        /// <param name="action">The action that contains the configuration for this component.</param>
        /// <param name="message">The message that is to be checked.</param>
        /// <param name="errorMessage">If there is a problem processing, this should be set</param>
        /// <returns>
        ///   <c>true</c> if the message should be processed.
        /// </returns>
        public override bool ShouldProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage)
        {
            //
            // Give the base class a chance to check it's own settings to see if we
            // should process this message.
            //
            if (!base.ShouldProcessMessage(action, message, out errorMessage))
            {
                return(false);
            }

            return(true);
        }
Пример #7
0
        /// <summary>
        /// Processes the message that was received from the remote user.
        /// </summary>
        /// <param name="action">The action that contains the configuration for this component.</param>
        /// <param name="message">The message that was received by Rock.</param>
        /// <param name="errorMessage">If there is a problem processing, this should be set</param>
        /// <returns>An SmsMessage that will be sent as the response or null if no response should be sent.</returns>
        public override SmsMessage ProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage)
        {
            errorMessage = string.Empty;

            //
            // Get the list of workflow attributes to set.
            //
            var workflowAttributesSettings = new List <KeyValuePair <string, object> >();
            var workflowAttributes         = action.Attributes["WorkflowAttributes"];

            if (workflowAttributes != null)
            {
                if (workflowAttributes.FieldType.Field is KeyValueListFieldType keyValueField)
                {
                    workflowAttributesSettings = keyValueField.GetValuesFromString(null,
                                                                                   GetAttributeValue(action, "WorkflowAttributes"),
                                                                                   workflowAttributes.QualifierValues,
                                                                                   false);
                }
            }

            var workflowType = WorkflowTypeCache.Get(GetAttributeValue(action, "WorkflowType").AsGuid());

            //
            // Launch the workflow.
            //
            Rock.Utility.TextToWorkflow.LaunchWorkflow(workflowType,
                                                       GetAttributeValue(action, "WorkflowNameTemplate"),
                                                       message.FromPerson,
                                                       message.FromNumber.Replace("+", ""),
                                                       message.ToNumber.Replace("+", ""),
                                                       message.Message,
                                                       message.Attachments,
                                                       workflowAttributesSettings,
                                                       out string response);

            //
            // If there is no response message then return null.
            //
            if (string.IsNullOrWhiteSpace(response))
            {
                return(null);
            }

            return(new SmsMessage
            {
                Message = response.Trim()
            });
        }
Пример #8
0
 /// <summary>
 /// Updates any Cache Objects that are associated with this entity
 /// </summary>
 /// <param name="entityState">State of the entity.</param>
 /// <param name="dbContext">The database context.</param>
 public void UpdateCache(EntityState entityState, Rock.Data.DbContext dbContext)
 {
     SmsActionCache.UpdateCachedEntity(Id, entityState);
 }
Пример #9
0
 /// <summary>
 /// Gets the cache object associated with this Entity
 /// </summary>
 /// <returns></returns>
 public IEntityCache GetCacheObject()
 {
     return(SmsActionCache.Get(Id));
 }
Пример #10
0
        /// <summary>
        /// Processes the drag events.
        /// </summary>
        private void ProcessDragEvents()
        {
            string argument      = Request["__EVENTARGUMENT"].ToStringSafe();
            var    segments      = argument.SplitDelimitedValues();
            var    smsPipelineId = GetSmsPipelineId();

            if (smsPipelineId == null || segments.Length != 3)
            {
                return;
            }

            using (var rockContext = new RockContext())
            {
                var smsActionService = new SmsActionService(rockContext);

                var actions = smsActionService
                              .Queryable()
                              .Where(a => a.SmsPipelineId == smsPipelineId)
                              .OrderBy(a => a.Order)
                              .ThenBy(a => a.Id)
                              .ToList();

                // Reset order actions to eliminate gaps.
                for (var i = 0; i < actions.Count; i++)
                {
                    actions[i].Order = i;
                }

                // Check for the event to add a new action.
                if (segments[0] == "add-action")
                {
                    var actionComponent = SmsActionContainer.GetComponent(segments[1]);
                    var order           = segments[2].AsInteger();

                    var action = new SmsAction
                    {
                        SmsPipelineId = smsPipelineId.Value,
                        Name          = actionComponent.Title,
                        IsActive      = true,
                        Order         = order,
                        SmsActionComponentEntityTypeId = actionComponent.TypeId
                    };

                    actions
                    .Where(a => a.Order >= order)
                    .ToList()
                    .ForEach(a => a.Order += 1);

                    smsActionService.Add(action);
                }
                else if (segments[0] == "reorder-action")
                {
                    // Check for the event to drag-reorder actions.
                    smsActionService.Reorder(actions, segments[1].AsInteger(), segments[2].AsInteger());
                }

                rockContext.SaveChanges();
                BindActions();
                SmsActionCache.Clear();
            }
        }
Пример #11
0
        /// <summary>
        /// Processes the message that was received from the remote user.
        /// </summary>
        /// <param name="action">The action that contains the configuration for this component.</param>
        /// <param name="message">The message that was received by Rock.</param>
        /// <param name="errorMessage">If there is a problem processing, this should be set</param>
        /// <returns>An SmsMessage that will be sent as the response or null if no response should be sent.</returns>
        public override SmsMessage ProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage)
        {
            new Rock.Communication.Medium.Sms().ProcessResponse(message.ToNumber, message.FromNumber, message.Message, out errorMessage);

            return(null);
        }
Пример #12
0
        /// <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);
        }
Пример #13
0
 /// <summary>
 /// Processes the message that was received from the remote user.
 /// </summary>
 /// <param name="action">The action that contains the configuration for this component.</param>
 /// <param name="message">The message that was received by Rock.</param>
 /// <param name="errorMessage">If there is a problem processing, this should be set</param>
 /// <returns>An SmsMessage that will be sent as the response or null if no response should be sent.</returns>
 public abstract SmsMessage ProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage);
Пример #14
0
 /// <summary>
 /// Gets the attribute value for the service check type
 /// </summary>
 /// <param name="action">The SMS action.</param>
 /// <param name="key">The key.</param>
 /// <returns></returns>
 public string GetAttributeValue(SmsActionCache action, string key)
 {
     return(action.GetAttributeValue(key));
 }