/// <summary> /// Create a Bookings appointment for the given consult request. /// </summary> /// <param name="ssoToken">The SSO token of the calling agent.</param> /// <param name="request">The consult request to book.</param> /// <param name="assignedStaffMemberId">The Bookings staff member ID of the assigned agent.</param> /// <param name="azureADSettings">Azure AD configuration settings.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation. The task result contains the created <see cref="GraphBeta.BookingAppointment"/>.</returns> public static async Task<GraphBeta.BookingAppointment> CreateBookingsAppointment(string ssoToken, Request request, string assignedStaffMemberId, AzureADSettings azureADSettings) { var authProvider = CreateOnBehalfOfProvider(azureADSettings, new[] { "BookingsAppointment.ReadWrite.All" }); var graphServiceClient = new GraphBeta.GraphServiceClient(authProvider); var bookingAppointment = new GraphBeta.BookingAppointment { CustomerEmailAddress = request.CustomerEmail, CustomerName = request.CustomerName, CustomerPhone = request.CustomerPhone, Start = GraphBeta.DateTimeTimeZone.FromDateTimeOffset(request.AssignedTimeBlock.StartDateTime.ToUniversalTime(), System.TimeZoneInfo.Utc), End = GraphBeta.DateTimeTimeZone.FromDateTimeOffset(request.AssignedTimeBlock.EndDateTime.ToUniversalTime(), System.TimeZoneInfo.Utc), OptOutOfCustomerEmail = false, ServiceId = request.BookingsServiceId, StaffMemberIds = new List<string> { assignedStaffMemberId }, IsLocationOnline = true, }; var bookingResult = await graphServiceClient.BookingBusinesses[request.BookingsBusinessId].Appointments .Request() .WithUserAssertion(new UserAssertion(ssoToken)) .AddAsync(bookingAppointment); return bookingResult; }
/// <summary> /// Update a Bookings appointment. /// </summary> /// <param name="ssoToken">The SSO token.</param> /// <param name="request">The consult request to book.</param> /// <param name="assignedStaffMemberId">The Bookings staff member ID of the assigned agent.</param> /// <param name="azureADSettings">Azure AD configuration settings.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public static async Task UpdateBookingsAppointment(string ssoToken, Request request, string assignedStaffMemberId, AzureADSettings azureADSettings) { var authProvider = CreateOnBehalfOfProvider(azureADSettings, new[] { "BookingsAppointment.ReadWrite.All" }); var graphServiceClient = new GraphBeta.GraphServiceClient(authProvider); var bookingAppointment = new GraphBeta.BookingAppointment { StaffMemberIds = new List<string> { assignedStaffMemberId }, }; await graphServiceClient.BookingBusinesses[request.BookingsBusinessId].Appointments[request.BookingsAppointmentId] .Request() .WithUserAssertion(new UserAssertion(ssoToken)) .UpdateAsync(bookingAppointment); }
/// <summary> /// Gets the Bookings staff member ID for the given user. /// </summary> /// <param name="ssoToken">The SSO token.</param> /// <param name="businessId">The ID for the Bookings business to use.</param> /// <param name="userPrincipalName">The UPN of the user.</param> /// <param name="azureADSettings">Azure AD configuration settings.</param> /// <returns>The Bookings staff member ID for the given user, or null if not found.</returns> public static async Task<string> GetBookingsStaffMemberId(string ssoToken, string businessId, string userPrincipalName, AzureADSettings azureADSettings) { var authProvider = CreateOnBehalfOfProvider(azureADSettings, new[] { "BookingsAppointment.ReadWrite.All" }); var graphServiceClient = new GraphBeta.GraphServiceClient(authProvider); var staffMembersRequest = graphServiceClient.BookingBusinesses[businessId].StaffMembers .Request() .Select(staffMember => new { staffMember.Id }) .Filter($"emailAddress eq '{userPrincipalName}'") .WithUserAssertion(new UserAssertion(ssoToken)); var staffMembers = await staffMembersRequest.GetAsync(); // We expect exactly one staff member to match if (staffMembers.Count != 1) { return null; } return staffMembers.FirstOrDefault()?.Id; }