public async Task OnTurn(ITurnContext context)
        {
            Dictionary <string, object> state = ConversationState <Dictionary <string, object> > .Get(context);

            DialogContext dc = dialogos.CreateContext(context, state);
            await dc.Continue();

            if (context.Activity.Type == ActivityTypes.Message)
            {
                RecognizerResult resultado = context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);

                var intencaoMaisPontuada = resultado?.GetTopScoringIntent();
                if (!context.Responded)
                {
                    IDictionary <string, object> argumentos = new Dictionary <string, object>();

                    if (this.ObterEntidade <string>(resultado, "Cidade") != null)
                    {
                        argumentos.Add("Cidade", this.ObterEntidade <string>(resultado, "Cidade"));
                    }

                    if (this.ObterEntidade <string>(resultado, "Tamanho") != null)
                    {
                        argumentos.Add("Tamanho", this.ObterEntidade <string>(resultado, "Tamanho"));
                    }

                    if (this.ObterEntidade <string>(resultado, "Sabor") != null)
                    {
                        argumentos.Add("Sabor", this.ObterEntidade <string>(resultado, "Sabor"));
                    }

                    switch ((intencaoMaisPontuada != null) ? intencaoMaisPontuada.Value.intent : null)
                    {
                    case "None":
                        await context.SendActivity("Não entendi.");

                        break;

                    case "PedirPizza":
                        await dc.Begin("pedirPizza", argumentos);

                        break;

                    case "PrevisaoTempo":
                        await dc.Begin("previsaoTempo", argumentos);

                        break;

                    case "MarcarConsulta":
                        await dc.Begin("marcarConsulta");

                        break;
                    }
                }
            }
        }
        private async Task NoneBegin(DialogContext dialogContext, IDictionary <string, object> args, SkipStepFunction next)
        {
            await dialogContext.Context.SendActivity(new Activity
            {
                Type = ActivityTypes.Typing
            });

            Thread.Sleep(4000);

            EntitiesParse entities = (EntitiesParse)args["entities"];

            if (entities.Ingredients.Count > 0 || entities.Drinks.Count > 0 || entities.ProductTypes.Count > 0)
            {
                await dialogContext.Context.SendActivity($"Me desculpe { dialogContext.Context.Activity.From.Name}, mas não consegui entender o que você gostaria {Emojis.SmileSad}" +
                                                         $"  \nMas baseado em informações encontradas na sua mensagem lhe recomendo os seguintes produtos {Emojis.SmileHappy}");
            }
            else
            {
                await dialogContext.Context.SendActivity($"Me desculpe { dialogContext.Context.Activity.From.Name}, mas não consegui entender o que você gostaria {Emojis.SmileSad}" +
                                                         $"  \nMas estou enviando algumas pizzas para você ver {Emojis.SmileHappy}");
            }
            await dialogContext.Context.SendActivity(new Activity
            {
                Type = ActivityTypes.Typing
            });

            Thread.Sleep(4000);
            await dialogContext.Begin(AskProduct.Ask_Product_Waterfall_Text, args);
        }
Exemple #3
0
        private static async Task TravelStepLaunchSearch(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next)
        {
            if (args != null)
            {
                await ManageIntentsInMessageAsync(dc, async (ctx, intent, _) =>
                {
                    var state = ctx.GetUserState <UserTravelState>();

                    switch (intent)
                    {
                    case "Affirmative":
                        await dc.Begin("Search");
                        break;

                    case "Negative":
                        if (state.GoodHealth)
                        {
                            await dc.Context.SendActivity("Merci d'avoir utiliser JASPER, passez une bonne journé !");
                        }
                        else
                        {
                            await dc.Context.SendActivity("Merci d'avoir utiliser JASPER, rétablissez-vous bien.");
                        }

                        dc.EndAll();
                        break;
                    }
                });
            }
        }
Exemple #4
0
        private async void ReservationHandler(DialogContext dialogContext, string amountPeople, string time)
        {
            var state = dialogContext.Context.GetConversationState <ReservationData>();

            state.AmountPeople = amountPeople;
            state.Time         = time;
            await dialogContext.Begin(PromptStep.GatherInfo);
        }
        private async Task ShowCardStep(DialogContext dialogContext, object result, SkipStepFunction next)
        {
            var selectedCard = (result as Microsoft.Bot.Builder.Prompts.ChoiceResult).Value.Value;
            var activity     = dialogContext.Context.Activity;

            switch (selectedCard)
            {
            case REPORT_ACCIDENT_CARD_ID:
                await dialogContext.Begin(PromptStep.GatherInfo);

                break;

            case "session":
                await dialogContext.Begin("session");

                break;
            }
        }
