Example #1
0
        public async Task OnTurn(ITurnContext context)
        {
            switch (context.Activity.Type)
            {
            case ActivityTypes.Message:
                string utterance = context.Activity.Text;

                var(userState, dialogCtx) = CreateContext(context);

                await dialogCtx.Continue();

                if (context.Responded)
                {
                    return;
                }

                var result = await luisService.GetResultAsync(utterance);

                var topIntent = result != null?result.TopIntent().intent : eShopLuisResult.Intent.None;

                switch (topIntent)
                {
                case eShopLuisResult.Intent.Catalog:
                    if (result.Entities.brand != null || result.Entities.type != null)
                    {
                        userState.CatalogFilter = ConvertToConvesationInfo(result);
                        await dialogCtx.Begin(CatalogDialog.Id);
                    }
                    else
                    {
                        await dialogCtx.Begin(CatalogFilterDialog.Id);
                    }
                    break;

                case eShopLuisResult.Intent.Login:
                    await context.SendActivity("No Login yet, sorry. Come back later");

                    break;

                case eShopLuisResult.Intent.Hello:
                    await context.SendActivity("Hi. How can I help you?");

                    break;

                case eShopLuisResult.Intent.Bye:
                    await context.SendActivity("Bye bye, remember I am here to help you when ever you need me.");

                    break;

                default:
                    await context.SendActivity($"Sorry, I did not understand '{utterance}'. Type '/help' if you need assistance.");

                    break;
                }
                break;

            default:
                await HandleSystemMessage(context);

                break;
            }
        }