private async Task <DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var result = await _botServices.Dispatch.RecognizeAsync(stepContext.Context, cancellationToken);

            /**
             * Sample LUIS return JSON which is coming from this endpoint:
             * https://ps-luis-bot2.cognitiveservices.azure.com/luis/prediction/v3.0/apps/d70fb317-2aee-433d-85ee-caf50dab7d9c/slots/production/predict?subscription-key=31a0d29eb3d04571a5ef757819249f8d&verbose=true&show-all-intents=true&log=true&query=is%20crash%20a%20bug%20type
             * {
             *  "query": "is crash a bug type",
             *  "prediction": {
             *  "topIntent": "QueryBugTypeIntent",
             *  "intents": {
             *  "QueryBugTypeIntent": {
             *  "score": 0.92179507
             *  },
             *  "NewBugReportIntent": {
             *  "score": 0.105129756
             *  },
             *  "GreetingIntent": {
             *  "score": 0.0039601624
             *  },
             *  "None": {
             *  "score": 0.00393270655
             *  }
             *  },
             *  "entities": {
             *  "BugType": [    <--------- This is what we are concerned on the code below
             *  "crash"
             *  ],
             *  "$instance": {
             *  "BugType": [
             *  {
             *  "type": "BugType",     <--------- This is what we are concerned on the code below
             *  "text": "crash",
             *  "startIndex": 3,
             *  "length": 5,
             *  "score": 0.9869405,
             *  "modelTypeId": 1,
             *  "modelType": "Entity Extractor",
             *  "recognitionSources": [
             *  "model"
             *  ]
             *  }
             *  ]
             *  }
             *  }
             *  }
             *  }
             */
            var   token = result.Entities.FindTokens("BugType").FirstOrDefault();
            Regex rgx   = new Regex("[^a-zA-Z0-9 -]");
            var   value = token != null?rgx.Replace(token.ToString(), "").Trim() : string.Empty;


            if (Common.BugTypes.Any(s => s.Equals(value, StringComparison.OrdinalIgnoreCase)))
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text(String.Format("Yes! {0} is a Bug Type!", value)), cancellationToken);

                // Create Facebook Response
                var replyMessage = stepContext.Context.Activity;

                var facebookMessage = new FacebookSendMessage();
                facebookMessage.notification_type  = "REGULAR";
                facebookMessage.attachment         = new FacebookAttachment();
                facebookMessage.attachment.Type    = FacebookAttachmentTypes.template;
                facebookMessage.attachment.Payload = new FacebookPayload();
                facebookMessage.attachment.Payload.TemplateType = FacebookTemplateTypes.generic;
                var bugType = new FacebookElement();
                bugType.Title = value;
                switch (value.ToLower())
                {
                case "security":
                    bugType.ImageUrl = "https://c1.staticflickr.com/9/8604/16042227002_1d00e0771d_b.jpg";
                    bugType.Subtitle = "This is a description of the security bug type";
                    break;

                case "crash":
                    bugType.ImageUrl = "https://upload.wikimedia.org/wikipedia/commons/5/50/Windows_7_BSOD.png";
                    bugType.Subtitle = "This is a description of the crash bug type";
                    break;

                case "power":
                    bugType.ImageUrl = "https://www.publicdomainpictures.net/en/view-image.php?image=1828&picture=power-button";
                    bugType.Subtitle = "This is a description of the power bug type";
                    break;

                case "performance":
                    bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:High_Performance_Computing_Center_Stuttgart_HLRS_2015_07_Cray_XC40_Hazel_Hen_IO.jpg";
                    bugType.Subtitle = "This is a description of the performance bug type";
                    break;

                case "usability":
                    bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:03-Pau-DevCamp-usability-testing.jpg";
                    bugType.Subtitle = "This is a description of the usability bug type";
                    break;

                case "seriousbug":
                    bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:Computer_bug.svg";
                    bugType.Subtitle = "This is a description of the serious bug type";
                    break;

                case "other":
                    bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:Symbol_Resin_Code_7_OTHER.svg";
                    bugType.Subtitle = "This is a description of the other bug type";
                    break;

                default:
                    break;
                }
                facebookMessage.attachment.Payload.Elements = new FacebookElement[] { bugType };
                replyMessage.ChannelData = facebookMessage;
                await stepContext.Context.SendActivityAsync(replyMessage);
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text(String.Format("No {0} is not a Bug Type.", value)), cancellationToken);
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }
Example #2
0
        public async Task QueryBugTypes(IDialogContext context, LuisResult result)
        {
            foreach (var entity in result.Entities.Where(Entity => Entity.Type == "BugType"))
            {
                var value = entity.Entity.ToLower();
                if (Enum.GetNames(typeof(BugType)).Where(a => a.ToLower().Equals(value)).Count() > 0)
                {
                    var replyMessage = context.MakeMessage();
                    replyMessage.Text = "Si es un tipo de bug!";
                    var facebookMessage = new FacebookSendMessage();
                    facebookMessage.attachment         = new FacebookAttachment();
                    facebookMessage.attachment.Type    = FacebookAttachmentTypes.template;
                    facebookMessage.attachment.Payload = new FacebookPayload();
                    facebookMessage.attachment.Payload.TemplateType = FacebookTemplateTypes.generic;

                    var bugType = new FacebookElement();
                    bugType.Title = value;
                    switch (value)
                    {
                    case "seguridad":
                        bugType.ImageUrl = "https://c1.staticflickr.com/9/8604/16042227002_1d00e0771d_b.jpg";
                        bugType.Subtitle = "Contactese con el ejecutivo, Horario: L-V ; 9:00 - 18:00 hrs.";
                        break;

                    case "crash":
                        bugType.ImageUrl = "https://upload.wikimedia.org/wikipedia/commons/5/50/Windows_7_BSOD.png";
                        bugType.Subtitle = "This is a description of the crash bug type";
                        break;

                    case "power":
                        bugType.ImageUrl = "https://www.publicdomainpictures.net/pictures/10000/velka/1-1232525611kwZ7.jpg#.W3YsdlxzoSo.link";
                        bugType.Subtitle = "This is a description of the power bug type";
                        break;

                    case "rendimiento":
                        bugType.ImageUrl = "https://upload.wikimedia.org/wikipedia/commons/e/e5/High_Performance_Computing_Center_Stuttgart_HLRS_2015_07_Cray_XC40_Hazel_Hen_IO.jpg";
                        bugType.Subtitle = "This is a description of the performance bug type";
                        break;

                    case "usabilidad":
                        bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:03-Pau-DevCamp-usability-testing.jpg";
                        bugType.Subtitle = "This is a description of the usability bug type";
                        break;

                    case "errorgrave":
                        bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:Computer_bug.svg";
                        bugType.Subtitle = "This is a description of the serious bug type";
                        break;

                    case "otro":
                        bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:Symbol_Resin_Code_7_OTHER.svg";
                        bugType.Subtitle = "This is a description of the other bug type";
                        break;

                    default:
                        break;
                    }
                    facebookMessage.attachment.Payload.Elements = new FacebookElement[] { bugType };
                    replyMessage.ChannelData = facebookMessage;     //ChannelData es un Json especifico para ese canal.
                    await context.PostAsync(replyMessage);

                    context.Wait(MessageReceived);
                    return;
                }
                else
                {
                    await context.PostAsync("Disculpa pero ese no es un tipo de bug.");

                    context.Wait(MessageReceived);
                    return;
                }
            }
            await context.PostAsync("Disculpa pero ese no es un tipo de bug.");

            context.Wait(MessageReceived);
            return;
        }
        private static Activity ReplyFacebookMessage(Activity activity, string entityName)
        {
            var facebookMessage = new FacebookSendMessage
            {
                attachment = new FacebookAttachment()
                {
                    Type = FacebookAttachmentTypes.template, Payload = new FacebookPayload()
                    {
                        TemplateType = FacebookTemplateTypes.generic
                    }
                }
            };
            var bugType = new FacebookElement()
            {
                Title = entityName
            };

            switch (entityName.ToLower())
            {
            case "security":
                bugType.ImageUrl = "https://c1.staticflickr.com/9/8604/16042227002_1d00e0771d_b.jpg";
                bugType.Subtitle = "This is a description of the security bug type";
                break;

            case "crash":
                bugType.ImageUrl = "https://upload.wikimedia.org/wikipedia/commons/5/50/Windows_7_BSOD.png";
                bugType.Subtitle = "This is a description of the crash bug type";
                break;

            case "power":
                bugType.ImageUrl = "https://www.publicdomainpictures.net/en/view-image.php?image=1828&picture=power-button";
                bugType.Subtitle = "This is a description of the power bug type";
                break;

            case "performance":
                bugType.ImageUrl =
                    "https://commons.wikimedia.org/wiki/File:High_Performance_Computing_Center_Stuttgart_HLRS_2015_07_Cray_XC40_Hazel_Hen_IO.jpg";
                bugType.Subtitle = "This is a description of the performance bug type";
                break;

            case "usability":
                bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:03-Pau-DevCamp-usability-testing.jpg";
                bugType.Subtitle = "This is a description of the usability bug type";
                break;

            case "seriousbug":
                bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:Computer_bug.svg";
                bugType.Subtitle = "This is a description of the serious bug type";
                break;

            case "other":
                bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:Symbol_Resin_Code_7_OTHER.svg";
                bugType.Subtitle = "This is a description of the other bug type";
                break;

            default:
                break;
            }

            facebookMessage.attachment.Payload.Elements = new FacebookElement[] { bugType };
            activity.ChannelData = facebookMessage;
            return(activity);
        }
