Exemple #1
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 #2
0
 private static async Task TravelStepGreeting(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next)
 {
     await ManageIntentsInMessageAsync(dc, async (ctx, intent, _) =>
     {
         if (intent == "Start" || intent == "Greetings")
         {
             await dc.Prompt("HealthPrompt", "Comment allez-vous aujourd'hui ?");
         }
         else
         {
             await ctx.SendActivity("Vous n'êtes pas très poli !");
             dc.EndAll();
         }
     });
 }
Exemple #3
0
        private static async Task ManageIntentsInMessageAsync(DialogContext dc, Func <ITurnContext, string, RecognizerResult, Task> onRecognizedIntent = null, Func <ITurnContext, Task> onUnrecognizedIntent = null)
        {
            var result    = dc.Context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);
            var topIntent = result?.GetTopScoringIntent();

            if ((topIntent?.score ?? 0) < 0.3)
            {
                await dc.Context.SendActivity("Je ne suis pas sûr d'avoir compris ce que vous avez dit...");

                if (onUnrecognizedIntent != null)
                {
                    await onUnrecognizedIntent(dc.Context);
                }
                else
                {
                    await dc.End();
                }
            }
            else
            {
                switch (topIntent?.intent)
                {
                case "Cancel":
                case "Exit":
                    await dc.Context.SendActivity("Merci d'avoir utilisé JASPER !");

                    dc.EndAll();
                    break;

                default:
                    if (onRecognizedIntent == null)
                    {
                        await dc.Context.SendActivity($"Intent: {topIntent?.intent} ({topIntent?.score}).");
                    }
                    else
                    {
                        await onRecognizedIntent(dc.Context, topIntent?.intent, result);
                    }

                    break;
                }
            }
        }
Exemple #4
0
        private static async Task LoadBagStepEnd(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next)
        {
            if (args != null)
            {
                var result = await BrainConnector.LoadBagAsync();

                if (result.status == 200)
                {
                    await dc.Context.TraceActivity($"Payload from BRAIN : {result.payload}");

                    await dc.Context.SendActivity("BRAIN charge votre valise, merci de patienter quelques instants.");

                    await BrainConnector.WaitUntilBagLoadedAsync();

                    await dc.Context.SendActivity("BRAIN indique que votre valide est chargée. Bon voyage !");

                    dc.EndAll();
                }
            }
        }
Exemple #5
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 #6
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;
            }
        }
Exemple #7
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 #8
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}");
            }
        }