public FacebookMessage GetTemplate()
        {
            var facebookElements = new List <FacebookElement>();

            foreach (var product in _products)
            {
                var facebookElement = new FacebookElement()
                {
                    Title     = product.Description,
                    Image_url = $"C:/Users/f.marcia/source/repos/LuisBot/LuisBot/Images/image.jpeg",
                    Buttons   = new FacebookButton[]
                    {
                        new FacebookButton()
                        {
                            Title   = CardMessagesResource.ListCardButtonTitle,
                            Type    = "postback",
                            Payload = JsonConvert.SerializeObject(new ProductSelectionPayload()
                            {
                                Action = "add", Product = product
                            })
                        }
                    }
                };

                facebookElements.Add(facebookElement);
            }

            var facebookMessage = new FacebookMessage()
            {
                Attachment = new FacebookAttachment()
                {
                    Type    = "template",
                    Payload = new FacebookPayload()
                    {
                        Template_type   = "list",
                        TopElementStyle = "compact",
                        Elements        = facebookElements.ToArray(),
                        Buttons         = new FacebookButton[]
                        {
                            new FacebookButton()
                            {
                                Title   = CardMessagesResource.ListCardFinalButtonTitle,
                                Type    = "postback",
                                Payload = JsonConvert.SerializeObject(new ProductSelectionPayload()
                                {
                                    Action = "cancel"
                                })
                            }
                        }
                    }
                }
            };

            return(facebookMessage);
        }
Esempio n. 2
0
        public async Task QueryAmenities(IDialogContext context, LuisResult result)
        {
            foreach (var entity in result.Entities.Where(e => e.Type == "Amenity"))
            {
                var value = entity.Entity.ToLower();
                if (value == "pool" || value == "gym" || value == "wifi" || value == "towels")
                {
                    Activity replyMessage    = _message.CreateReply();
                    var      facebookMessage = new FacebookMessage();
                    facebookMessage.notification_type  = "NO_PUSH";
                    facebookMessage.attachment         = new FacebookAttachment();
                    facebookMessage.attachment.type    = "template";
                    facebookMessage.attachment.payload = new FacebookPayload();
                    facebookMessage.attachment.payload.template_type = "generic";

                    var amenitiy = new FacebookElement();
                    amenitiy.subtitle = "Yes we have that!";
                    amenitiy.title    = value;

                    switch (value)
                    {
                    case "pool":
                        amenitiy.image_url = "http://www.girltweetsworld.com/wp-content/uploads/2012/02/P1000180.jpg";
                        break;

                    case "gym":
                        amenitiy.image_url = "https://s-media-cache-ak0.pinimg.com/originals/cb/c9/4a/cbc94af79da9e334a8555e850da136f4.jpg";
                        break;

                    case "wifi":
                        amenitiy.image_url = "http://media.idownloadblog.com/wp-content/uploads/2016/02/wifi-icon.png";
                        break;

                    case "towels":
                        amenitiy.image_url = "http://www.prabhutextile.com/images/bath_towel_1.jpg";
                        break;

                    default:
                        break;
                    }
                    facebookMessage.attachment.payload.elements = new FacebookElement[] { amenitiy };
                    replyMessage.ChannelData = facebookMessage;

                    await context.PostAsync(replyMessage);

                    context.Wait(MessageReceived);
                    return;
                }
            }

            await context.PostAsync("I'm sorry that we don't have that.");

            context.Wait(MessageReceived);
        }
Esempio n. 3
0
        public FacebookMessage GetTemplate()
        {
            var facebookElements = new List <FacebookElement>();

            foreach (var cluster in _clusters)
            {
                var facebookElement = new FacebookElement()
                {
                    Title   = cluster.Description,
                    Buttons = new FacebookButton[]
                    {
                        new FacebookButton()
                        {
                            Title   = cluster.Description,
                            Type    = "postback",
                            Payload = JsonConvert.SerializeObject(new OptionSelectionPayload()
                            {
                                Action = "add", Option = cluster.Id
                            })
                        }
                    }
                };

                facebookElements.Add(facebookElement);
            }

            var facebookMessage = new FacebookMessage()
            {
                Attachment = new FacebookAttachment()
                {
                    Type    = "template",
                    Payload = new FacebookPayload()
                    {
                        Template_type   = "list",
                        TopElementStyle = "compact",
                        Elements        = facebookElements.ToArray(),
                        Buttons         = new FacebookButton[]
                        {
                            new FacebookButton()
                            {
                                Title   = CardMessagesResource.ListCardFinalButtonTitle,
                                Type    = "postback",
                                Payload = JsonConvert.SerializeObject(new OptionSelectionPayload()
                                {
                                    Action = "cancel"
                                })
                            }
                        }
                    },
                }
            };

            return(facebookMessage);
        }
        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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public async Task QueryAmenities(IDialogContext context, LuisResult result)
        {
            foreach (var entity in result.Entities.Where(e => e.Type == "Amenity"))
            {
                var entityValue = entity.Entity.ToLower();

                if (entityValue == "kitchen" || entityValue == "towels" || entityValue == "wifi" || entityValue == "gym")
                {
                    //await context.PostAsync("We have that.");

                    Activity replyMessage = _message.CreateReply();

                    var facebookMessage = new FacebookMessage();
                    facebookMessage.attachment         = new FacebookAttachment();
                    facebookMessage.attachment.type    = "template";
                    facebookMessage.attachment.payload = new FacebookPayload();
                    facebookMessage.attachment.payload.template_type = "generic";

                    var amenity = new FacebookElement();
                    amenity.subtitle = "Yes, we have that";
                    amenity.title    = entityValue;

                    switch (entityValue)
                    {
                    case "kitchen":
                        amenity.image_url = "http://luxurylaunches.com/wp-content/uploads/2015/10/Mark-hotel-suites-3.jpg";
                        break;

                    case "gym":
                        amenity.image_url = "https://s-media-cache-ak0.pinimg.com/originals/cb/c9/4a/cbc94af79da9e334a8555e850da136f4.jpg";
                        break;

                    case "wifi":
                        amenity.image_url = "http://media.idownloadblog.com/wp-content/uploads/2016/02/wifi-icon.png";
                        break;

                    case "towels":
                        amenity.image_url = "http://www.prabhutextile.com/images/bath_towel_1.jpg";
                        break;

                    default:
                        break;
                    }

                    facebookMessage.attachment.payload.elements = new FacebookElement[] { amenity };

                    replyMessage.ChannelData = facebookMessage;
                    await context.PostAsync(replyMessage);

                    context.Wait(MessageReceived);
                    return;
                }
                else
                {
                    await context.PostAsync("I'm sorry. We don't have that.");

                    context.Wait(MessageReceived);
                    return;
                }
            }

            await context.PostAsync("I'm sorry. We don't have that.");

            context.Wait(MessageReceived);
            return;
        }
Esempio n. 7
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;
        }
Esempio n. 8
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;
        }