Esempio n. 1
0
        /// <summary>
        /// Gets the facts.
        /// </summary>
        /// <param name="stocks">The stocks.</param>
        /// <returns></returns>
        private List <AdaptiveFact> GetFacts(List <Stock> stocks, FindStockDetails stockDetails)
        {
            List <AdaptiveFact> facts = new List <AdaptiveFact>();

            foreach (var stock in stocks)
            {
                string FactValue = "";

                if (string.IsNullOrWhiteSpace(stockDetails.Brand))
                {
                    FactValue = $"{stock.Brand}";
                }
                if (string.IsNullOrWhiteSpace(stockDetails.Style))
                {
                    FactValue = $"{FactValue}  :  {stock.Style}";
                }
                if (string.IsNullOrWhiteSpace(stockDetails.Color))
                {
                    FactValue = $"{FactValue}  :  {stock.Color}";
                }
                if (string.IsNullOrWhiteSpace(stockDetails.Size))
                {
                    FactValue = $"{FactValue}  :  {stock.Size}";
                }

                facts.Add(new AdaptiveFact
                {
                    Title = stock.Quantity.ToString(),
                    Value = FactValue = $"{FactValue}  :  {stock.Branch}"
                });
            }
            return(facts);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the facts in columns2.
        /// </summary>
        /// <param name="stocks">The stocks.</param>
        /// <param name="stockDetails">The stock details.</param>
        /// <returns></returns>
        private List <AdaptiveColumn> GetFactsInColumns(List <Stock> stocks, FindStockDetails stockDetails)
        {
            List <AdaptiveElement> QtyElements    = new List <AdaptiveElement>();
            List <AdaptiveElement> SizeElements   = new List <AdaptiveElement>();
            List <AdaptiveElement> BranchElements = new List <AdaptiveElement>();
            List <AdaptiveElement> IBTElements    = new List <AdaptiveElement>();

            //build the headers items.
            QtyElements.Add(CreateTextBlock("**Quantity**"));
            stockDetails.Garment = stocks[0].Garment;
            stockDetails.Brand   = stocks[0].Brand;
            stockDetails.Style   = stocks[0].Style;
            stockDetails.Color   = stocks[0].Color;
            stockDetails.Size    = stocks[0].Size;
            BranchElements.Add(CreateTextBlock("**Branch**"));
            IBTElements.Add(CreateTextBlock("**IBT**"));

            //load all the result items
            int item = 0;

            foreach (var stock in stocks)
            {
                QtyElements.Add(CreateTextBlock(stock.Quantity.ToString()));
                if (string.IsNullOrWhiteSpace(stockDetails.Size))
                {
                    SizeElements.Add(CreateTextBlock(stock.Size));
                }
                BranchElements.Add(CreateTextBlock(stock.Branch));
                IBTElements.Add(
                    new AdaptiveNumberInput
                {
                    Id  = "qtr_" + item++,
                    Max = stock.Quantity,
                    Min = 0
                });
            }

            List <AdaptiveColumn> ColumnList = new List <AdaptiveColumn>();

            ColumnList.Add(new AdaptiveColumn
            {
                Items = QtyElements,
                Width = AdaptiveColumnWidth.Auto
            });
            ColumnList.Add(new AdaptiveColumn
            {
                Items = BranchElements,
                Width = AdaptiveColumnWidth.Auto
            });
            ColumnList.Add(new AdaptiveColumn
            {
                Items = IBTElements,
                Width = "40px"
            });

            return(ColumnList);
        }
Esempio n. 3
0
        /// <summary>
        /// Finds the stock by filters.
        /// </summary>
        /// <param name="findStockDetails">The find stock details.</param>
        /// <returns></returns>
        public async Task <List <Stock> > FindStockByFilters(FindStockDetails findStockDetails)
        {
            string sql = $"SELECT * FROM dbo.tStock WHERE Garment = '{findStockDetails.Garment}'";

            if (!string.IsNullOrWhiteSpace(findStockDetails.Color))
            {
                sql = $"{sql} AND Color = '{findStockDetails.Color}'";
            }

            if (!string.IsNullOrWhiteSpace(findStockDetails.Size))
            {
                sql = $"{sql} AND Size = '{findStockDetails.Size}'";
            }

            if (!string.IsNullOrWhiteSpace(findStockDetails.Brand))
            {
                sql = $"{sql} AND Brand = '{findStockDetails.Brand}'";
            }

            return(await ExecWithConnAsync(async db => {
                var resultList = await db.QueryAsync <Stock>(sql, commandType: System.Data.CommandType.Text).ConfigureAwait(false);
                return resultList.ToList();
            }));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the stock adaptive card.
        /// </summary>
        /// <param name="facts">The facts.</param>
        /// <returns></returns>
        private Attachment CreateStockAdaptiveCard(List <AdaptiveColumn> facts, FindStockDetails stockDetails)
        {
            var card = new AdaptiveCard("1.0");

            string FactHeader  = "";
            string SearchValue = $"Sku = {stockDetails.SkuCode}{Environment.NewLine}";

            SearchValue = $"{SearchValue}**The product details are:**{Environment.NewLine}";

            if (!string.IsNullOrWhiteSpace(stockDetails.Garment))
            {
                SearchValue = $"{SearchValue}Garment = {stockDetails.Garment}{Environment.NewLine}";
            }
            else
            {
                FactHeader = $"**Garment** ";
            }

            if (!string.IsNullOrWhiteSpace(stockDetails.Brand))
            {
                SearchValue = $"{SearchValue}Brand = {stockDetails.Brand}{Environment.NewLine}";
            }
            else
            {
                FactHeader = $"**Brand** ";
            }

            if (!string.IsNullOrWhiteSpace(stockDetails.Style))
            {
                SearchValue = $"{SearchValue}Style = {stockDetails.Style}{Environment.NewLine}";
            }
            else
            {
                FactHeader = $"{FactHeader} **Style** ";
            }

            if (!string.IsNullOrWhiteSpace(stockDetails.Color))
            {
                SearchValue = $"{SearchValue}Color = {stockDetails.Color}{Environment.NewLine}";
            }
            else
            {
                FactHeader = $"{FactHeader} **Color** ";
            }

            if (!string.IsNullOrWhiteSpace(stockDetails.Size))
            {
                SearchValue = $"{SearchValue}Size = {stockDetails.Size}{Environment.NewLine}";
            }
            else
            {
                FactHeader = $"{FactHeader} **Size**  ";
            }


            List <AdaptiveElement> adaptiveElements = new List <AdaptiveElement>()
            {
                new AdaptiveColumnSet
                {
                    Columns = new List <AdaptiveColumn>()
                    {
                        new AdaptiveColumn
                        {
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveImage
                                {
                                    Url  = new Uri("https://github.com/enablers104/chatbot/blob/master/Images/Logo.png?raw=true"),
                                    Size = AdaptiveImageSize.Small
                                },
                                new AdaptiveTextBlock
                                {
                                    Text     = "Inventory search",
                                    Spacing  = AdaptiveSpacing.Medium,
                                    Size     = AdaptiveTextSize.Default,
                                    Weight   = AdaptiveTextWeight.Bolder,
                                    Wrap     = true,
                                    MaxLines = 0
                                },
                                new AdaptiveTextBlock
                                {
                                    Text     = "Based on:" + Environment.NewLine + SearchValue + "**We have the following stock in the following branches:**",
                                    Size     = AdaptiveTextSize.Default,
                                    IsSubtle = true,
                                    Wrap     = true,
                                    MaxLines = 0
                                },
                                new AdaptiveColumnSet
                                {
                                    Columns = facts,
                                    Bleed   = true,
                                }
                            },
                            Separator = true
                        }
                    }
                }
            };

            AdaptiveContainer container = new AdaptiveContainer
            {
                Items = adaptiveElements
            };

            card.Body.Add(container);

            var attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card
            };

            return(attachment);
        }
