Esempio n. 1
0
        public static CVR APICallNodeValidations_ERROR(ChatFlowPack pack)
        {
            var res          = new CVR();
            var msgs         = new List <string>();
            var apicallNodes = pack.ChatNodes.Where(x => x.NodeType == NodeTypeEnum.ApiCall).ToList();

            if (apicallNodes.Count > 0)
            {
                foreach (var node in apicallNodes)
                {
                    var nodeMsg = $"Error: In node '{node.Identifer()}', ";
                    if (node.ApiMethod == null)
                    {
                        msgs.Add($"{nodeMsg} '{nameof(node.ApiMethod)}' field is not set! Set it to the Method(HTTP Verb) of the api you want to use.");
                        res.SetStatus(CVS.Error);
                    }

                    if (string.IsNullOrWhiteSpace(node.ApiUrl))
                    {
                        msgs.Add($"{nodeMsg} '{nameof(node.ApiUrl)}' field is not set! Set it to the api you want to use.");
                        res.SetStatus(CVS.Error);
                    }
                    else if (!Uri.TryCreate(node.ApiUrl, UriKind.Absolute, out Uri uri))
                    {
                        msgs.Add($"{nodeMsg} '{nameof(node.ApiUrl)}' field has invalid URL! Set it to a valid URL. Did you forget to start with http:// or https://");
                        res.SetStatus(CVS.Error);
                    }
                }
            }
            if (msgs.Count > 0)
            {
                return(res.SetMsg(msgs.Join("\r\n")).SetStatus(CVS.Error));
            }
            return(res.Valid());
        }
Esempio n. 2
0
        public static CVR NodesWithGetXTypeButtonsShouldHaveVariableName_ERROR(ChatFlowPack pack)
        {
            var res = new CVR();
            var nonEmptyVarNameBtnTypes = new HashSet <ButtonTypeEnum>(new[]
            {
                ButtonTypeEnum.GetText,
                ButtonTypeEnum.GetTime,
                ButtonTypeEnum.GetVideo,
                ButtonTypeEnum.GetFile,
                ButtonTypeEnum.GetImage,
                ButtonTypeEnum.GetItemFromSource,
                ButtonTypeEnum.GetLocation,
                ButtonTypeEnum.GetNumber,
                ButtonTypeEnum.GetPhoneNumber,
                ButtonTypeEnum.GetDate,
                ButtonTypeEnum.GetDateTime,
                ButtonTypeEnum.GetAudio
            });
            var respMessage = new List <string>();

            foreach (var node in pack.ChatNodes)
            {
                if (node.Buttons.Any(x => nonEmptyVarNameBtnTypes.Contains(x.ButtonType)) && string.IsNullOrWhiteSpace(node.VariableName))
                {
                    respMessage.Add($"Error: Node '{node.Identifer()}' must not have Variable Name field empty as it is being used to capture information. Variable Name will allow you to refer the captured information later in the flow to display or to send it to any APIs");
                }
            }
            if (respMessage.Count > 0)
            {
                return(res.SetMsg(string.Join("\r\n", respMessage)).SetStatus(CVS.Error));
            }
            return(res.Valid());
        }
Esempio n. 3
0
        /// <summary>
        /// Should be the first in the validator's list
        /// </summary>
        /// <param name="pack"></param>
        /// <returns></returns>
        private static CVR EmptyValidation_ERROR(ChatFlowPack pack)
        {
            var res = new CVR();

            if (pack == null || pack.ChatNodes == null || pack.ChatNodes.Count == 0)
            {
                return(res.SetMsg("Error: The chat flow is empty! Please add at least one chat node").SetStatus(CVS.Error));
            }
            return(res.Valid());
        }
Esempio n. 4
0
        public static CVR AllNodesShouldHaveAName_WARNING(ChatFlowPack pack)
        {
            var res            = new CVR();
            var emptyNameNodes = pack.ChatNodes.Where(x => string.IsNullOrWhiteSpace(x.Name)).ToList();

            if (emptyNameNodes.Count > 0)
            {
                return(res.SetMsg($"Warning: {emptyNameNodes.Count} chat node(s) have empty name(s). It's recommended to give each node a name which can help you identify it. These are the node ids, search them and give them a name. ({emptyNameNodes.Select(x => x.Id).Join(", ")})").SetStatus(ChatFlowValidationStatus.Warning));
            }
            return(res.Valid());
        }
Esempio n. 5
0
        public static CVR OnlyOneTextInputButtonIsAllowedPerNode_ERROR(ChatFlowPack pack)
        {
            var res  = new CVR();
            var msgs = new List <string>();

            foreach (var node in pack.ChatNodes.Where(x => x.Buttons != null && x.Buttons.Count > 0))
            {
                if (node.Buttons.Count(x => InputTextButtonTypes.Contains(x.ButtonType)) > 1)
                {
                    msgs.Add($"Error: Node '{node.Identifer()}' has multiple text input buttons. Only one text input button is allowed per node.");
                }
            }
            if (msgs.Count > 0)
            {
                return(res.SetMsg(msgs.Join("\r\n")).SetStatus(CVS.Error));
            }
            return(res.Valid());
        }
Esempio n. 6
0
        private static CVR EmptyNodeValidation_ERROR(ChatFlowPack pack)
        {
            var res         = new CVR();
            var respMessage = new List <string>();

            foreach (var node in pack.ChatNodes.Where(x => x.NodeType == NodeTypeEnum.Combination))
            {
                if (node.Sections == null || node.Sections.Count <= 0)
                {
                    respMessage.Add($"Error: Node '{node.Identifer()}' has no sections/content! Combination nodes cannot be empty.");
                }
            }

            if (respMessage.Count > 0)
            {
                return(res.SetMsg(string.Join("\r\n", respMessage)).SetStatus(CVS.Error));
            }
            return(res.Valid());
        }