Example #4
0
        public async Task QueryBugTypes(IDialogContext context, LuisResult result)
        {
            foreach (var entity in result.Entities.Where(Entity => Entity.Type == "BugType"))
            {
                var value = entity.Entity.ToLower();
                if (Enum.GetNames(typeof(BugType)).Where(a => a.ToLower().Equals(value)).Count() > 0)
                {
                    var replyMessage = context.MakeMessage();
                    replyMessage.Text = "Yes that is a bug type!";
                    var facebookMessage = new FacebookSendMessage();
                    facebookMessage.attachment         = new FacebookAttachment();
                    facebookMessage.attachment.Type    = FacebookAttachmentTypes.template;
                    facebookMessage.attachment.Payload = new FacebookPayload();
                    facebookMessage.attachment.Payload.TemplateType = FacebookTemplateTypes.generic;

                    var bugType = new FacebookElement();
                    bugType.Title = value;
                    switch (value)
                    {
                    case "security":
                        bugType.ImageUrl = "https://c1.staticflickr.com/9/8604/16042227002_1d00e0771d_b.jpg";
                        bugType.Subtitle = "This is a description of the security bug type";
                        break;

                    case "crash":
                        bugType.ImageUrl = "https://upload.wikimedia.org/wikipedia/commons/5/50/Windows_7_BSOD.png";
                        bugType.Subtitle = "This is a description of the crash bug type";
                        break;

                    case "power":
                        bugType.ImageUrl = "https://www.publicdomainpictures.net/en/view-image.php?image=1828&picture=power-button";
                        bugType.Subtitle = "This is a description of the power bug type";
                        break;

                    case "performance":
                        bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:High_Performance_Computing_Center_Stuttgart_HLRS_2015_07_Cray_XC40_Hazel_Hen_IO.jpg";
                        bugType.Subtitle = "This is a description of the performance bug type";
                        break;

                    case "usability":
                        bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:03-Pau-DevCamp-usability-testing.jpg";
                        bugType.Subtitle = "This is a description of the usability bug type";
                        break;

                    case "seriousbug":
                        bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:Computer_bug.svg";
                        bugType.Subtitle = "This is a description of the serious bug type";
                        break;

                    case "other":
                        bugType.ImageUrl = "https://commons.wikimedia.org/wiki/File:Symbol_Resin_Code_7_OTHER.svg";
                        bugType.Subtitle = "This is a description of the other bug type";
                        break;

                    default:
                        break;
                    }
                    facebookMessage.attachment.Payload.Elements = new FacebookElement[] { bugType };
                    replyMessage.ChannelData = facebookMessage;
                    await context.PostAsync(replyMessage);

                    context.Wait(MessageReceived);
                    return;
                }
                else
                {
                    await context.PostAsync("I'm sorry that is not a bug type.");

                    context.Wait(MessageReceived);
                    return;
                }
            }
            await context.PostAsync("I'm sorry that is not a bug type.");

            context.Wait(MessageReceived);
            return;
        }