コード例 #1
0
        private async Task ProcessBrandChoice(IDialogContext context, IAwaitable <object> awaitable)
        {
            Activity reply, ans = (Activity)(await awaitable);
            string   brand = ans.Text;


            if ((brand.Length > 7) && (brand.StartsWith("I want ")))
            {
                brand = brand.Substring(7).ToLower();
            }
            if (handSetsBag.IsBrandUnavailable(brand))
            {
                reply = ans.CreateReply("I'm sorry, unfortunately we do not have that brand available, would it be possible to pick another one?");
                Miscellany.ComposeBrandsCarousel(reply, handSetsBag.GetAllBrands().Keys, handSetsBag);
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync(reply);
            }
            else if (!handSetsBag.GetAllBrands().Keys.Contains(brand))
            {
                reply = ans.CreateReply("I'm sorry, unfortunately I don't know that brand, would it be possible to pick another one?");
                Miscellany.ComposeBrandsCarousel(reply, handSetsBag.GetAllBrands().Keys, handSetsBag);
                await Miscellany.InsertDelayAsync(context);

                await context.PostAsync(reply);
            }
            else
            {
                decoder.StrKeyWords = new List <string> {
                    brand.ToLower()
                };
                context.Wait(MessageReceived);
                await DecodeAndProcessIntentAsync(context);
            }
        }
コード例 #2
0
        private async Task AskBrandAndModelAsync(IDialogContext context)
        {
            StringBuilder builder        = new StringBuilder();
            var           reply          = ((Activity)context.Activity).CreateReply();
            int           numberOfModels = availableModelsCount;

            try
            {
                brands = GetAllBrands();

                reply.Text = $"You can choose from {numberOfModels} models from Apple, Samsung, Nokia and other leading brands. Click or type the brands below from this list";
                if (debugMessages)
                {
                    await context.PostAsync("DEBUG : Calling ComposeBrandsCarousel()");
                }
                Miscellany.ComposeBrandsCarousel(reply, brands.Keys, handSets);
                // ComposeBrandsCarousel(reply);
            }
            catch (Exception xception)
            {
                await context.PostAsync("xception message = " + xception.Message);
            }
            await Miscellany.InsertDelayAsync(context);

            await context.PostAsync(reply);

            context.Wait(BrandChoiceMadeAskModelAsync);
        }
コード例 #3
0
        public async Task ProcessLuisNeedsResult(IDialogContext context, IAwaitable <object> awaitable)
        {
            Tuple <NodeLuisSubsNeeds.ENeeds, double> result = (Tuple <NodeLuisSubsNeeds.ENeeds, double>) await awaitable;
            StringBuilder sb         = new StringBuilder();
            double        needsScore = result.Item2;

            NodeLuisSubsNeeds.ENeeds needsIntent = result.Item1;
            int handSetsLeft, handSetsNow = decoder.CurrentNumberofHandsetsLeft();

            if (CommonDialog.debugMessages)
            {
                await context.PostAsync("DEBUG : Beginning of the method ProcessLuisNeedResult()");
            }
            if (needsScore > desiredFeatureScore)  // WE have a need
            {
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("DEBUG : It's a need, namely " + needsIntent.ToString());
                }
                context.ConversationData.SetValue <NodeLuisSubsNeeds.ENeeds>(BotConstants.LAST_NEED_KEY, needsIntent);
                decoder.LastOneWasNeed    = true;
                decoder.FeatureOrNeedDesc = NodeLuisSubsNeeds.GetNeedIntentDesc(result.Item1);
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("DEBUG : I'm going to obtain the top");
                }
                handSetsLeft = needsScores.GetTopFive(needsIntent);
                if (CommonDialog.debugMessages)
                {
                    await context.PostAsync("DEBUG : I've already obtained the top 5");
                }
                await UpdateUserAsync(context, handSetsLeft, handSetsNow);
            }
            else
            {
                try
                {
                    if (desiredFeature == EIntents.None)
                    {
                        await context.PostAsync("I'm sorry, I'm afraid I didn't understand that, could you please rephrase?");

                        return;
                    }
                    if (CommonDialog.debugMessages)
                    {
                        await context.PostAsync("DEBUG : I'm goin to set frequency");
                    }
                    topButtons.SetNewFreq(desiredFeature, sb);
                    if (CommonDialog.debugMessages)
                    {
                        await context.PostAsync("DEBUG : New Frequency set, getting into the switch to switch to correct one (no pun intented)");
                    }
                    context.ConversationData.SetValue(BotConstants.LAST_FEATURE_KEY, desiredFeature);
                    switch (desiredFeature)
                    {
                    case EIntents.Small:
                        if (!ExtractPhoneSizeInfo(res))
                        {
                            PromptDialog.Choice(context, ProcessSizeChoice, new List <string>()
                            {
                                "BIGGER", "SMALLER", "THE SAME"
                            }, "Are you looking for a phone with a similar size as your existing model or something bigger or smaller?", "Not understood, please try again", 3);
                        }
                        break;

                    case EIntents.Camera:
                        if (!GetCameraCompositeEntityData(res))      // The desired megapixels aren't present, so in this particular case we'll send it to fuzzy engine
                        {
                            if (CommonDialog.debugMessages)
                            {
                                await context.PostAsync("DEBUG : Camera intent : No data detected");
                            }
                            decoder.ExcludeThis(EIntents.Camera);
                            decoder.SetSizeRequirements(-1, true);
                            handSetsLeft = needsScores.GetTopFive(NodeLuisSubsNeeds.ENeeds.Camera);
                            await UpdateUserAsync(context, handSetsLeft, handSetsNow);
                        }
                        else
                        {
                            if (CommonDialog.debugMessages)
                            {
                                await context.PostAsync("DEBUG : Camera intent : Data detected");
                            }
                            await DecodeAndProcessIntentAsync(context);
                        }
                        break;

                    case EIntents.OS:
                        if (!GetOSData(res))
                        {
                            if (CommonDialog.debugMessages)
                            {
                                await context.PostAsync("Handling OS intent");
                            }
                            PromptDialog.Choice(context, ProcessEnumeratedChoice, handSetsBag.GetBagOSes(), "Could you please indicate your favourite Operating System?", "Not understood, please try again", 3);
                        }
                        else
                        {
                            await DecodeAndProcessIntentAsync(context);
                        }
                        break;

                    case EIntents.Color:
                        if (!GetPreferredColors(res))
                        {
                            PromptDialog.Choice(context, ProcessEnumeratedChoice, handSetsBag.GetBagColors(), "Could you please indicate your favourite Color?", "Not understood, please try again", 3);
                        }
                        else
                        {
                            await DecodeAndProcessIntentAsync(context);
                        }
                        break;

                    case EIntents.Brand:
                        if (!GetSpecificBrands(res))
                        {
                            List <string> brands = handSetsBag.GetBagBrands();
                            Activity      reply  = (Activity)context.MakeMessage();

                            reply.Text = "Could you please indicate your favourite brand?";
                            await Miscellany.InsertDelayAsync(context);

                            Miscellany.ComposeBrandsCarousel(reply, brands, handSetsBag);
                            await context.PostAsync(reply);

                            context.Wait(ProcessBrandChoice);
                        }
                        else
                        {
                            await DecodeAndProcessIntentAsync(context);
                        }
                        break;

                    default:
                        await DecodeAndProcessIntentAsync(context);

                        break;
                    }
                }
                catch (ArgumentException)
                {
                    await context.PostAsync("Argument xception");
                }
                catch (Exception xception)
                {
                    await context.PostAsync($"Error...Exception Message = {xception.Message}");
                }
            }
        }