Ejemplo n.º 1
0
        private async Task ConfirmBookOneOfManyRooms(IDialogContext context, IAwaitable <IMessageActivity> awaitable)
        {
            var result = await awaitable;
            var answer = _cleanup.Replace(result.Text ?? "", "");
            var room   = _roomResults.MatchName(answer);

            if (answer.ToLowerInvariant() == "no" || answer.ToLowerInvariant() == "cancel")
            {
                await context.PostAsync(context.CreateMessage("OK.", InputHints.AcceptingInput));

                context.Done(string.Empty);
            }
            else if (room != null)
            {
                await BookIt(context, room.Id, _criteria.StartTime, _criteria.EndTime);
            }
            else
            {
                var anyRoom = _allRooms.MatchName(answer);
                if (null == anyRoom)
                {
                    await context.PostAsync(context.CreateMessage($"Sorry, I didn't understand '{answer}'", InputHints.IgnoringInput));
                }
                else
                {
                    await context.PostAsync(context.CreateMessage($"Sorry, '{anyRoom.Info.SpeakableName}' isn't an option", InputHints.IgnoringInput));
                }
                await PromptForMultipleRooms(context);
            }
        }
Ejemplo n.º 2
0
 private async Task BookedIt(IDialogContext context, IAwaitable <string> result)
 {
     try
     {
         var msg = await result;
         await context.PostAsync(context.CreateMessage(msg, InputHints.AcceptingInput));
     }
     catch (ApplicationException ex)
     {
         await context.PostAsync(context.CreateMessage($"Failed to book room: {ex.Message}", InputHints.AcceptingInput));
     }
     context.Done(string.Empty);
 }
Ejemplo n.º 3
0
        private async Task PromptForMultipleRooms(IDialogContext context)
        {
            var msg = $"{_roomResults.Count} rooms are available, which do you want?  {string.Join(", ", _roomResults.Select(i => i.Info.SpeakableName).Take(5))}.";
            await context.PostAsync(context.CreateMessage(msg, InputHints.ExpectingInput));

            context.Wait(ConfirmBookOneOfManyRooms);
        }
Ejemplo n.º 4
0
        public async Task ListRooms(IDialogContext context, LuisResult result)
        {
            var rooms = DDDSydney17.Data.Timeslots.SelectMany(t => t.Sessions)
                        .Where(s => !string.IsNullOrWhiteSpace(s.Room.Name)).OrderBy(s => s.Room.Name).Select(s => s.Room.Name)
                        .Distinct();

            var actions = rooms.Select(room => new CardAction
            {
                Title = room,
                Type  = ActionTypes.ImBack,
                Value = $"What is schedule for {room} room?"
            }).ToList();

            var message = context.CreateMessage();

            message.Text             = "Here is a list of available rooms:";
            message.SuggestedActions = new SuggestedActions
            {
                Actions = actions
            };

            await context.PostAsync(message);

            context.Wait(MessageReceived);
        }
Ejemplo n.º 5
0
        public async Task GetEndTime(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var text = (await argument).Text;

            if (string.IsNullOrEmpty(text) || text.ToLowerInvariant() == "cancel" || text.ToLowerInvariant() == "stop")
            {
                context.Done <RoomSearchCriteria>(null);
                return;
            }

            var svc    = GetLuisService();
            var result = await svc.QueryAsync(text, CancellationToken.None);

            _criteria.LoadEndTimeCriteria(result, context.GetTimezone());

            if (!_criteria.EndTime.HasValue)
            {
                await context.PostAsync(context.CreateMessage($"Sorry, I couldn't understand that end time or duration.", InputHints.IgnoringInput));
                await PromptForEndTime(context);

                return;
            }

            await PromptNext(context);
        }
Ejemplo n.º 6
0
        public async Task ClearFloor(IDialogContext context, LuisResult result)
        {
            context.SetPreferredFloor(null);
            await context.PostAsync(context.CreateMessage($"Preferred floor cleared.", InputHints.AcceptingInput));

            context.Done(string.Empty);
        }
