public async Task <Response> GetResponseAsync(Request request) { var dialog = await _dialogflowService.GetResponseAsync(request); Response response; switch (dialog.IntentName) { case "DatesPeriods": response = GetDatesPeriodsReponse(dialog); break; case "Dates": response = GetDatesReponse(dialog); break; default: response = new Response { Text = dialog.Response, Finished = dialog.EndConversation }; break; } return(response); }
public async Task <Response> GetResponseAsync(Request request) { var dialog = await _dialogflowService.GetResponseAsync(request); var response = new Response { Text = dialog?.Response, Finished = dialog?.EndConversation ?? false, Buttons = dialog?.Buttons, ScopeKey = dialog?.ScopeKey }; TrySetSavedText(request.SessionId, dialog); var resetTextIndex = string.Empty; var isGotResetParameter = dialog?.Parameters.TryGetValue("resetTextIndex", out resetTextIndex) ?? false; if (isGotResetParameter && string.Equals(resetTextIndex, bool.TrueString, StringComparison.InvariantCultureIgnoreCase)) { request.NextTextIndex = 0; } if (string.Equals(dialog?.Action, "GetText")) { var textKey = dialog?.GetParameters("textKey").FirstOrDefault(); response = await GetText(request, dialog?.Response, textKey); } response.Emotions = GetEmotions(dialog); response.NextTextIndex = request.NextTextIndex; response.Text = GetResponseText(request.Appeal, response.Text); response.Buttons = AddButtonsFromPayload(response.Buttons, dialog?.Payload, request.Source); return(response); }