Esempio n. 7
0
        public static CVR MandatoryFieldsPerButtonType_ERROR(ChatFlowPack pack)
        {
            var res  = new CVR();
            var msgs = new List <string>();

            foreach (var node in pack.ChatNodes.Where(x => x.Buttons != null && x.Buttons.Count > 0))
            {
                var nodeMsg = $"Error: In node '{node.Identifer()}', ";
                foreach (var btn in node.Buttons)
                {
                    if (node.NodeType == NodeTypeEnum.Combination && btn.ButtonType == ButtonTypeEnum.NextNode && !btn.Hidden && string.IsNullOrWhiteSpace(btn.NextNodeId))
                    {
                        msgs.Add($"{nodeMsg} button '{btn}' is of type '{btn.ButtonType}' and is not hidden. So, it must be mapped to a node. Any NextNode button which is not hidden must be mapped to a next node.");
                    }
                    if (node.NodeType == NodeTypeEnum.Combination && btn.ButtonType == ButtonTypeEnum.NextNode && !btn.Hidden && (string.IsNullOrWhiteSpace(btn.ButtonName) && string.IsNullOrWhiteSpace(btn.ButtonText)))
                    {
                        msgs.Add($"{nodeMsg} button '{btn}' is of type '{btn.ButtonType}' and is not hidden. So, it must have text! Any NextNode button which is not hidden must have text which is displayed on the button.");
                    }
                    if (btn.ButtonType == ButtonTypeEnum.DeepLink && string.IsNullOrWhiteSpace(btn.DeepLinkUrl))
                    {
                        msgs.Add($"{nodeMsg} button '{btn}' is of type '{btn.ButtonType}' but the field '{nameof(btn.DeepLinkUrl)}' is empty! Set it to the target deeplink url.");
                    }
                    if ((btn.ButtonType == ButtonTypeEnum.FetchChatFlow || btn.ButtonType == ButtonTypeEnum.OpenUrl) && string.IsNullOrWhiteSpace(btn.Url))
                    {
                        msgs.Add($"{nodeMsg} button '{btn}' is of type '{btn.ButtonType}' but the field '{nameof(btn.Url)}' is empty! Set it to the target url.");
                    }
                    if (btn.ButtonType == ButtonTypeEnum.FetchChatFlow && string.IsNullOrWhiteSpace(btn.NextNodeId))
                    {
                        msgs.Add($"{nodeMsg} button '{btn}' is of type '{btn.ButtonType}' but the field '{nameof(btn.NextNodeId)}' is empty! Set it to the target next node id.");
                    }
                }
            }
            if (msgs.Count > 0)
            {
                return(res.SetMsg(msgs.Join("\r\n")).SetStatus(CVS.Error));
            }
            return(res.Valid());
        }
Esempio n. 8
0
        public static CVR CarouselSectionsValidations_ERROR(ChatFlowPack pack)
        {
            var res = new CVR();
            var carouselSectionNodes = pack.ChatNodes.Where(x => x.Sections.Any(y => y.SectionType == SectionTypeEnum.Carousel));
            var msgs = new List <string>();

            foreach (var node in carouselSectionNodes)
            {
                var nodeMsg = $"Error: In node '{node.Identifer()}' ";

                foreach (var sec in node.Sections.Where(x => x.SectionType == SectionTypeEnum.Carousel))
                {
                    var carSec    = sec as CarouselSection;
                    var carSecMsg = $"{nodeMsg} in Carousel Section '{carSec}' ";
                    if (carSec.Items == null || carSec.Items.Count == 0)
                    {
                        msgs.Add($"{carSecMsg} has no items!");
                        res.SetStatus(CVS.Error);
                        continue;
                    }
                    foreach (var carItem in carSec.Items)
                    {
                        var carItemMsg = $"{carSecMsg} Carousel Item '{carItem}' ";
                        if (carItem.Buttons != null)
                        {
                            if (carItem.Buttons.Count > 3)
                            {
                                msgs.Add($"{carItemMsg} has more than 3 buttons! A carousel item can have maximum of 3 buttons.");
                                res.SetStatus(CVS.Error);
                            }

                            foreach (var carBtn in carItem.Buttons)
                            {
                                var carItemBtnMsg = $"{carItemMsg} Carousel Button '{carBtn}' ";
                                if (string.IsNullOrWhiteSpace(carBtn.Text))
                                {
                                    msgs.Add($"{carItemBtnMsg}, text is empty!");
                                    res.SetStatus(CVS.Error);
                                }
                                if ((carBtn.Type == CardButtonType.DeepLink || carBtn.Type == CardButtonType.OpenUrl) && string.IsNullOrWhiteSpace(carBtn.Url))
                                {
                                    msgs.Add($"{carItemBtnMsg} is of type '{carBtn.Type}' but the '{nameof(carBtn.Url)}' field is empty! Set it to the target url.");
                                    res.SetStatus(CVS.Error);
                                }
                                if (carBtn.Type == CardButtonType.NextNode && string.IsNullOrWhiteSpace(carBtn.NextNodeId))
                                {
                                    msgs.Add($"{carItemBtnMsg} is of type '{carBtn.Type}' but the '{nameof(carBtn.NextNodeId)}' field is empty! Set it to the target Next Node Id.");
                                    res.SetStatus(CVS.Error);
                                }
                            }
                        }
                    }
                }
            }

            if (msgs.Count > 0)
            {
                return(res.SetMsg(msgs.Join("\r\n")).SetStatus(CVS.Error));
            }
            return(res.Valid());
        }