Exemplo n.º 1
0
        public async Task None(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            LanguageManager lang = await LanguageManager.GetLanguage(context, activity);

            string message = "";
            string image   = "";

            if (result.Entities.Any(e => e.Type == "Genexus"))
            {
                message = lang.Genexus;
            }
            else
            {
                ConversationObject convObj = await Watson.Conversation.SendMessage(result.Query);

                if (convObj != null && convObj.entities.Length > 0)
                {
                    ConversationEntity        convEnt = convObj.entities[0];
                    WatsonEntityHelper.Entity ent     = WatsonEntityHelper.GetEntity(convEnt.entity);
                    Break b;
                    switch (ent)
                    {
                    case WatsonEntityHelper.Entity.Radisson:
                        message = lang.Map;
                        image   = ImageHelper.GetLocationImage();
                        break;

                    case WatsonEntityHelper.Entity.CoatCheck:
                        message = lang.CoatCheck;
                        image   = ImageHelper.GetCoatCheck();
                        break;

                    case WatsonEntityHelper.Entity.FrontDesk:
                        message = lang.FrontDesk;
                        break;

                    case WatsonEntityHelper.Entity.Room:
                        int floor;
                        image   = ImageHelper.GetRoomImage(convEnt.value, out floor);
                        message = string.Format(lang.RoomMap, convEnt.value, floor);
                        break;

                    case WatsonEntityHelper.Entity.Break:
                        b = NextBreak.Find();
                        if (b != null)
                        {
                            message = string.Format(lang.Break, b.Sessionstarttimetext, convEnt.value);
                        }
                        else
                        {
                            message = lang.NoMoreBreaks;
                        }
                        break;

                    case WatsonEntityHelper.Entity.Snack:
                        b = NextBreak.Find();
                        if (b != null)
                        {
                            message = string.Format(lang.Snack, b.Sessionstarttimetext, convEnt.value);
                        }
                        else
                        {
                            message = lang.NoMoreBreaks;
                        }
                        break;

                    case WatsonEntityHelper.Entity.TimeQ:
                        break;

                    default:
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(message) && result.Query.Length > 2)
            {
                SearchServiceSoapClient client = new SearchServiceSoapClient();
                List <SourceParam>      parm   = new List <SourceParam>();
                parm.Add(new SourceParam()
                {
                    sourceName = BotConfiguration.GXSEARCH_KEY
                });
                Search2Response response = await client.Search2Async($"{result.Query} webidioid:{lang.SearchCode}", parm.ToArray(), "SearchHighlight", 1, 10);

                if (response.Body.Search2Result.DocumentsCount > 0)
                {
                    await SendMessage(context, string.Format(lang.SearchFound, response.Body.Search2Result.DocumentsCount, result.Query), result.Query, NONE);

                    foreach (var doc in response.Body.Search2Result.Documents)
                    {
                        StringBuilder msg = new StringBuilder($"- {doc.Description.Sanitize()}");
                        foreach (var p in doc.Properties)
                        {
                            if (p.Key == "charlaexp")
                            {
                                msg.Append($" ({p.Value.Sanitize()})");
                            }
                        }

                        await SendMessage(context, msg.ToString());
                    }
                    context.Wait(MessageReceived);
                    return;
                }
            }

            if (string.IsNullOrEmpty(message))
            {
                int fails = 1;
                if (context.UserData.TryGetValue <int>(CONSECUTIVES_FAILS, out fails))
                {
                    fails++;
                    if (fails > 6)
                    {
                        message = lang.MyBad6;
                    }
                    else if (fails > 4)
                    {
                        message = lang.MyBad4;
                    }
                    else if (fails > 2)
                    {
                        message = lang.MyBad2;
                    }
                    else
                    {
                        message = lang.MyBad1;
                    }
                }
                else
                {
                    message = lang.MyBad1;
                }

                context.UserData.SetValue <int>(CONSECUTIVES_FAILS, fails);
            }
            else
            {
                OnSuccess(context);
            }


            await SendMessage(context, message, image, result.Query, NONE);

            context.Wait(MessageReceived);
        }
Exemplo n.º 2
0
        public async Task Location(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            if (IsScoreTooLow(context, result))
            {
                await None(context, activity, result);

                return;
            }
            else
            {
                OnSuccess(context);
            }

            LanguageManager lang = await LanguageManager.GetLanguage(context, activity);

            ConversationObject convObj = await Watson.Conversation.SendMessage(result.Query);

            if (convObj != null && convObj.entities.Length > 0)
            {
                ConversationEntity        entity = convObj.entities[0];
                WatsonEntityHelper.Entity ent    = WatsonEntityHelper.GetEntity(entity.entity);
                string message = "";                // $"{entity.entity}:{entity.value}";
                string image   = null;
                Break  b;
                switch (ent)
                {
                case WatsonEntityHelper.Entity.CDS:
                    break;

                case WatsonEntityHelper.Entity.Radisson:
                    message = lang.Map;
                    image   = ImageHelper.GetLocationImage();
                    break;

                case WatsonEntityHelper.Entity.CoatCheck:
                    message = lang.CoatCheck;
                    image   = ImageHelper.GetCoatCheck();
                    break;

                case WatsonEntityHelper.Entity.FrontDesk:
                    message = lang.FrontDesk;
                    break;

                case WatsonEntityHelper.Entity.Room:
                    int floor;
                    image   = ImageHelper.GetRoomImage(entity.value, out floor);
                    message = string.Format(lang.RoomMap, entity.value, floor);
                    break;

                case WatsonEntityHelper.Entity.Break:
                    b = NextBreak.Find();
                    if (b != null)
                    {
                        message = string.Format(lang.Break, b.Sessionstarttimetext);
                    }
                    else
                    {
                        message = lang.NoMoreBreaks;
                    }
                    break;

                case WatsonEntityHelper.Entity.Snack:
                    b = NextBreak.Find();
                    if (b != null)
                    {
                        message = string.Format(lang.Snack, b.Sessionstarttimetext, entity.value);
                    }
                    else
                    {
                        message = lang.NoMoreBreaks;
                    }
                    break;

                case WatsonEntityHelper.Entity.Restroom:
                    var floors = new[] { 2, 3, 4 };
                    PromptDialog.Choice(context, RestroomFloorComplete, floors, string.Format(lang.WhatFloor, floors), string.Format(lang.InvalidFloor, floors), 3, PromptStyle.Auto);
                    return;

                default:
                    break;
                }

                await SendMessage(context, message, image, result.Query, LOCATION);
            }
            else
            {
                await SendMessage(context, lang.NoLocation, result.Query, LOCATION);
            }

            context.Wait(MessageReceived);
        }