Exemple #6
0
        public async Task <bool> TryConsumeAsync(DialogContext dialogContext, string utterance)
        {
            if (utterance.Contains("logout"))
            {
                await dialogContext.Begin(LogoutPrompt);

                return(true);
            }

            return(false);
        }
Exemple #7
0
        private static async Task ResultsStepAction(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next)
        {
            if (args != null)
            {
                await ManageIntentsInMessageAsync(dc, async (ctx, intent, _) =>
                {
                    var state     = dc.Context.GetUserState <UserTravelState>();
                    var isBooking = state.CurrentTravelId.HasValue;

                    switch (intent)
                    {
                    case "Affirmative":
                        if (isBooking)
                        {
                            await ctx.SendActivity("Je m'en occupe tout de suite, vous recevrez les informations par mail");
                            await Task.Delay(1000);
                            await dc.Begin("LoadBag");
                        }
                        else
                        {
                            await dc.Begin("Search");
                        }

                        break;

                    case "Negative":
                        if (state.GoodHealth)
                        {
                            await dc.Context.SendActivity("Merci d'avoir utiliser JASPER, passez une bonne journé !");
                        }
                        else
                        {
                            await dc.Context.SendActivity("Merci d'avoir utiliser JASPER, rétablissez-vous bien.");
                        }

                        dc.EndAll();
                        break;
                    }
                });
            }
        }
Exemple #8
0
        public async Task OnTurn(ITurnContext context)
        {
            Dictionary <string, object> state = ConversationState <Dictionary <string, object> > .Get(context);

            DialogContext dc = dialogos.CreateContext(context, state);
            await dc.Continue();

            if (context.Activity.Type == ActivityTypes.Message)
            {
                if (!context.Responded)
                {
                    await dc.Begin("PedirPizaa");
                }
            }
        }
Exemple #9
0
        public async Task OnTurn(ITurnContext turnContext)
        {
            try
            {
                Dictionary <string, object> state = null;
                DialogContext dc = null;
                switch (turnContext.Activity.Type)
                {
                case ActivityTypes.Message:
                    if (turnContext.Activity.Text == "signout")
                    {
                        var botframeworkAdapter = turnContext.Adapter as BotFrameworkAdapter;
                        await botframeworkAdapter.SignOutUser(turnContext, _connectionSettingName);

                        await turnContext.SendActivity("You are now signed out.");
                    }
                    else
                    {
                        state = ConversationState <Dictionary <string, object> > .Get(turnContext);

                        dc = _dialogs.CreateContext(turnContext, state);
                        await dc.Continue();

                        // Check to see if anyone replied. If not then start dialog
                        if (!turnContext.Responded)
                        {
                            await dc.Begin("displayToken");
                        }
                    }
                    break;

                case ActivityTypes.Event:
                case ActivityTypes.Invoke:
                    // Create dialog context and continue executing the "current" dialog, if any.
                    // This is important for OAuthCards because tokens can be received via TokenResponse events
                    state = ConversationState <Dictionary <string, object> > .Get(turnContext);

                    dc = _dialogs.CreateContext(turnContext, state);
                    await dc.Continue();

                    break;
                }
            }
            catch (Exception e)
            {
                await turnContext.SendActivity($"Exception: {e.Message}");
            }
        }
Exemple #10
0
        private static async Task SearchStepLaunchResults(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next)
        {
            if (args != null)
            {
                var state = dc.Context.GetUserState <UserTravelState>();

                await ManageIntentsInMessageAsync(dc, async (ctx, intent, result) =>
                {
                    switch (intent)
                    {
                    case "Activities":
                        JToken[] data    = GetEntities <JToken>(result, "Activities");
                        state.Activities = data.Select(x => x.First.Value <string>()).ToList();
                        break;

                    case "NoActivities":
                        state.Activities = new List <string>();
                        break;
                    }

                    await dc.Begin("Results");
                });
            }
        }
