// >> START recordings-downloader-step-5
        public static void downloadAllRecordings(string dates)
        {
            Console.WriteLine("Start batch request process.");
            BatchDownloadJobStatusResult completedBatchStatus = new BatchDownloadJobStatusResult();

            // Process and build the request for downloading the recordings
            // Get the conversations within the date interval and start adding them to batch request
            AnalyticsConversationQueryResponse conversationDetails = conversationsApi.PostAnalyticsConversationsDetailsQuery(new ConversationQuery(Interval: dates));

            foreach (var conversations in conversationDetails.Conversations)
            {
                addConversationRecordingsToBatch(conversations.ConversationId);
            }

            // Send a batch request and start polling for updates
            BatchDownloadJobSubmissionResult result = recordingApi.PostRecordingBatchrequests(batchRequestBody);

            completedBatchStatus = getRecordingStatus(result);

            // Start downloading the recording files individually
            foreach (var recording in completedBatchStatus.Results)
            {
                downloadRecording(recording);
            }
        }
 /// <summary>
 /// Format conversation details to object inside and array. Get every mediatype per conversation
 /// </summary>
 /// <param name="conversationDetails"></param>
 /// <returns></returns>
 private static void extractConversationDetails(AnalyticsConversationQueryResponse conversationDetails)
 {
     // Push all conversationId from conversationDetails to conversationIds
     foreach (var conversationDetail in conversationDetails.Conversations)
     {
         getRecordingMetaData(conversationDetail.ConversationId);
     }
 }
Example #3
0
        private AnalyticsConversation GetSingleAnalyticsConversation(string conversationId)
        {
            var conversations = new List <AnalyticsConversation>();
            AnalyticsConversationQueryResponse analyticsConversationQueryResponse = null;

            // Find conversation by id
            AddLog($"Getting a single Analytics Conversation: {conversationId}", true);

            var interval = $"{dtAnalyticsStart.Value.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ")}/{dtAnalyticsEnd.Value.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ")}";

            AddLog($"Interval: {interval}", true);

            var body = new ConversationQuery()
            {
                Interval            = interval,
                ConversationFilters = new List <AnalyticsQueryFilter>()
                {
                    new AnalyticsQueryFilter(
                        AnalyticsQueryFilter.TypeEnum.And,
                        new List <AnalyticsQueryClause>()
                    {
                        new AnalyticsQueryClause()
                        {
                            Type       = AnalyticsQueryClause.TypeEnum.And,
                            Predicates = new List <AnalyticsQueryPredicate>()
                            {
                                new AnalyticsQueryPredicate()
                                {
                                    Type      = AnalyticsQueryPredicate.TypeEnum.Dimension,
                                    Dimension = AnalyticsQueryPredicate.DimensionEnum.Conversationid,
                                    _Operator = AnalyticsQueryPredicate.OperatorEnum.Matches,
                                    Value     = conversationId
                                }
                            }
                        }
                    }
                        )
                },
                Paging = new PagingSpec()
                {
                    PageSize   = 25,
                    PageNumber = 1
                }
            };

            analyticsConversationQueryResponse = analyticsApi.PostAnalyticsConversationsDetailsQuery(body);
            if (analyticsConversationQueryResponse.Conversations != null && analyticsConversationQueryResponse.Conversations.Count > 0)
            {
                AddLog($"Got {analyticsConversationQueryResponse.Conversations.Count} analytics conversation(s)", true);
                return(analyticsConversationQueryResponse.Conversations[0]);
            }
            else
            {
                MessageBox.Show($"Conversation {conversationId} not found.");
            }
            return(null);
        }
Example #4
0
        /// <summary>
        /// Get all conversations by interval.
        /// Link: https://developer.mypurecloud.com/api/rest/v2/conversations/#post-api-v2-analytics-conversations-details-query
        /// </summary>
        /// <param name="begin">Datetime, begin date of interval</param>
        /// <param name="end">Datetime, end date of interval</param>
        /// <returns>List<AnalyticsConversation>, list of purecloud conversations</returns>
        public async Task <List <AnalyticsConversation> > GetConversationsByInterval(DateTime begin, DateTime end, int pageNumber)
        {
            List <AnalyticsConversation> result = new List <AnalyticsConversation>();

            using (HttpClient hc = new HttpClient())
            {
                hc.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"Bearer {_token}");
                hc.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");

                AnalyticsConversationQueryResponse response = new AnalyticsConversationQueryResponse();
                ConversationQuery queryParam = new ConversationQuery()
                {
                    //Interval = "2019-01-01T00:00:00.000Z/2019-01-31T23:59:59.999Z",
                    Interval = $"{begin.ToString("yyyy-MM-dd")}T00:00:00.000Z/{end.ToString("yyyy-MM-dd")}T23:59:59.999Z",
                    Order    = ConversationQuery.OrderEnum.Asc,
                    OrderBy  = ConversationQuery.OrderByEnum.Conversationstart,
                    Paging   = new PagingSpec()
                    {
                        PageSize   = _pageSize,
                        PageNumber = pageNumber
                    }
                };

                HttpResponseMessage responseMessage = await hc.PostAsync(_uribase + "/api/v2/analytics/conversations/details/query",
                                                                         new StringContent(queryParam.ToJson(), Encoding.UTF8, "application/json"));

                int tentatives = 0;
                do
                {
                    string jsonMessage = await responseMessage.Content.ReadAsStringAsync();

                    if (responseMessage.IsSuccessStatusCode)
                    {
                        response = JsonConvert.DeserializeObject <AnalyticsConversationQueryResponse>(jsonMessage);
                        if (response.Conversations != null)
                        {
                            result = response.Conversations;
                        }
                    }
                    else if (responseMessage.StatusCode == HttpStatusCode.TooManyRequests)
                    {
                        await DelayTime(responseMessage);
                    }
                    else if ((int)responseMessage.StatusCode >= 300 && (int)responseMessage.StatusCode < 600)
                    {
                        throw new Exception(jsonMessage);
                    }

                    tentatives++;
                } while (!responseMessage.IsSuccessStatusCode && tentatives < 3);
            }

            return(result);
        }
        static void Main(string[] args)
        {
            // OAuth input
            Console.Write("Enter Client ID: ");
            string clientId = Console.ReadLine();

            Console.Write("Enter Client Secret: ");
            string clientSecret = Console.ReadLine();

            // Get the Date Interval
            Console.Write("Enter Date Interval (YYYY-MM-DDThh:mm:ss/YYYY-MM-DDThh:mm:ss): ");
            string interval = Console.ReadLine();

            Console.WriteLine("Working...");

            // Configure SDK Settings
            string accessToken = GetToken(clientId, clientSecret);

            PureCloudPlatform.Client.V2.Client.Configuration.Default.AccessToken = accessToken;

            // Instantiate APIs
            ConversationsApi conversationsApi = new ConversationsApi();

            // Create folder that will store all the downloaded recordings
            string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            path = path.Substring(0, path.LastIndexOf("bin"));
            System.IO.Directory.CreateDirectory(path + "\\Recordings");

            // Call conversation API, pass date inputted to extract conversationIds needed
            AnalyticsConversationQueryResponse conversationDetails = conversationsApi.PostAnalyticsConversationsDetailsQuery(new ConversationQuery(Interval: interval));

            // Pass conversation details to function
            extractConversationDetails(conversationDetails);

            // Final Output
            Console.WriteLine("DONE");

            if (Debugger.IsAttached)
            {
                Console.ReadKey();
            }
        }
