Esempio n. 1
0
        public async Task <bool> CreateCall(Tuple <int, string> emailType, Message message)
        {
            _log.Information($"ImportService::Creating call for email: {message.Id}||{message.InboundMessage.MessageID}");

            var departmentData = _dataService.GetDataProviderByEmailCode(emailType.Item2);

            if (departmentData != null)
            {
                try
                {
                    int emailFormatType = 0;

                    if (departmentData.Options == null || departmentData.Options.EmailFormatType < 0)
                    {
                        departmentData.Options.EmailFormatType = (int)CallEmailTypes.Generic;
                    }
                    else
                    {
                        emailFormatType = departmentData.Options.EmailFormatType;
                    }

                    List <Call> activeCalls = new List <Call>();
                    if (CallTypesThatNeedActiveCalls.CallTypes.Contains(emailFormatType))
                    {
                        activeCalls = await CallsApi.GetActiveCalls(departmentData.DepartmentInfo.Id);
                    }

                    int defaultPriority = (int)ApiClient.Common.CallPriority.High;

                    if (departmentData.CallPriorities != null && departmentData.CallPriorities.Any())
                    {
                        var defaultPrio = departmentData.CallPriorities.FirstOrDefault(x => x.IsDefault && x.IsDeleted == false);

                        if (defaultPrio != null)
                        {
                            defaultPriority = defaultPrio.Id;
                        }
                    }

                    var call = _callsService.GenerateCallFromEmail((CallEmailTypes)emailFormatType, message.InboundMessage,
                                                                   departmentData.DepartmentInfo.ManagingUserId,
                                                                   departmentData.DepartmentInfo.Members, departmentData.DepartmentInfo, activeCalls, departmentData.Units, defaultPriority);

                    if (call != null)
                    {
                        call.DepartmentId = departmentData.DepartmentInfo.Id;

                        var savedCall = await CallsApi.AddNewCall(call);
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex, $"ImportService::Exception attempting to create call for email: {message.Id}||{message.InboundMessage.MessageID}");
                }
            }

            return(false);
        }
Esempio n. 2
0
 public void Init()
 {
     instance = new CallsApi();
 }
Esempio n. 3
0
        private void _audioProcessor_TriggerProcessingFinished(object sender, Events.TriggerProcessedEventArgs e)
        {
            if (e.Mp3Audio != null && e.Mp3Audio.Length > 0)
            {
                Call newCall = new Call();
                newCall.Priority = (int)CallPriority.Medium;
                StringBuilder watchersToned = new StringBuilder();

                watchersToned.Append($"{e.Watcher.Name} ");

                newCall.GroupCodesToDispatch = new List <string>();
                newCall.GroupCodesToDispatch.Add(e.Watcher.Code);
                newCall.CallSource       = 3;
                newCall.SourceIdentifier = e.Watcher.Id.ToString();

                var additionalCodes = e.Watcher.GetAdditionalWatchers();
                if (additionalCodes != null && additionalCodes.Count > 0)
                {
                    foreach (var code in additionalCodes)
                    {
                        if (!newCall.GroupCodesToDispatch.Contains(code.Code))
                        {
                            watchersToned.Append($"{code.Name} ");
                            newCall.GroupCodesToDispatch.Add(code.Code);

                            if (code.Type == 1)
                            {
                                newCall.AllCall = true;
                            }
                        }
                    }
                }

                // Run through the additional comma seperated group codes and add them.
                if (!string.IsNullOrWhiteSpace(e.Watcher.AdditionalCodes))
                {
                    var newCodes = e.Watcher.AdditionalCodes.Split(char.Parse(","));

                    if (newCodes != null && newCodes.Length > 0)
                    {
                        foreach (var code in newCodes)
                        {
                            if (!newCall.GroupCodesToDispatch.Contains(code))
                            {
                                newCall.GroupCodesToDispatch.Add(code);
                            }
                        }
                    }
                }

                newCall.NatureOfCall =
                    $"Relay import, listen to audio for call info. Toned: {watchersToned}";
                newCall.Notes =
                    $"Audio importted call from a radio dispatch using the Resgrid Relay app. Listen to attached audio for call information. Call was created on {DateTime.Now.ToString("F")}. Was an AllCall: {newCall.AllCall}. Watchers Toned: {watchersToned}";

                if (e.Watcher.Type == 1)
                {
                    newCall.AllCall = true;
                }

                if (newCall.AllCall)
                {
                    newCall.Name = $"ALLCALL Audio Import {DateTime.Now.ToString("g")}";
                }
                else
                {
                    newCall.Name = $"Audio Import {DateTime.Now.ToString("g")}";
                }

                newCall.Attachments = new List <CallAttachment>();
                newCall.Attachments.Add(new CallAttachment()
                {
                    CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio,
                    FileName           = $"Relay_{e.Watcher.TriggerFiredTimestamp.ToString("s").Replace(":", "_")}.mp3",
                    Timestamp          = DateTime.UtcNow,
                    Data = e.Mp3Audio
                });

                try
                {
                    var savedCall = AsyncHelpers.RunSync <Call>(() => CallsApi.AddNewCall(newCall));

                    if (savedCall != null)
                    {
                        CallCreatedEvent?.Invoke(this, new CallCreatedEventArgs(e.Watcher.Name, savedCall.CallId, savedCall.Number, DateTime.Now));
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(ex.ToString());
                }
                finally
                {
                    newCall = null;
                }
            }
            else
            {
                _logger.Warning($"No Dispatch Audio detected, unable to save call for {e.Watcher.Name}");
            }
        }