Exemple #11
0
        public async Task OnTurn(ITurnContext context)
        {
            //TODO: is this the right way to handle cards?
            string  utterance = context.Activity.Text;
            JObject cardData  = (JObject)context.Activity.Value;

            if (cardData != null && cardData.Property("intent") != null)
            {
                utterance = cardData["utterance"].ToString();
            }
            System.Threading.CancellationToken ct;

            CafeBotUserState userState         = context.GetUserState <CafeBotUserState>();
            CafeBotConvState conversationState = context.GetConversationState <CafeBotConvState>();

            switch (context.Activity.Type)
            {
            case ActivityTypes.ConversationUpdate:
                var newUserName = context.Activity.MembersAdded[0].Name;
                if (!string.IsNullOrWhiteSpace(newUserName) && newUserName != "Bot")
                {
                    await context.SendActivity($"Hello {newUserName}! I'm the Cafe bot!");

                    // remember the user's name
                    userState.name = newUserName;

                    userState.sendCards = true;

                    await context.SendActivity("I can help you find contoso cafe locations, book a table and answer questions about Contoso cafe!");

                    // send a welcome card
                    if (userState.sendCards)
                    {
                        await context.SendActivity(CreateCardResponse(context.Activity, createWelcomeCardAttachment()));
                    }
                }
                break;

            case ActivityTypes.Message:
                // create dialogContext
                DialogContext dc = _dialogs.CreateContext(context, conversationState);


                if (utterance == "start over")
                {
                    //restart the conversation
                    await context.SendActivity("Sure.. Let's start over");

                    dc.EndAll();
                }
                else
                {
                    // continue with any active dialogs
                    await dc.Continue();
                }

                if (!context.Responded)
                {
                    // call LUIS and get results
                    LuisRecognizer lRecognizer = createLUISRecognizer();
                    cafeLUISModel  lResult     = await lRecognizer.Recognize <cafeLUISModel>(utterance, ct);

                    Dictionary <string, object> lD = new Dictionary <string, object>();
                    if (lResult != null)
                    {
                        lD.Add("luisResult", lResult);
                    }

                    // top level dispatch
                    switch (lResult.TopIntent().intent)
                    {
                    case cafeLUISModel.Intent.Greeting:
                        await context.SendActivity("Hello, I'm the contoso cafe bot. How can I help you?");

                        if (userState.sendCards)
                        {
                            await context.SendActivity(CreateCardResponse(context.Activity, createWelcomeCardAttachment()));
                        }
                        break;

                    case cafeLUISModel.Intent.Book_Table:
                        await dc.Begin("BookTable", lD);

                        break;

                    case cafeLUISModel.Intent.Who_are_you_intent:
                        await dc.Begin("WhoAreYou");

                        break;

                    case cafeLUISModel.Intent.None:
                    default:
                        await getQnAResult(context);

                        break;
                    }
                }
                break;
            }
        }
        private static async Task Waterfall3_Step2(DialogContext dc, object args, SkipStepFunction next)
        {
            await dc.Context.SendActivity("step2");

            await dc.Begin("test-waterfall-c");
        }
Exemple #13
0
        public async Task OnTurn(ITurnContext context)
        {
            //TODO: is this the right way to handle cards?
            string  utterance = context.Activity.Text;
            JObject cardData  = (JObject)context.Activity.Value;

            if (cardData != null && cardData.Property("intent") != null)
            {
                utterance = cardData["utterance"].ToString();
            }

            var userState         = context.GetUserState <CafeBotUserState>();
            var conversationState = context.GetConversationState <CafeBotConvState>();

            switch (context.Activity.Type)
            {
            case ActivityTypes.ConversationUpdate:
                var newUserName = context.Activity.MembersAdded[0].Name;
                if (!string.IsNullOrWhiteSpace(newUserName) && newUserName != "Bot")
                {
                    await context.SendActivity($"Hello {newUserName}! I'm the Cafe bot!");

                    // remember the user's name
                    userState.name = newUserName;

                    userState.sendCards = true;

                    await context.SendActivity("I can help you find contoso cafe locations, book a table and answer questions about Contoso cafe!");

                    // send a welcome card
                    if (userState.sendCards)
                    {
                        await context.SendActivity(CreateCardResponse(context.Activity, createWelcomeCardAttachment()));
                    }
                }
                break;

            case ActivityTypes.Message:

                // create dialogContext
                DialogContext dc = _dialogs.CreateContext(context, conversationState);

                if (utterance == "start over")
                {
                    //restart the conversation
                    await context.SendActivity("Sure.. Let's start over");

                    dc.EndAll();
                }
                else
                {
                    // continue with any active dialogs
                    await dc.Continue();
                }
                if (!context.Responded)
                {
                    // top level dispatch
                    switch (utterance)
                    {
                    case "hi":
                        await context.SendActivity("Hello, I'm the contoso cafe bot. How can I help you?");

                        if (userState.sendCards)
                        {
                            await context.SendActivity(CreateCardResponse(context.Activity, createWelcomeCardAttachment()));
                        }
                        break;

                    case "book table":
                        // await context.SendActivity("I'm still learning to book a table!");
                        // start waterfall dialog for table booking
                        await dc.Begin("BookTable");

                        break;

                    case "who are you?":
                        // await context.SendActivity("I'm the cafe bot!");
                        // start waterfall dialog for who are you?
                        await dc.Begin("WhoAreYou");

                        break;

                    default:
                        await getQnAResult(context);

                        break;
                    }
                }
                break;
            }
        }
