public async Task <OpenApiResult> GenerateTemplateAsync( IOpenApiContext context, CreateNotificationsRequest body) { // We can guarantee tenant Id is available because it's part of the Uri. ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId !).ConfigureAwait(false); var registeredCommunicationChannels = new List <CommunicationType>() { CommunicationType.WebPush, CommunicationType.Email, CommunicationType.Sms }; // TODO: In the future, check if these registeredCommunicationChannels are actually usable for the current Tenant. if (registeredCommunicationChannels is null || registeredCommunicationChannels.Count == 0) { throw new Exception($"There are no communication channel set up for the user {body.UserIds[0]} for notification type {body.NotificationType} for tenant {tenant.Id}"); } // Gets the AzureBlobTemplateStore INotificationTemplateStore templateStore = await this.tenantedTemplateStoreFactory.GetTemplateStoreForTenantAsync(tenant).ConfigureAwait(false); NotificationTemplate?responseTemplate = await this.generateTemplateComposer.GenerateTemplateAsync(templateStore, body.Properties, registeredCommunicationChannels, body.NotificationType).ConfigureAwait(false); return(this.OkResult(responseTemplate)); }
public async Task <OpenApiResult> CreateNotificationsAsync( IOpenApiContext context, CreateNotificationsRequest body) { // We can guarantee tenant Id is available because it's part of the Uri. ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId !).ConfigureAwait(false); string delegatedTenantId = await this.marainServicesTenancy.GetDelegatedTenantIdForRequestingTenantAsync(tenant.Id).ConfigureAwait(false); var operationId = Guid.NewGuid(); CreateOperationHeaders response = await this.operationsControlClient.CreateOperationAsync( delegatedTenantId, operationId).ConfigureAwait(false); // Create a new CreateNotificationForDeliveryChannelsRequest Object which supports the communication types and delivery channels var createNotificationForDeliveryChannelsRequestObject = new CreateNotificationForDeliveryChannelsRequest( body.NotificationType, body.UserIds, body.Timestamp, body.Properties, body.CorrelationIds); IDurableOrchestrationClient orchestrationClient = context.AsDurableFunctionsOpenApiContext().OrchestrationClient ?? throw new OpenApiServiceMismatchException($"Operation {CreateNotificationsOperationId} has been invoked, but no Durable Orchestration Client is available on the OpenApi context."); await orchestrationClient.StartNewAsync( nameof(CreateAndDispatchNotificationsOrchestration), new TenantedFunctionData <CreateNotificationForDeliveryChannelsRequest>(context.CurrentTenantId !, createNotificationForDeliveryChannelsRequestObject, operationId)).ConfigureAwait(false); return(this.AcceptedResult(response.Location)); }
public async Task <OpenApiResult> CreateNotificationsAsync( IOpenApiContext context, CreateNotificationsRequest body) { // We can guarantee tenant Id is available because it's part of the Uri. ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId !).ConfigureAwait(false); string delegatedTenantId = await this.marainServicesTenancy.GetDelegatedTenantIdForRequestingTenantAsync(tenant.Id).ConfigureAwait(false); var operationId = Guid.NewGuid(); CreateOperationHeaders response = await this.operationsControlClient.CreateOperationAsync( delegatedTenantId, operationId).ConfigureAwait(false); IDurableOrchestrationClient orchestrationClient = context.AsDurableFunctionsOpenApiContext().OrchestrationClient ?? throw new OpenApiServiceMismatchException($"Operation {CreateNotificationsOperationId} has been invoked, but no Durable Orchestration Client is available on the OpenApi context."); await orchestrationClient.StartNewAsync( nameof(CreateAndDispatchNotificationsOrchestration), new TenantedFunctionData <CreateNotificationsRequest>(context.CurrentTenantId !, body, operationId)).ConfigureAwait(false); return(this.AcceptedResult(response.Location)); }