public async Task <ActionResult> Post(TranscriptionReferenceRequest reference, [FromServices] DaprClient daprClient, CancellationToken cancellationToken)
        {
            var dapr            = new DaprHelper(daprClient);
            var TranscriptionId = Guid.NewGuid();

            try{
                _logger.LogInformation($"{TranscriptionId}. Request to transcribe {reference.blobURL} was received");

                var state = await dapr.UpdateState(TranscriptionId, reference.blobURL);

                _logger.LogInformation($"{TranscriptionId}. Record was successfullly saved as to {Components.StateStoreName} State Store");

                await dapr.PublishEvent(TranscriptionId, reference.blobURL, cancellationToken);

                _logger.LogInformation($"{TranscriptionId}. {reference.blobURL} was successfullly published to {Components.PubSubName} pubsub store");

                return(Ok(new { TranscriptionId = TranscriptionId, StatusMessage = state.Value.Status, LastUpdated = state.Value.LastUpdateTime }));
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Failed to transcribe {reference.blobURL} - {ex.Message}");
            }

            return(BadRequest());
        }
        public override async Task TranscribeAudioStream(TranscriptionRequest request, IServerStreamWriter <TranscriptionReply> responseStream, ServerCallContext context)
        {
            var TranscriptionId = Guid.NewGuid();
            var createdTime     = DateTime.UtcNow.ToString();

            var reply = new TranscriptionReply {
                TranscriptionId   = TranscriptionId.ToString(),
                CreateTime        = DateTime.UtcNow.ToString(),
                LastUpdateTime    = DateTime.UtcNow.ToString(),
                Status            = TraduireTranscriptionStatus.Started.ToString(),
                BlobUri           = request.BlobUri,
                TranscriptionText = string.Empty
            };

            _logger.LogInformation($"Transcription request was received.");
            try{
                var state = await _daprClient.UpdateState(TranscriptionId, request.BlobUri);

                _logger.LogInformation($"{TranscriptionId}. Transcription request was successfullly saved as to {Components.StateStoreName} State Store");
                await responseStream.WriteAsync(reply);

                await _daprClient.PublishEvent(TranscriptionId, request.BlobUri, context.CancellationToken);

                _logger.LogInformation($"{TranscriptionId}. {request.BlobUri} was successfullly published to {Components.PubSubName} pubsub store");
                reply.Status         = TraduireTranscriptionStatus.SentToCognitiveServices.ToString();
                reply.LastUpdateTime = DateTime.UtcNow.ToString();
                await responseStream.WriteAsync(reply);

                TraduireTranscription currentState;
                do
                {
                    await Task.Delay(TimeSpan.FromSeconds(waitTime));

                    currentState = await _daprClient.GetState(TranscriptionId);

                    _logger.LogInformation($"{TranscriptionId}. Transcription status is {currentState.Status}");
                    reply.Status         = currentState.Status.ToString();
                    reply.LastUpdateTime = DateTime.UtcNow.ToString();
                    await responseStream.WriteAsync(reply);
                } while(currentState.Status != TraduireTranscriptionStatus.Completed);

                _logger.LogInformation($"{TranscriptionId}. Attempting to download completed transcription");
                reply.TranscriptionText = currentState.TranscriptionText;
                await responseStream.WriteAsync(reply);
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Failed to transcribe {request.BlobUri} - {ex.Message}");
                reply.Status         = TraduireTranscriptionStatus.Failed.ToString();
                reply.LastUpdateTime = DateTime.UtcNow.ToString();
                await responseStream.WriteAsync(reply);
            }
        }
        public async Task <ActionResult> Post([FromForm] IFormFile file, [FromServices] DaprClient daprClient, CancellationToken cancellationToken)
        {
            var dapr            = new DaprHelper(daprClient, file);
            var TranscriptionId = Guid.NewGuid();

            _logger.LogInformation($"File upload request was received.");
            try{
                _logger.LogInformation($"{TranscriptionId}. Base64 encoding file and uploading via Dapr to {Components.BlobStoreName}.");

                var response = await dapr.UploadFile(cancellationToken);

                _logger.LogInformation($"{TranscriptionId}. File was successfullly saved to {Components.BlobStoreName} blob storage");

                var sasUrl = await dapr.GetBlobSasToken(response.blobURL, Environment.GetEnvironmentVariable("MSI_CLIENT_ID"));

                _logger.LogInformation($"{TranscriptionId}. File was successfullly saved to {Components.BlobStoreName} blob storage");

                var state = await dapr.UpdateState(TranscriptionId, sasUrl);

                _logger.LogInformation($"{TranscriptionId}. Record was successfullly saved as to {Components.StateStoreName} State Store");

                await dapr.PublishEvent(TranscriptionId, sasUrl, cancellationToken);

                _logger.LogInformation($"{TranscriptionId}. {sasUrl} was successfullly published to {Components.PubSubName} pubsub store");

                return(Ok(new { TranscriptionId = TranscriptionId, StatusMessage = state.Value.Status, LastUpdated = state.Value.LastUpdateTime }));
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Failed to create {file.FileName} - {ex.Message}");

                if (ex.InnerException != null)
                {
                    _logger.LogWarning("Inner exception: {0}", ex.InnerException);
                }
            }

            return(BadRequest());
        }