Exemple #14
0
        public async Task OnTurn(ITurnContext turnContext)
        {
            /*if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate && turnContext.Activity.MembersAdded.FirstOrDefault()?.Id == turnContext.Activity.Recipient.Id)
             * {
             *  await turnContext.SendActivity($"Seja bem vindo a Pergher pizzaria {Emojis.SmileHappy}");
             *
             *  await turnContext.SendActivity(new Activity
             *  {
             *      Type = ActivityTypes.Typing
             *  });
             *
             *  await turnContext.SendActivity($"Eu sou o Jorge o bot da Pergher pizzaria e estou aqui para auxiliá-lo no seu pedido {Emojis.SmileHappy} \n" +
             *      "Atualmente eu posso realizar as seguintes tarefas: \n" +
             *      "*-Ofereço bebidas e pizzas cutomizadas na sua solicitação* \n" +
             *      "*-Mostro como seu carrinho está no momento* \n" +
             *      "*-Limpo seu carrinho quando solicitado* \n" +
             *      "*-Finalizo seu carrinho quando solicitado* \n" +
             *      "*-Edito e removo itens seu carrinho quando solicitado* \n" +
             *      "*-Edito seu endreço de entrega atual quando solicitado* \n" +
             *      "*-Busco seus pedidos abertos para saber o seu estado* \n");
             *
             *  await turnContext.SendActivity($"Quando tiver alguma dúvida simplesmente escreva *AJUDA* e lhe redirecionarei para exemplos de uso {Emojis.SmileHappy}\n" +
             *      $"Caso queira sair de uma conversa que esteja no momento, simplesmente digite *SAIR* e voltaremos ao fluxo normal da conversa {Emojis.SmileHappy}\n" +
             *      $"Em que lhe posso ser útil no momento?");
             *
             * }*/

            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                var           dialogState   = turnContext.GetConversationState <Dictionary <string, object> >();
                DialogContext dialogContext = DialogFlow.CreateContext(turnContext, dialogState);

                if (turnContext.Activity.Text.ToLower() == "sair")
                {
                    dialogContext.EndAll();
                }
                else if (turnContext.Activity.Text.ToLower() == "ajuda")
                {
                    //IActivity activity = MessageFactory.SuggestedActions(new CardAction[]
                    //    {
                    //        new CardAction
                    //        {
                    //            Title = "Abrir documentação",
                    //            Type = ActionTypes.OpenUrl,
                    //            Value = "https://pizzeria-bot-tc.readthedocs.io/pt/latest/index.html"
                    //        }
                    //    });

                    IActivity activity = MessageFactory.Attachment(new HeroCard
                    {
                        Buttons = new List <CardAction>
                        {
                            new CardAction
                            {
                                Title = "Abrir manual",
                                Type  = ActionTypes.OpenUrl,
                                Value = "https://pizzeria-bot-tc.readthedocs.io/pt/latest/index.html"
                            }
                        }
                    }.ToAttachment());

                    await dialogContext.Context.SendActivity($"Clique no botão abaixo para abrir o manual {Emojis.SmileHappy} ");

                    await dialogContext.Context.SendActivity(activity);
                }
                else
                {
                    await dialogContext.Continue();

                    BotUserState userState = UserState <BotUserState> .Get(dialogContext.Context);

                    if (!turnContext.Responded)
                    {
                        RecognizerResult luisResult   = turnContext.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);
                        string           intentResult = LuisResult.GetLuisIntent(luisResult, userState);

                        IDictionary <string, object> args = new Dictionary <string, object>
                        {
                            { "entities", EntitiesParse.RecognizeEntities(luisResult.Entities) }
                        };

                        await dialogContext.Begin(intentResult, args);
                    }
                }
            }
            else if (turnContext.Activity.Type != ActivityTypes.ConversationUpdate)
            {
                await turnContext.SendActivity($"Olá, ainda não estou preparado para tratar este tipo de informacão {Emojis.SmileSad}  \n" +
                                               $"Peço que utilize apenas texto para melhorar nossa interação {Emojis.SmileHappy}");
            }
        }