public static UserFindMeetingTimesRequestBody GetUserFindMeetingTimesRequestBody(DateTimeOffset date, string[] normalizedEmails, int normalizedDuration, bool isOrganizerOptional) { var startDate = date; // TBD: should be input by user var dateDuration = new TimeSpan(1, 0, 0, 0); var jstTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"); var endDate = new DateTimeOffset(date.AddDays(dateDuration.Days).Year, date.AddDays(dateDuration.Days).Month, date.AddDays(dateDuration.Days).Day, 0, 0, 0, jstTimeZoneInfo.BaseUtcOffset); var startDateQuery = $"{startDate.UtcDateTime.Year:D4}-{startDate.UtcDateTime.Month:D2}-{startDate.UtcDateTime.Day:D2}" + $"T{startDate.UtcDateTime.Hour:D2}:{startDate.UtcDateTime.Minute:D2}:{startDate.UtcDateTime.Second:D2}.{startDate.UtcDateTime.Millisecond:D3}Z"; var endDateQuery = $"{endDate.UtcDateTime.Year:D4}-{endDate.UtcDateTime.Month:D2}-{endDate.UtcDateTime.Day:D2}" + $"T{endDate.UtcDateTime.Hour:D2}:{endDate.UtcDateTime.Minute:D2}:{endDate.UtcDateTime.Second:D2}.{endDate.UtcDateTime.Millisecond:D3}Z"; var inputAttendee = normalizedEmails.Select(i => new Attendee() { EmailAddress = new EmailAddress() { Address = i } }) .ToList(); var inputDuration = new Duration(TimeSpan.FromMinutes(normalizedDuration)); var userFindMeetingTimesRequestBody = new UserFindMeetingTimesRequestBody() { Attendees = inputAttendee, TimeConstraint = new TimeConstraint() { Timeslots = new List <TimeSlot>() { new TimeSlot() { Start = new DateTimeTimeZone() { DateTime = startDateQuery, TimeZone = "UTC" }, End = new DateTimeTimeZone() { DateTime = endDateQuery, TimeZone = "UTC" } } } }, MeetingDuration = inputDuration, MaxCandidates = 15, IsOrganizerOptional = isOrganizerOptional, ReturnSuggestionReasons = true, MinimumAttendeePercentage = 100 }; return(userFindMeetingTimesRequestBody); }
/// <summary> /// Get request object for find meeting times API /// </summary> /// <param name="date">String representation of date</param> /// <param name="normalizedEmails">List of participants emails</param> /// <param name="normalizedDuration">Duration of the meeting</param> /// <returns><see cref="UserFindMeetingTimesRequestBody" /></returns> public static UserFindMeetingTimesRequestBody GetUserFindMeetingTimesRequestBody(DateTime date, string[] normalizedEmails, int normalizedDuration) { var startDate = $"{date.Year:D4}-{date.Month:D2}-{date.Day:D2}T00:00:00.000Z"; var endDate = $"{date.Year:D4}-{date.Month:D2}-{date.Day:D2}T10:00:00.000Z"; var inputAttendee = normalizedEmails.Select(i => new Attendee() { EmailAddress = new EmailAddress() { Address = i } }) .ToList(); var inputDuration = new Duration(new TimeSpan(0, normalizedDuration, 0)); var userFindMeetingTimesRequestBody = new UserFindMeetingTimesRequestBody() { Attendees = inputAttendee, TimeConstraint = new TimeConstraint() { Timeslots = new List<TimeSlot>() { new TimeSlot() { Start = new DateTimeTimeZone() { DateTime = startDate, TimeZone = "UTC" }, End = new DateTimeTimeZone() { DateTime = endDate, TimeZone = "UTC" } } } }, MeetingDuration = inputDuration, MaxCandidates = 15, IsOrganizerOptional = true, //false, ReturnSuggestionReasons = true, MinimumAttendeePercentage = 100 }; return userFindMeetingTimesRequestBody; }
public void AddRooms(UserFindMeetingTimesRequestBody request, List <Room> rooms) { var attendees = request.Attendees as List <Attendee>; foreach (var room in rooms) { attendees.Add(new Attendee() { EmailAddress = new EmailAddress() { Address = room.Address, Name = room.Name }, Type = AttendeeType.Optional }); } }
/// <summary> /// Add rooms to meeting time suggestion request /// </summary> /// <param name="request">Meeting time suggestion request</param> /// <param name="rooms">List of rooms</param> public void AddRooms(UserFindMeetingTimesRequestBody request, List <Room> rooms) { try { var attendees = request.Attendees as List <Attendee>; attendees?.AddRange(rooms.Select(room => new Attendee() { EmailAddress = new EmailAddress() { Address = room.Address, Name = room.Name }, Type = AttendeeType.Optional })); } catch (Exception ex) { _loggingService.Error(ex); throw; } }
/// <summary> /// Provides meeting times suggestions /// </summary> /// <param name="accessToken">Access Token for API</param> /// <param name="userFindMeetingTimesRequestBody">Request object for calling Find Meeting Times API</param> /// <returns>Task of <see cref="MeetingTimeSuggestionsResult"/></returns> public async Task <MeetingTimeSuggestionsResult> GetMeetingsTimeSuggestions(string accessToken, UserFindMeetingTimesRequestBody userFindMeetingTimesRequestBody) { try { var rooms = await _roomService.GetRooms(accessToken); _roomService.AddRooms(userFindMeetingTimesRequestBody, rooms); var httpResponseMessage = await _httpService.AuthenticatedPost(FindsMeetingTimeEndpoint, accessToken, userFindMeetingTimesRequestBody, string.Empty); var meetingTimeSuggestionsResult = JsonConvert.DeserializeObject <MeetingTimeSuggestionsResult>(await httpResponseMessage.Content.ReadAsStringAsync()); return(meetingTimeSuggestionsResult); } catch (Exception ex) { _loggingService.Error(ex); throw; } }
public async Task <MeetingTimeSuggestionsResult> GetMeetingsTimeSuggestions(string accessToken, UserFindMeetingTimesRequestBody userFindMeetingTimesRequestBody) { try { //var rooms = roomService.GetRooms(); //roomService.AddRooms(userFindMeetingTimesRequestBody, rooms); var httpResponseMessage = await ApplyOperation(FindsMeetingTimeEndpoint, accessToken, userFindMeetingTimesRequestBody, string.Empty); var meetingTimeSuggestionsResult = JsonConvert.DeserializeObject <MeetingTimeSuggestionsResult>(await httpResponseMessage.Content.ReadAsStringAsync()); return(meetingTimeSuggestionsResult); } catch (Exception ex) { // TBD - log exception var messgae = ex.Message; throw ex; } }
private async Task GetMeetingSuggestions(IDialogContext context, IAwaitable <string> argument) { string startDate = date + "T00:00:00.000Z"; string endDate = date + "T20: 00:00.00Z"; List <Attendee> inputAttendee = new List <Attendee>(); foreach (var i in normalizedEmails) { inputAttendee.Add( new Attendee() { EmailAddress = new EmailAddress() { Address = i } } ); } Duration inputDuration = new Duration(new TimeSpan(0, normalizedDuration, 0)); var userFindMeetingTimesRequestBody = new UserFindMeetingTimesRequestBody() { Attendees = inputAttendee, TimeConstraint = new TimeConstraint() { Timeslots = new List <TimeSlot>() { new TimeSlot() { Start = new DateTimeTimeZone() { DateTime = startDate, TimeZone = "UTC" }, End = new DateTimeTimeZone() { DateTime = endDate, TimeZone = "UTC" } } } }, MeetingDuration = inputDuration, MaxCandidates = 15, IsOrganizerOptional = false, ReturnSuggestionReasons = true, MinimumAttendeePercentage = 100 }; var meetingTimeSuggestion = await meetingService.GetMeetingsTimeSuggestions(result.AccessToken, userFindMeetingTimesRequestBody); var stringBuilder = new StringBuilder(); int num = 1; lstStartDateTme = new List <DateTime>(); foreach (var suggestion in meetingTimeSuggestion.MeetingTimeSuggestions) { DateTime startTime, endTime; DateTime.TryParse(suggestion.MeetingTimeSlot.Start.DateTime, out startTime); DateTime.TryParse(suggestion.MeetingTimeSlot.End.DateTime, out endTime); lstStartDateTme.Add(startTime); stringBuilder.AppendLine($"{num} {startTime.AddHours(timeZoneHours).AddMinutes(timeZoneMinutes).ToString()} - {endTime.AddHours(timeZoneHours).AddMinutes(timeZoneMinutes).ToString()}\n"); num++; } await context.PostAsync($"There are the options for meeting"); await context.PostAsync(stringBuilder.ToString()); PromptDialog.Text(context, this.ScheduleMeeitng, "Please select one slot by giving input such as 1, 2 ,3 ....."); }
// TBD - inject function logic for the interaction with Graph API private async Task GetMeetingSuggestions(IDialogContext context, IMessageActivity message) { try { await context.Forward(new AuthDialog(new MSALAuthProvider(), GetAuthenticationOptions()), async (IDialogContext authContext, IAwaitable <AuthResult> authResult) => { #region TBD Replace with real input var userFindMeetingTimesRequestBody = new UserFindMeetingTimesRequestBody() { Attendees = new List <Attendee>() { new Attendee() { EmailAddress = new EmailAddress() { Address = "*****@*****.**", Name = "Alex Darrow" } } }, LocationConstraint = new LocationConstraint() { IsRequired = false, SuggestLocation = true, Locations = new List <LocationConstraintItem>() { new LocationConstraintItem() { DisplayName = "Conf Room 32/1368", LocationEmailAddress = "*****@*****.**" } } }, TimeConstraint = new TimeConstraint() { Timeslots = new List <TimeSlot>() { new TimeSlot() { Start = new DateTimeTimeZone() { DateTime = "2017-07-27T04:19:50.442Z", TimeZone = "Pacific Standard Time" }, End = new DateTimeTimeZone() { DateTime = "2017-08-03T04:19:50.442Z", TimeZone = "Pacific Standard Time" } } } }, MeetingDuration = new Duration(new TimeSpan(2, 0, 0)), MaxCandidates = 15, IsOrganizerOptional = false, ReturnSuggestionReasons = true, MinimumAttendeePercentage = 100 }; #endregion var result = await authResult; var meetingTimeSuggestion = await meetingService.GetMeetingsTimeSuggestions(result.AccessToken, userFindMeetingTimesRequestBody); var stringBuilder = new StringBuilder(); foreach (var suggestion in meetingTimeSuggestion.MeetingTimeSuggestions) { stringBuilder.AppendLine($"start - {suggestion.MeetingTimeSlot.Start.DateTime.ToString()} and end - {suggestion.MeetingTimeSlot.End.DateTime.ToString()}"); } await authContext.PostAsync($"Thesre are the options for meeting {stringBuilder.ToString()}"); }, message, CancellationToken.None); } catch (Exception ex) { var msg = ex.Message; throw ex; } }