Example #1
0
        private async Task DispatchToTopIntentAsync(ITurnContext <IMessageActivity> turnContext, string intent, LuisReconizedModel recognizerResult, CancellationToken cancellationToken)
        {
            //if (recognizerResult.Intents[0].Score < 0.8) { intent = "None";  };

            switch (intent)
            {
            case "searchDestinations":

                var destinations      = new Destinations();
                var destinationType   = recognizerResult.Entities.destinationType[0][0];
                var _listDestinations = destinations.GetDestination(destinationType);
                var messagge          = "Estos son los destinos de " + destinationType + " disponibles:\r";

                foreach (var d in _listDestinations)
                {
                    messagge += "- " + d + " \r";
                }

                var standardCard = new StandardCard();
                standardCard.Title       = "Destinos disponibles";
                standardCard.Description = messagge;

                var response = ((Activity)turnContext.Activity).CreateReply();
                var reply    = standardCard.GetCard();

                var result = new Attachment()
                {
                    ContentType = "application/vnd.microsoft.card.adaptive",
                    Content     = reply
                };

                response.Attachments = new List <Attachment>()
                {
                    result
                };
                await turnContext.SendActivityAsync(response, cancellationToken);

                break;

            case "purchaseTicket":


                var destination = ParserLuisHelper.GetDestination(recognizerResult);
                var ticketType  = ParserLuisHelper.GetTicketType(recognizerResult);
                var payment     = ParserLuisHelper.GetPaymentMethod(recognizerResult);;
                var dates       = ParserLuisHelper.GetDates(recognizerResult);;

                var conversationStateAccessors = ConversationState.CreateProperty <ConversationData>(nameof(ConversationData));
                var conversationData           = await conversationStateAccessors.GetAsync(turnContext, () => new ConversationData());

                conversationData.OnDialog    = "OtherDialog";
                conversationData.Destination = destination;
                conversationData.Payment     = payment;
                conversationData.DateFrom    = dates.Start.ToString();
                conversationData.DateUp      = dates.End.ToString();
                conversationData.TicketType  = ticketType;

                await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>(nameof(DialogState)), cancellationToken);

                break;

            case "getGreetings":

                await turnContext.SendActivityAsync((new Grettings()).GetGreetting());

                break;

            case "getJokes":

                await turnContext.SendActivityAsync((new Jokes()).GetJokes());

                break;

            case "getInsults":

                await turnContext.SendActivityAsync((new Insults()).GetInsults());

                break;


            case "getTicketRefund":
                await turnContext.SendActivityAsync("Veo que me estas solicitando un devoluciĆ³n. En este momentos no tengo implementada esa funcionalidad.");

                break;

            case "getTicketInformation":
                await turnContext.SendActivityAsync("Veo que me estas solicitando informaciĆ³n sobre un viaje. En este momentos no tengo implementada esa funcionalidad.");

                break;

            default:
                await turnContext.SendActivityAsync("No he logrado comprender lo que me quieres decir. Intenta nuevamente.");

                break;
            }
        }