/// <summary> /// Translates text /// </summary> /// <param name="text">Text to translate</param> /// <param name="languageFrom">original language</param> /// <param name="languageTo">final language</param> /// <returns></returns> public static async Task <string> TranslateAsync(string text, string languageFrom = "en", string languageTo = "es") { var translation = string.Empty; try { var translateResponse = await TranslateRequest(string.Format(TranslateUrlTemplate, text, languageFrom, languageTo, "general"), MicrosoftTranslatorService.microsoftTranslatorKey); if (translateResponse.IsSuccessStatusCode) { System.Runtime.Serialization.DataContractSerializer dcs = new System.Runtime.Serialization.DataContractSerializer(Type.GetType("System.String")); var stream = await translateResponse.Content.ReadAsStreamAsync(); translation = (string)dcs.ReadObject(stream); } else { translation = "Sorry, we couldn't translate your message"; } } catch (Exception ex) { translation = "Sorry, there was an error translating your message"; } DiagnosticsUtil.TraceInformation($"Translating: original {text} - result: {translation}"); return(translation); }
public override async Task StartAsync(IDialogContext context) { DiagnosticsUtil.TraceInformation($"SurveyLUISDialog- StartAsync"); _context = new LUISDialogContext(context.Activity.From.Id); _context.Refresh(IntentType.StartDialog, null); _context.Questions = new List <Question>() { new Question() { Id = 0, Subject = "Años", Text = "¿Cuántos años tienes", EntityType = EntityType.Age }, new Question() { Id = 1, Subject = "Lugar de estudios", Text = "¿Dónde estudias", EntityType = EntityType.Location }, new Question() { Id = 2, Subject = "Opinion", Text = "¿Te ha gustado la charla?", EntityType = EntityType.Opinion }, }; Response response = GetNextResponse(); await SendResponse(context, response); }
public async Task None(IDialogContext context, LuisResult result) { DiagnosticsUtil.TraceInformation($"SurveyLUISDialog- Empty"); _context.Refresh(IntentType.None, result); var response = GetNextResponse(); await SendResponse(context, response); }
public async Task StartDialog(IDialogContext context, LuisResult result) { DiagnosticsUtil.TraceInformation($"MainLUISDialog- StartDialog"); _context.Refresh(IntentType.StartDialog, result); var response = GetNextResponse(); await SendResponse(context, response); }
public async Task Opinion(IDialogContext context, LuisResult result) { DiagnosticsUtil.TraceInformation($"SurveyLUISDialog- Opinion"); _context.Refresh(IntentType.Opinion, result); _context.CheckAnswer(result); var response = GetNextResponse(); await SendResponse(context, response); }
public async Task ReadyData(IDialogContext context, LuisResult result) { DiagnosticsUtil.TraceInformation($"MainLUISDialog- ReadyData"); _context.Refresh(IntentType.Ready, result); //var response = GetNextResponse(); var surveyDialogInfo = new SurveyLUISDialog.Models.SurveyLUISDialogInfo(_info); _flowType = FlowType.Survey; context.Call(new SurveyLUISDialog.SurveyLUISDialog(surveyDialogInfo), SurveyLUISDialogDone); await Task.FromResult(0); }
// Send response private async Task SendResponse(IDialogContext context, Response response) { IMessageActivity activity; // Ensure original translation DiagnosticsUtil.TraceInformation($"Response locale {_info.Info.Locale}"); response.Message = await TranslationUtil.ReverseFromSpanishTranslation(response.Message, _info.Info.Locale); // Build message switch (_info.Info.ChannelId) { case AlexaBotframework.BotFrameworkBot.Helpers.Constants.Channels.DirectLine: activity = BuildDirectLineMessage(context, response); break; default: activity = BuildDefaultMessage(context, response); break; } // Send response await context.PostAsync(activity); // Check end conversation if (response.EndConversation) { DialogResultType resultType = _context.SurveyCompleted ? DialogResultType.Completed : DialogResultType.Suspended; context.Done(resultType); } else { context.Wait(MessageReceived); } }
public SurveyLUISDialog(SurveyLUISDialogInfo info) { DiagnosticsUtil.TraceInformation($"SurveyLUISDialog constructor"); _info = info; }
public MainLUISDialog(DialogInfo info) { DiagnosticsUtil.TraceInformation($"MainLUISDialog constructor"); _info = info; _flowType = FlowType.Normal; }