Ejemplo n.º 7
0
        public async Task FindVenue(IDialogContext context, LuisResult result)
        {
            var location     = $"{DDDSydney17.Lat},{DDDSydney17.Long}";
            var googleApiKey = ConfigurationManager.AppSettings["GoogleApiKey"];
            var mapUrl       =
                $"https://maps.googleapis.com/maps/api/staticmap?center={location}&zoom=17&size=600x300&maptype=roadmap&markers=color:red%7Clabel:DDD%7C{location}&key={googleApiKey}";

            var card = new HeroCard("DDD Sydney", "UTS",
                                    "DDD Sydney will be held at UTS CBD campus, on Level 3 of the Peter Johnson Building, CB06 (entrance via Harris Street)")
            {
                Images = new List <CardImage>
                {
                    new CardImage(mapUrl)
                },
                Buttons = new List <CardAction>
                {
                    new CardAction
                    {
                        Title = "Get Directions",
                        Type  = ActionTypes.OpenUrl,
                        Value =
                            $"https://www.google.com.au/maps/dir//{location}/@{location},19z/data=!4m8!1m7!3m6!1s0x0:0x0!2zMzPCsDUyJzU5LjYiUyAxNTHCsDEyJzA2LjUiRQ!3b1!8m2!3d{DDDSydney17.Lat}!4d{DDDSydney17.Long}"
                    }
                }
            };

            await context.PostAsync(context.CreateMessage(card.ToAttachment()));

            context.Wait(MessageReceived);
        }
Ejemplo n.º 8
0
        public async Task HelpIntent(IDialogContext context, LuisResult result)
        {
            await context.PostAsync(context.CreateMessage(
                                        $"This is a Rightpoint Labs Beta app and not supported by the helpdesk.  Submit bugs via https://github.com/RightpointLabs/conference-room/issues or bug Rupp ([email protected]) if it's broken.",
                                        $"This is a Rightpoint Labs Beta app and not supported by the helpdesk.  Bug Rupp if it's broken.",
                                        InputHints.AcceptingInput));

            context.Done(string.Empty);
        }
Ejemplo n.º 9
0
        public async Task GotBuilding(IDialogContext context, IAwaitable <BuildingChoice> argument)
        {
            var building = await argument;

            context.SetBuilding(building);

            await context.PostAsync(context.CreateMessage($"Building set to {building.BuildingName}.", InputHints.AcceptingInput));

            context.Done(building);
        }
Ejemplo n.º 10
0
        private async Task SetBuildingCallback(IDialogContext context, IAwaitable <BuildingChoice> result)
        {
            var building = await result;

            context.SetBuilding(building);

            await context.PostAsync(context.CreateMessage($"Building set to {building.BuildingName}.", InputHints.AcceptingInput));

            context.Done(string.Empty);
        }
Ejemplo n.º 11
0
        private async Task SetFloorCallback(IDialogContext context, IAwaitable <FloorChoice> result)
        {
            var floor = await result;

            if (null != floor)
            {
                context.SetPreferredFloor(floor);
                await context.PostAsync(context.CreateMessage($"Preferred floor set to {floor.FloorName}.", InputHints.AcceptingInput));
            }
            context.Done(string.Empty);
        }
Ejemplo n.º 12
0
        private async Task ProcessSecurityLevelChange(IDialogContext context, string securityLevel)
        {
            if (!string.IsNullOrEmpty(securityLevel))
            {
                securityLevel = _cleanup.Replace(securityLevel, "");
            }
            if (string.IsNullOrEmpty(securityLevel) || (securityLevel != "high" && securityLevel != "low"))
            {
                await context.PostAsync(context.CreateMessage($"This bot supports two security modes.  Use high when you're always in control.  Use low when used in public (ie. via Cortana Invoke).  What security level would you like - high or low?", InputHints.ExpectingInput));

                context.Wait(SetSecurityValue);
            }
            else
            {
                await context.PostAsync(context.CreateMessage($"Security set to {securityLevel}.", InputHints.AcceptingInput));

                context.SetSecurityLevel(securityLevel);
                context.Done(string.Empty);
            }
        }
Ejemplo n.º 13
0
        public async Task GotBuilding(IDialogContext context, IAwaitable <BuildingChoice> argument)
        {
            var building   = await argument;
            var buildingId = building?.BuildingId;

            if (string.IsNullOrEmpty(buildingId))
            {
                await context.PostAsync(context.CreateMessage($"Set your building first with the 'set building' command", InputHints.AcceptingInput));

                context.Done(string.Empty);
                return;
            }

            // searching...
            await context.PostAsync(context.CreateMessage($"Booking {_criteria}", InputHints.IgnoringInput));

            await context.SendTyping();

            await context.Forward(new RoomNinjaGetRoomsStatusForBuildingCallDialog(_requestUri, buildingId), GotRoomStatus, context.Activity, new CancellationToken());
        }
