Exemplo n.º 1
0
 public async Task <int?> GetPhoneColumn(Guid sourceId)
 {
     return(await _sourceManager.GetPhoneColumn(sourceId));
 }
Exemplo n.º 2
0
        public async Task ProcessNew()
        {
            var events = await _eventManager.GetEvents()
                         .Where(x => x.Status == EventStatus.Pending).ToListAsync();

            foreach (var newEvent in events)
            {
                newEvent.Status = EventStatus.InProgress;
                await _eventManager.UpdateEvent(newEvent);

                var text = await _textManager.GetText(newEvent.TextId);

                var phoneColumnResult = await _sourceManager.GetPhoneColumn(newEvent.SourceId);

                var phoneColumn = 0;
                if (phoneColumnResult != null)
                {
                    phoneColumn = (int)phoneColumnResult;
                }

                var headers = await _sourceManager.GetHeaders(newEvent.SourceId);

                var content = await _sourceManager.GetContent(newEvent.SourceId, int.MaxValue, 0);

                foreach (var item in content.Items)
                {
                    var phoneNumber = item[phoneColumn];

                    var finalText = _textConverter.GenerateResultingText(headers, item, text.Value);

                    var voiceFile = await _voiceService.GenerateAudio(finalText, text.Language, text.Speaker, text.Emotion, text.Speed);

                    //var callAudioFile = _audioConverter.Convert(voiceFile.Value);

                    var call = new Call
                    {
                        EventId     = newEvent.Id,
                        MessageText = finalText,
                        Phone       = phoneNumber,
                        Result      = CallResult.Pending
                    };

                    var newCall = await _callManager.AddCall(call);

                    var formatName        = Enum.GetName(typeof(AudioFormat), _voiceService.Format);
                    var voiceFileNameBase = $"{newEvent.Id.ToString()}_{newCall.Id.ToString()}";
                    var voiceFileName     = $"{voiceFileNameBase}.{formatName}";

                    //change to callAudioFile
                    var voiceUrl = await _blobManager.UploadFile(voiceFile.Value, voiceFileName, _voiceService.Format);

                    var callResultSuccess = await _telephonyHandler.MakeCall(phoneNumber, voiceUrl, voiceFileName, voiceFileNameBase);

                    newCall.Result = callResultSuccess ? CallResult.Success : CallResult.Failed;

                    // TODO add migration with removed Required header
                    newCall.Created = DateTime.Now;

                    await _callManager.UpdateCall(newCall);

                    // TODO FIX THIS SHIT
                    Thread.Sleep(30000);
                }
            }
        }