/// <summary> /// Creates the account details adaptive card. /// </summary> /// <param name="accountDetails">The account details.</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> private Attachment CreateAccountDetailsAdaptiveCard(FindAccountDetails accountDetails) { var card = new AdaptiveCard("1.0"); 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 = "Basic information", Spacing = AdaptiveSpacing.Medium, Size = AdaptiveTextSize.Default, Weight = AdaptiveTextWeight.Bolder, Wrap = true, MaxLines = 0 }, new AdaptiveFactSet { Facts = new List <AdaptiveFact> { new AdaptiveFact { Title = "Title", Value = $"**{accountDetails.Title}**" }, new AdaptiveFact { Title = "First Name", Value = $"**{accountDetails.FirstName}**" }, new AdaptiveFact { Title = "Last Name", Value = $"**{accountDetails.LastName}**" }, new AdaptiveFact { Title = "Identity Number", Value = $"**{accountDetails.IdentityNumber}**" }, new AdaptiveFact { Title = "Cellphone Number", Value = $"**{accountDetails.CellphoneNumber}**" } } } }, Separator = true } } } }; AdaptiveContainer container = new AdaptiveContainer { Items = adaptiveElements }; card.Body.Add(container); var attachment = new Attachment() { ContentType = AdaptiveCard.ContentType, Content = card }; return(attachment); }
/// <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)); }