Ejemplo n.º 14
0
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            if (null == _buildingName)
            {
                await context.PostAsync(context.CreateMessage($"What building are you in?", InputHints.ExpectingInput));

                context.Wait(GetBuildingName);
                return;
            }

            await context.Forward(new RoomNinjaGetBuildingsCallDialog(_requestUri), GotBuildings, context.Activity, new CancellationToken());
        }
Ejemplo n.º 15
0
        public async Task GotBuilding(IDialogContext context, IAwaitable <BuildingChoice> argument)
        {
            var building   = await argument;
            var buildingId = building?.BuildingId;

            if (string.IsNullOrEmpty(buildingId))
            {
                await context.PostAsync(context.CreateMessage($"Set your building first with the 'set building' command", InputHints.AcceptingInput));

                context.Done <FloorChoice>(null);
                return;
            }

            if (null == _floorName)
            {
                await context.PostAsync(context.CreateMessage($"What is your default floor?", InputHints.ExpectingInput));

                context.Wait(GetFloorName);
                return;
            }

            await context.Forward(new RoomNinjaGetRoomsStatusForBuildingCallDialog(_requestUri, buildingId), GotRooms, context.Activity, new CancellationToken());
        }
Ejemplo n.º 16
0
        public async Task GetSize(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var text = _sizeCleanup.Replace((await argument).Text, "");

            if (string.IsNullOrEmpty(text) || text.ToLowerInvariant() == "cancel" || text.ToLowerInvariant() == "stop")
            {
                await context.PostAsync(context.CreateMessage($"Cancelling.", InputHints.AcceptingInput));

                context.Done <RoomSearchCriteria>(null);
                return;
            }

            _criteria.NumberOfPeople = int.Parse(text);
            await PromptNext(context);
        }
Ejemplo n.º 17
0
        private async Task ConfirmBookOneRoom(IDialogContext context, IAwaitable <IMessageActivity> awaitable)
        {
            var result = await awaitable;
            var answer = _cleanup.Replace(result.Text ?? "", "");

            if (answer.ToLowerInvariant() == "yes" || answer.ToLowerInvariant() == "ok")
            {
                await BookIt(context, _roomResults[0].Id, _criteria.StartTime, _criteria.EndTime);
            }
            else
            {
                await context.PostAsync(context.CreateMessage("Not booking room.", InputHints.AcceptingInput));

                context.Done(string.Empty);
            }
        }
Ejemplo n.º 18
0
        public async Task GetEquipment(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var text = (await argument).Text;

            if (string.IsNullOrEmpty(text) || text.ToLowerInvariant() == "cancel" || text.ToLowerInvariant() == "stop")
            {
                await context.PostAsync(context.CreateMessage($"Cancelling.", InputHints.AcceptingInput));

                context.Done <RoomSearchCriteria>(null);
                return;
            }

            _criteria.ParseEquipment(text);

            await PromptNext(context);
        }
Ejemplo n.º 19
0
        private async Task GotRoomStatus(IDialogContext context, IAwaitable <RoomsService.RoomStatusResult[]> callback)
        {
            var rooms = await callback;
            var room  = rooms.MatchName(_criteria.Room);

            if (null == room)
            {
                var speak = $"Can't find room {_criteria.Room}";
                await context.PostAsync(context.CreateMessage($"{speak}, options: {string.Join(", ", rooms.Select(i => i.Info.SpeakableName))}", speak, InputHints.AcceptingInput));

                context.Done(string.Empty);
            }
            else
            {
                await BookIt(context, room.Id, _criteria.StartTime, _criteria.EndTime);
            }
        }
Ejemplo n.º 20
0
        private static async Task SearchWeb(IDialogContext context, string query)
        {
            if (await SearchQnA(context, query))
            {
                return;
            }

            await context.SendTyping();

            var search       = new BindSearchService();
            var searchResult = await search.Search($"DDD Sydney 2017: {query}");

            var attachments = BingSearchCard.GetSearchCards(searchResult);

            await context.PostAsync("Here it goes, this is what I found.");

            await context.PostAsync(context.CreateMessage(attachments.ToList()));
        }
