Exemple #1
0
        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 <FlightBooking>(stepContext.Context, cancellationToken);

            switch (luisResult.TopIntent().intent)
            {
            case FlightBooking.Intent.BookFlight:
                await ShowWarningForUnsupportedCities(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.Airport,
                    Origin      = luisResult.FromEntities.Airport,
                    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 FlightBooking.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 FlightBooking.Intent.GetBridgeTypology:
                BridgeTopologyDetails topologyDetails = new BridgeTopologyDetails()
                {
                    Country = luisResult.Country
                };
                return(await stepContext.BeginDialogAsync(nameof(BridgeTypologyDialog), topologyDetails, cancellationToken));

            //var getBridgeMessageText = "Sick dude, what kind of bridge?";
            //var GgtBridgeMessageMessage = MessageFactory.Text(getBridgeMessageText, getBridgeMessageText, InputHints.IgnoringInput);
            //await stepContext.Context.SendActivityAsync(GgtBridgeMessageMessage, cancellationToken);
            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));
        }
Exemple #2
0
        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 <FlightBooking>(stepContext.Context, cancellationToken);

            switch (luisResult.TopIntent().intent)
            {
            case FlightBooking.Intent.BookFlight:
                //await ShowWarningForUnsupportedCities(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.Airport,
                    Origin      = luisResult.FromEntities.Airport,
                    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 FlightBooking.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 FlightBooking.Intent.GetBridgeTypology:
                BridgeTopologyDetails topologyDetails = new BridgeTopologyDetails()
                {
                    Country  = luisResult.Country,
                    Material = luisResult.Material,
                    MaxSpan  = luisResult.MaxSpan
                };
                return(await stepContext.BeginDialogAsync(nameof(BridgeTypologyDialog), topologyDetails, cancellationToken));

            //var getBridgeMessageText = "Sick dude, what kind of bridge?";
            //var GgtBridgeMessageMessage = MessageFactory.Text(getBridgeMessageText, getBridgeMessageText, InputHints.IgnoringInput);
            //await stepContext.Context.SendActivityAsync(GgtBridgeMessageMessage, cancellationToken);
            case FlightBooking.Intent.GetPersonFromSkill:
                var skill = luisResult.Skill;

                var getPersonFromSkillMessageText = string.Empty;
                try
                {
                    var foundPerson = GetDataFromDB.FindPersonWithSkill(skill.ToLower());
                    getPersonFromSkillMessageText = $"The people below are great at {skill}:\r\n{foundPerson}";
                }
                catch (Exception e)
                {
                    getPersonFromSkillMessageText = e.ToString();
                    //throw;
                }
                var getPersonFromSkillMessage = MessageFactory.Text(getPersonFromSkillMessageText, getPersonFromSkillMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(getPersonFromSkillMessage, cancellationToken);

                break;

            case FlightBooking.Intent.GetTranslation:
                var word           = luisResult.Word;
                var language       = luisResult.Language;
                var translatedWord = GetDataFromDB.FindWord(word.ToLower(), language);
                var getTranslatedWordMessageText = $"The {language} word for {word} is {translatedWord}";
                var getTranslatedWordMessage     = MessageFactory.Text(getTranslatedWordMessageText, getTranslatedWordMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(getTranslatedWordMessage, cancellationToken);

                break;

            case FlightBooking.Intent.GetProjectFromTypology:
                string getProjectFromTypoMessageText = string.Empty;
                try
                {
                    var typologi = luisResult.Typology;
                    if (typologi != null)
                    {
                        var matchedProjects = GetDataFromDB.FindProjcetByTypology(typologi.ToLower());
                        getProjectFromTypoMessageText = $"The projects below are using the same typology as {typologi}:\r\n{matchedProjects}";
                    }
                    else
                    {
                        getProjectFromTypoMessageText = "Try again.";
                    }
                }
                catch (Exception e)
                {
                    getProjectFromTypoMessageText = e.ToString();
                    //throw ;
                }
                var getProjectFromTypoMessage = MessageFactory.Text(getProjectFromTypoMessageText, getProjectFromTypoMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(getProjectFromTypoMessage, cancellationToken);

                break;

            case FlightBooking.Intent.GetPersonFromProject:
                var project = luisResult.Project;
                var people  = "bunch of people";
                var getPersonFromProjectMessageText = $"{project} is great at {people}";
                var getPersonFromProjectMessage     = MessageFactory.Text(getPersonFromProjectMessageText, getPersonFromProjectMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(getPersonFromProjectMessage, cancellationToken);

                break;

            case FlightBooking.Intent.ShowProject:
                var    projectModel = luisResult.Project;
                string url          = StreamProject.GetProjectUrl(projectModel);
                string response     = string.Empty;
                if (url == null)
                {
                    response = $"sorry couldn't find that model.";
                }
                else
                {
                    response  = $"A 3d view of the model '{projectModel}' can be found here: ";
                    response += url;
                }
                var msgMessage1 = MessageFactory.Text(response, response, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(msgMessage1, cancellationToken);

                break;

            case FlightBooking.Intent.GenerateParametricBuilding:
                var curviness = luisResult.Curviness;
                var levels    = luisResult.Levels;
                StreamProject.StreamBuilding(levels, curviness);
                string msg = $"I have generated a building with {levels} levels. Please see the link here: ";
                msg += "http://bot.continuum.codes/viewer.html";
                var msgMessage = MessageFactory.Text(msg, msg, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(msgMessage, cancellationToken);

                break;

            case FlightBooking.Intent.WhatsNext:
                var whatsnext = "Thank you! I will continue to learn from all of you. Your quesions will help me grow my knowledge such that I can better support you in the future. A first step is to run micro - applications to help you solve your problems and, as my database grows, I will be able to suggest solutions to increasingly complex technical problems.";
                //var matchedProjects = GetDataFromDB.FindProjcetByTypology(typologi.ToLower());
                //var getProjectFromTypoMessageText = $"The projects below are using the same typology as {typologi}:\r\n{matchedProjects}";
                var whatsnextMsg = MessageFactory.Text(whatsnext, whatsnext, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(whatsnextMsg, cancellationToken);

                break;

            default:
                var act = stepContext?.Context?.Activity?.Text;
                if (_askCounter > 0 && act != "Hello")
                {
                    return(await stepContext.BeginDialogAsync(nameof(CreatePostDialog), null, cancellationToken));
                }

                break;
                // 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;
            }
            _askCounter++;
            return(await stepContext.NextAsync(null, cancellationToken));
        }