Example #6
0
        private List <AnalyticsConversation> GetActiveConversations()
        {
            AddLog("Getting active conversations...", true);
            var conversations = new List <AnalyticsConversation>();
            var pageNumber    = 1;
            AnalyticsConversationQueryResponse analyticsConversationQueryResponse = null;

            var dateTimeNowISO          = DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ");
            var dateTimeNowISOMinus1Day = DateTime.UtcNow.AddDays(-1).ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ");

            AddLog($"Start Date/Time: {dateTimeNowISOMinus1Day}", true);
            AddLog($"End Date/Time: {dateTimeNowISO}", true);

            do
            {
                var body = new ConversationQuery()
                {
                    Interval            = $"{dateTimeNowISOMinus1Day}/{dateTimeNowISO}",
                    ConversationFilters = new List <AnalyticsQueryFilter>()
                    {
                        new AnalyticsQueryFilter(
                            AnalyticsQueryFilter.TypeEnum.And,
                            new List <AnalyticsQueryClause>()
                        {
                            new AnalyticsQueryClause()
                            {
                                // Should not be disconnected
                                Type       = AnalyticsQueryClause.TypeEnum.And,
                                Predicates = new List <AnalyticsQueryPredicate>()
                                {
                                    new AnalyticsQueryPredicate()
                                    {
                                        Type      = AnalyticsQueryPredicate.TypeEnum.Dimension,
                                        Dimension = AnalyticsQueryPredicate.DimensionEnum.Conversationend,
                                        _Operator = AnalyticsQueryPredicate.OperatorEnum.Notexists
                                    }
                                }
                            }
                        }
                            )
                    },
                    SegmentFilters = new List <AnalyticsQueryFilter>()
                    {
                        new AnalyticsQueryFilter(
                            AnalyticsQueryFilter.TypeEnum.And,
                            new List <AnalyticsQueryClause>()
                        {
                            new AnalyticsQueryClause()
                            {
                                Type       = AnalyticsQueryClause.TypeEnum.And,
                                Predicates = new List <AnalyticsQueryPredicate>()
                                {
                                    // Should be a call
                                    new AnalyticsQueryPredicate()
                                    {
                                        Type      = AnalyticsQueryPredicate.TypeEnum.Dimension,
                                        Dimension = AnalyticsQueryPredicate.DimensionEnum.Mediatype,
                                        _Operator = AnalyticsQueryPredicate.OperatorEnum.Matches,
                                        Value     = "voice"
                                    },
                                    // Should match selected edge
                                    new AnalyticsQueryPredicate()
                                    {
                                        Type      = AnalyticsQueryPredicate.TypeEnum.Dimension,
                                        Dimension = AnalyticsQueryPredicate.DimensionEnum.Edgeid,
                                        _Operator = AnalyticsQueryPredicate.OperatorEnum.Matches,
                                        Value     = currentEdge.Id
                                    }
                                }
                            }
                        }
                            )
                    },
                    Order   = ConversationQuery.OrderEnum.Asc,
                    OrderBy = ConversationQuery.OrderByEnum.Conversationstart,
                    Paging  = new PagingSpec()
                    {
                        PageSize   = 100,
                        PageNumber = pageNumber++
                    }
                };

                analyticsConversationQueryResponse = analyticsApi.PostAnalyticsConversationsDetailsQuery(body);
                AddLog($"Got response: {analyticsConversationQueryResponse.ToString()}", true);

                if (analyticsConversationQueryResponse.Conversations != null)
                {
                    AddLog($"Got {analyticsConversationQueryResponse.Conversations.Count} conversations", true);
                    foreach (var analyticsConversation in analyticsConversationQueryResponse.Conversations)
                    {
                        conversations.Add(analyticsConversation);
                    }
                }
            } while (analyticsConversationQueryResponse.Conversations != null);

            return(conversations);
        }
 public void Init()
 {
     instance = new AnalyticsConversationQueryResponse();
 }