Ejemplo n.º 21
0
        private async Task GotRooms(IDialogContext context, IAwaitable <RoomsService.RoomStatusResult[]> callback)
        {
            var roomOnFloor = (await callback).MatchFloorName(_floorName);

            if (null == roomOnFloor)
            {
                await context.PostAsync(context.CreateMessage($"Can't find floor {_floorName}.", InputHints.AcceptingInput));

                context.Done <FloorChoice>(null);
            }
            else
            {
                context.Done(new FloorChoice()
                {
                    Floor     = roomOnFloor.Info.Floor,
                    FloorId   = roomOnFloor.Info.FloorId,
                    FloorName = roomOnFloor.Info.FloorName,
                });
            }
        }
Ejemplo n.º 22
0
        private async Task GotBuildings(IDialogContext context, IAwaitable <RoomsService.BuildingResult[]> callback)
        {
            var building = (await callback).MatchName(_buildingName);

            if (null == building)
            {
                await context.PostAsync(context.CreateMessage($"Can't find building {_buildingName}.", InputHints.AcceptingInput));

                context.Done <BuildingChoice>(null);
            }
            else
            {
                var choice = new BuildingChoice()
                {
                    BuildingId   = building.Id,
                    BuildingName = building.Name,
                    TimezoneId   = GetTimezone(building.Id),
                };
                context.Done(choice);
            }
        }
Ejemplo n.º 23
0
        public async Task ListSpeakers(IDialogContext context, LuisResult result)
        {
            var speakers = DDDSydney17.Data.Timeslots.SelectMany(t => t.Sessions).OrderBy(s => s.Presenter.Name)
                           .Select(s => s.Presenter.Name).Distinct();

            var actions = speakers.Select(speaker => new CardAction
            {
                Title = speaker,
                Type  = ActionTypes.ImBack,
                Value = $"When is {speaker}'s talk?"
            }).ToList();

            var message = context.CreateMessage();

            message.Text             = "This is the list of speakers we have this year:";
            message.SuggestedActions = new SuggestedActions
            {
                Actions = actions
            };

            await context.PostAsync(message);

            context.Wait(MessageReceived);
        }
Ejemplo n.º 24
0
 public static IMessageActivity CreateMessage(this IDialogContext context, string text, string inputHint)
 {
     return(context.CreateMessage(text, text, inputHint));
 }
Ejemplo n.º 25
0
        private async Task GotRoomStatus(IDialogContext context, IAwaitable <RoomsService.RoomStatusResult[]> callback)
        {
            var rooms = await callback;
            var room  = rooms.MatchName(_criteria.Room);

            // TODO: do we need to use api.GetRoomsStatus(room.Id) ?
            if (null == room)
            {
                await context.PostAsync(context.CreateMessage($"Can't find room {_criteria.Room}", InputHints.AcceptingInput));
            }
            else
            {
                var tz  = GetTimezone(context.GetBuilding()?.BuildingId);
                var now = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, tz);

                // ok, now we just have rooms that meet the criteria - let's see what's free when asked
                var meetings     = room.Status.NearTermMeetings.Where(i => i.End > (_criteria.StartTime ?? now)).OrderBy(i => i.Start).ToList();
                var firstMeeting = meetings.FirstOrDefault();
                var result       =
                    (null == firstMeeting)
                        ? new { busy = false, room = room, Until = (DateTimeOffset?)null }
                        : (firstMeeting.Start > (_criteria.EndTime ?? _criteria.StartTime ?? now) && !firstMeeting.IsStarted)
                            ? new { busy = false, room = room, Until = (DateTimeOffset?)TimeZoneInfo.ConvertTime(firstMeeting.Start, tz) }
                            : new { busy = true, room = room, Until = (DateTimeOffset?)TimeZoneInfo.ConvertTime(GetNextFree(meetings), tz) };

                var until = result.Until.HasValue ? $"{result.Until.ToSimpleTime()}" : "";
                var start = _criteria.StartTime.HasValue ? $" at {_criteria.StartTime.ToSimpleTime()}" : "";

                var reason = firstMeeting == null ? "" :
                             !string.IsNullOrEmpty(firstMeeting.Organizer) && firstMeeting.Organizer != room.Info.DisplayName ?
                             $" by {firstMeeting.Organizer}" :
                             !string.IsNullOrEmpty(firstMeeting.Subject) ?
                             $" for {firstMeeting.Subject}" :
                             "";
                if (!string.IsNullOrEmpty(reason) && null != firstMeeting && _criteria.StartTime.HasValue)
                {
                    reason = $"{reason} from {TimeZoneInfo.ConvertTime(firstMeeting.Start, tz):h:mm tt}";
                }
                if (!string.IsNullOrEmpty(reason) && null != firstMeeting && (result.Until != firstMeeting.End || _criteria.StartTime.HasValue))
                {
                    reason = $"{reason} until {TimeZoneInfo.ConvertTime(firstMeeting.End, tz).ToSimpleTime()}";
                }

                var displayName = room?.Info?.SpeakableName ?? _criteria.Room;
                if (result.busy)
                {
                    if (!string.IsNullOrEmpty(reason))
                    {
                        if (_criteria.StartTime.HasValue)
                        {
                            reason = $" and will be used{reason}";
                        }
                        else
                        {
                            reason = $" and is currently used{reason}";
                        }
                    }
                    if (result.Until.HasValue)
                    {
                        await context.PostAsync(context.CreateMessage($"{displayName} is busy{start} until {until}{reason}", InputHints.AcceptingInput));
                    }
                    else
                    {
                        await context.PostAsync(context.CreateMessage($"{displayName} is busy{start}{reason}", InputHints.AcceptingInput));
                    }
                }
                else
                {
                    if (result.Until.HasValue)
                    {
                        if (!string.IsNullOrEmpty(reason))
                        {
                            reason = $" when it's reserved{reason}";
                        }
                        await context.PostAsync(context.CreateMessage($"{displayName} is free{start} until {until}{reason}", InputHints.AcceptingInput));
                    }
                    else
                    {
                        await context.PostAsync(context.CreateMessage($"{displayName} is free{start}", InputHints.AcceptingInput));
                    }
                }
            }
            context.Done(string.Empty);
        }
        private async Task PromptForRoom(IDialogContext context)
        {
            await context.PostAsync(context.CreateMessage($"For what room?", InputHints.ExpectingInput));

            context.Wait(GetRoom);
        }