Esempio n. 5
0
        /// <summary>
        /// Acts the step asynchronous.
        /// </summary>
        /// <param name="stepContext">The step context.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                // LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance.
                return(await stepContext.BeginDialogAsync(nameof(BookingDialog), new BookingDetails(), cancellationToken));
            }

            // Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)
            var luisResult = await _luisRecognizer.RecognizeAsync <LiriModel>(stepContext.Context, cancellationToken);

            switch (luisResult.TopIntent().intent)
            {
            case LiriModel.Intent.BookIBT:
                await ShowWarningForUnsupportedBranches(stepContext.Context, luisResult, cancellationToken);

                // Initialize BookingDetails with any entities we may have found in the response.
                var bookingDetails = new BookingDetails()
                {
                    // Get destination and origin from the composite entities arrays.
                    Destination = luisResult.ToEntities.Branch,
                    Origin      = luisResult.FromEntities.Branch,
                    TravelDate  = luisResult.TravelDate,
                };

                // Run the BookingDialog giving it whatever details we have from the LUIS call, it will fill out the remainder.
                return(await stepContext.BeginDialogAsync(nameof(BookingDialog), bookingDetails, cancellationToken));

            case LiriModel.Intent.TFGAccount:

                // Initialize BookingDetails with any entities we may have found in the response.
                var findAccountDetails = new FindAccountDetails()
                {
                    // Get destination and origin from the composite entities arrays.
                    CellphoneNumber = luisResult.phonenumber,
                    FirstName       = luisResult.FirstName,
                    IdentityNumber  = luisResult.IDNumber,
                    LastName        = luisResult.LastName,
                    Title           = luisResult.Title,
                };

                // Run the BookingDialog giving it whatever details we have from the LUIS call, it will fill out the remainder.
                return(await stepContext.BeginDialogAsync(nameof(AccountDialog), findAccountDetails, cancellationToken));

            case LiriModel.Intent.GetWeather:
                // We haven't implemented the GetWeatherDialog so we just display a TODO message.
                var getWeatherMessageText = "TODO: get weather flow here";
                var getWeatherMessage     = MessageFactory.Text(getWeatherMessageText, getWeatherMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(getWeatherMessage, cancellationToken);

                break;

            case LiriModel.Intent.TFGLegals:

                var    legal       = stepContext.Result;
                string msgResponse = "HINT: For Legal enquiry (Terms and Conditions or Privacy Statement)";
                if (legal.ToString().ToLower().Contains("terms"))
                {
                    msgResponse = "[Click for terms and conditions](https://www.tfg.co.za/terms-and-conditions)";
                }
                if (legal.ToString().ToLower().Contains("privacy"))
                {
                    msgResponse = "[Click for privacy statement](https://www.tfg.co.za/privacy-statement)";
                }
                var LegalMessage = MessageFactory.Text(msgResponse, msgResponse, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(LegalMessage, cancellationToken);

                break;

            case LiriModel.Intent.TFGStock:
                // Initialize StockDetails with any entities we may have found in the response.
                var stockDetails = new FindStockDetails()
                {
                    // Get Stock Entities entities arrays.
                    Garment = luisResult.Garment,
                    Color   = luisResult.Color,
                    Brand   = luisResult.Brand,
                    Size    = luisResult.Size
                };

                return(await stepContext.BeginDialogAsync(nameof(FindStockDialog), stockDetails, cancellationToken));

            case LiriModel.Intent.TFGSkuLookup:
                var stock = new FindStockDetails()
                {
                    SkuCode = luisResult.SkuCode
                };

                return(await stepContext.BeginDialogAsync(nameof(SkuLookupDialog), stock, cancellationToken));

            case LiriModel.Intent.TFGHR:
                var findHRDetails = new FindHRDetails()
                {
                    QueryType            = luisResult.QueryType,
                    IdentificationNumber = luisResult.EmployeeNumber
                };

                return(await stepContext.BeginDialogAsync(nameof(HRDialog), findHRDetails, cancellationToken));

            case LiriModel.Intent.Cancel:
                StringBuilder cancelMessageText = new StringBuilder();
                cancelMessageText.AppendLine($"Thank you for using LiRi the friendly BOT.");
                cancelMessageText.AppendLine($"Good bye!");
                var goodByeMessage = MessageFactory.Text(cancelMessageText.ToString(), cancelMessageText.ToString(), InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(goodByeMessage, cancellationToken);

                break;

            default:
                // Catch all for unhandled intents
                var didntUnderstandMessageText = $"Sorry, I didn't get that. Please try asking in a different way (intent was {luisResult.TopIntent().intent})";
                var didntUnderstandMessage     = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken);

                break;
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }