Exemplo n.º 1
0
        public async Task CreateMeme(IDialogContext context, LuisResult result)
        {
            int             memetype = 0;
            MemeCreateOrder order    = new MemeCreateOrder();

            memetype = await ExtractMemeTypeReccomendationFromResult(result);

            memetext = await Task.Run(() => ExtractMemeTextReccomendationFromResult(result));

            // got a memetype back from the reccomender? fill it in
            if (memetype != 0)
            {
                order.memeOptions = (PopularMemeTypes)memetype;
            }
            // got text back from the reccomendation engine? fill that in too
            if ((memetext.TopText != string.Empty) || (memetext.BottomText != string.Empty))
            {
                // check if the meme text entity reccomendations came back with anything.  If the user used pre-filling syntaxt intents
                // then we should just pass those in to the order
                order.toptext    = (memetext.TopText == String.Empty) ? null : memetext.TopText;
                order.bottomtext = (memetext.BottomText == String.Empty) ? null : memetext.BottomText;
            }

            // if at this point we have enough information to create the meme without prompts, we bypass
            // the interactive conversation and just go
            if (order.HasEnoughInformationToCreateMeme)
            {
                Activity reply = context.MakeMessage() as Activity;
                await CaptionService.GenerateResultForMemeCreate(memetype, memetext.TopText, memetext.BottomText, reply);

                await context.PostAsync(reply);

                context.Wait(MessageReceived);
            }
            // otherwise, spin the converation from where we are (starting from whatever point we're at)
            else
            {
                IFormDialog <MemeCreateOrder> createOrderDialog = MakeMemeCreateInteractiveDialog(order);
                context.Call(createOrderDialog, FinalizeMemeCreation);
            }
        }
Exemplo n.º 2
0
        private async Task FinalizeMemeCreation(IDialogContext context, IAwaitable <MemeCreateOrder> result)
        {
            MemeCreateOrder order;

            try
            {
                order = await result;
            }
            catch (OperationCanceledException)
            {
                await context.PostAsync("We'll try again some other time");

                return;
            }
            Activity reply = context.MakeMessage() as Activity;
            await CaptionService.GenerateResultForMemeCreate(order, reply);

            await context.PostAsync(reply);

            context.Wait(MessageReceived);
        }