/// <summary> /// Query response /// </summary> /// <param name="context"></param> /// <param name="result"></param> /// <returns></returns> private async Task OnQueryResponseSelected(IDialogContext context, IAwaitable <string> result) { Trace.TraceInformation("AppAuthDialog::OnSubOptionSelected"); string query = await result; UserProfile userInfo = context.ConversationData.GetValue <UserProfile>(UserSessionDataKey); userInfo.Query = query; context.ConversationData.SetValue <UserProfile>(UserSessionDataKey, userInfo); if (query == "No") { IFarmingOperations ihro = ServiceLocator.GetFarmingOperations(); ihro.UpdateQueries(userInfo.Name, userInfo.EMail, userInfo.Query, string.Empty); await context.PostAsync($"Thanks " + userInfo.Name + " for contacting us. Our expert team will reach you shortly."); context.Done <object>(null); } else { PromptDialog.Attachment(context, OnUploadImageResponse, "Please upload any images / media files for your query. "); } }
/// <summary> /// This method will get selected once the symptom selected. /// </summary> /// <param name="context"></param> /// <param name="result"></param> /// <returns></returns> private async Task OnSymptomsSelected(IDialogContext context, IAwaitable <string> result) { try { Trace.TraceInformation("AppAuthDialog::OnSubOptionSelected"); string optionSelected = await result; UserProfile userInfo = context.ConversationData.GetValue <UserProfile>(UserSessionDataKey); userInfo.SearchOption = optionSelected; reservationChoice = optionSelected; string subCategory = userInfo.CropSubCategory; context.ConversationData.SetValue <UserProfile>(UserSessionDataKey, userInfo); IFarmingOperations ihro = ServiceLocator.GetFarmingOperations(); await context.PostAsync(ihro.GetSymptomResults(optionSelected, subCategory)); IList <string> menuOptions = new List <string> { "Yes", "No" }; PromptDialog.Choice(context, OnResponseSelected, menuOptions, "Did you get answer for your query?", "Not a valid option", 2); } catch (TooManyAttemptsException ex) { string fullError = ex.ToString(); Trace.TraceError(fullError); await context.PostAsync($"Sorry, I don't understand."); context.Done(true); } }
/// <summary> /// Start method for chatbot /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task StartAsync(IDialogContext context) { Trace.TraceInformation("FarmingAssistanceDialog::StartAsync"); await context.PostAsync("Welcome to Farm Assistance Services!"); UserProfile userInfo = context.ConversationData.GetValue <UserProfile>(UserSessionDataKey); IFarmingOperations ihro = ServiceLocator.GetFarmingOperations(); IList <string> menuOptions = await ihro.GetCropCategories(userInfo.Id); PromptDialog.Choice(context, OnOptionSelected, menuOptions, "Please choose type of a farm that you looking for assistance:", "Not a valid option", 2); }
/// <summary> /// To upload image responses from user. /// </summary> /// <param name="context"></param> /// <param name="result"></param> /// <returns></returns> private async Task OnUploadImageResponse(IDialogContext context, IAwaitable <IEnumerable <Attachment> > result) { var attachments = await result; UserProfile userInfo = context.ConversationData.GetValue <UserProfile>(UserSessionDataKey); IFarmingOperations ihro = ServiceLocator.GetFarmingOperations(); foreach (var attachment in attachments) { ihro.UpdateQueries(userInfo.Name, userInfo.EMail, userInfo.Query, attachment.ContentUrl); } await context.PostAsync($"Thanks " + userInfo.Name + " for contacting us. Our expert team will reach you shortly."); context.Done <object>(null); }
/// <summary> /// This method will get executed once sub category will get selected. /// </summary> /// <param name="context"></param> /// <param name="result"></param> /// <returns></returns> private async Task OnSubOptionSelected(IDialogContext context, IAwaitable <string> result) { try { Trace.TraceInformation("AppAuthDialog::OnSubOptionSelected"); string optionSelected = await result; UserProfile userInfo = context.ConversationData.GetValue <UserProfile>(UserSessionDataKey); userInfo.CropSubCategory = optionSelected; reservationChoice = optionSelected; context.ConversationData.SetValue <UserProfile>(UserSessionDataKey, userInfo); IFarmingOperations ihro = ServiceLocator.GetFarmingOperations(); IList <string> menuOptions = await ihro.GetSearchOptions(optionSelected); if (menuOptions.Count > 0) { PromptDialog.Choice(context, OnSearchOptionSelected, menuOptions, "Please choose Search options to serve you better", "Not a valid option", 2); } else { await context.PostAsync($"Sorry. I haven't trained in this area yet. "); PostQuery(context); } } catch (TooManyAttemptsException ex) { string fullError = ex.ToString(); Trace.TraceError(fullError); await context.PostAsync($"Sorry, I don't understand."); context.Done(true); } }