Ejemplo n.º 27
0
        private async Task PromptForEquipment(IDialogContext context)
        {
            await context.PostAsync(context.CreateMessage($"What equipment do you need?", InputHints.ExpectingInput));

            context.Wait(GetEquipment);
        }
Ejemplo n.º 28
0
        private async Task PromptForSize(IDialogContext context)
        {
            await context.PostAsync(context.CreateMessage($"For how many people?", InputHints.ExpectingInput));

            context.Wait(GetSize);
        }
Ejemplo n.º 29
0
        private async Task PromptForEndTime(IDialogContext context)
        {
            await context.PostAsync(context.CreateMessage($"Ending when?", InputHints.ExpectingInput));

            context.Wait(GetEndTime);
        }
Ejemplo n.º 30
0
        public async Task FindTalk(IDialogContext context, LuisResult result)
        {
            if (!result.Entities.Any())
            {
                if (await SearchQnA(context, result.Query))
                {
                    return;
                }

                await context.PostAsync("You need to be a bit more specific");
                await ShowHelp(context);

                return;
            }

            await context.PostAsync("So you are looking for a talk?\n\nLet's see what I have here.");

            await context.SendTyping();

            var timeslots = DDDSydney17.Data.Timeslots;

            if (result.TryFindEntity(KeynoteFilter, out EntityRecommendation _))
            {
                timeslots = timeslots.FindKeynote();
            }

            if (result.TryFindEntity(LocknoteFilter, out EntityRecommendation _))
            {
                timeslots = timeslots.FindLocknote();
            }

            if (result.TryFindEntity(SpeakerFilter, out EntityRecommendation speaker))
            {
                timeslots = timeslots.FindSpeaker(speaker.Entity);
            }

            if (result.TryFindEntity(TitleFilter, out EntityRecommendation title))
            {
                timeslots = timeslots.FindTitle(title.Entity);
            }

            if (result.TryFindEntity(RoomFilter, out EntityRecommendation room))
            {
                timeslots = timeslots.FindRoom(room.Entity);
            }

            if (result.TryFindTime(TimeFilter, NextFilter, out TimeSpan time))
            {
                timeslots = timeslots.FindTime(time);
            }

            if (!timeslots.Any())
            {
                await context.PostAsync("Sorry, but I could not find what you are looking for");;
                await SearchWeb(context, result.Query);
            }
            else
            {
                if (timeslots.SelectMany(x => x.Sessions).Count() > 1)
                {
                    await context.PostAsync("Good news, I found some talks");
                }
                else
                {
                    await context.PostAsync("Good news, I found one talk");
                }
                var message = context.CreateMessage(SessionCard.GetSessionCards(timeslots).ToList());
                await context.PostAsync(message);
            }
            context.Wait(MessageReceived);
        }