question

Adam Burgess avatar image
Adam Burgess asked Phong Vu commented

Message Store Export C# Index does not contain definition for List

I am trying to test out the Message Store Export (kinda new at this) and am running into some errors. I am using the code from the documentation here. I already replaced the depreciated WebClient with HTTP but am still getting this error:

Error CS1061 'Index' does not contain a definition for 'List' and no accessible extension method 'List' accepting a first argument of type 'Index' could be found (are you missing a using directive or an assembly reference?)

I do have the RingCentral SDK installed. Any help would be appreciated!

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using RingCentral;

namespace Export_MessageStore
{
    class Program
    {
        static RestClient restClient;
        static HttpClient httpClient = new HttpClient();

        static async Task Main(string[] args)
        {
            try
            {
                // Instantiate the SDK
                restClient = new RestClient("SANDBOX-APP-CLIENTID", "SANDBOX-APP-CLIENTSECRET", "https://platform.devtest.ringcentral.com");
                // Authenticate a user using a personal JWT token
                await restClient.Authorize("SANDBOX_JWT");

                await CreateMessageStoreReport();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        static private async Task CreateMessageStoreReport()
        {
            var bodyParams = new CreateMessageStoreReportRequest
            {
                dateFrom = "2023-03-01T00:00:00.000Z",
                dateTo = "2023-03-31T23:59:59.999Z"
            };

            var response = await restClient.Restapi().Account().MessageStoreReport().Post(bodyParams);
            await GetMessageStoreReportTask(response.id);
        }

        static private async Task GetMessageStoreReportTask(string taskId)
        {
            bool isCompleted = false;
            while (!isCompleted)
            {
                var response = await restClient.Restapi().Account().MessageStoreReport(taskId).Get();
                Console.WriteLine("Task creation status: " + response.status);
                switch (response.status)
                {
                    case "Completed":
                        isCompleted = true;
                        await GetMessageStoreReportArchive(taskId);
                        break;
                    case "AttemptFailed":
                    case "Failed":
                    case "Cancelled":
                        Console.WriteLine("Export message store failed.");
                        return;
                    default:
                        await Task.Delay(10000); // Use non-blocking delay
                        break;
                }
            }
        }

        static private async Task GetMessageStoreReportArchive(string taskId)
        {
            Console.WriteLine("Getting report uri ...");
            var resp = await restClient.Restapi().Account().MessageStoreReport(taskId).Archive().List();
            var dateStr = DateTime.Now.ToString("yyyy-MM-dd-HH_mm");
            for (var i = 0; i < resp.records.Length; i++)
            {
                var fileName = $"message_store_content_{dateStr}_{i}.zip";
                var contentUrl = $"{resp.records[i].uri}?access_token={restClient.token.access_token}";

                // Use HttpClient for downloading the file
                var response = await httpClient.GetAsync(contentUrl);
                if (response.IsSuccessStatusCode)
                {
                    using (var stream = await response.Content.ReadAsStreamAsync())
                    using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                    {
                        await stream.CopyToAsync(fileStream);
                    }
                    Console.WriteLine($"{fileName} file is saved to the local machine.");
                }
                else
                {
                    Console.WriteLine($"Failed to download file: {fileName}");
                }
            }
        }
    }
}
rest apisms and text messagingsdkdeveloper sandboxmessage
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Phong Vu avatar image
Phong Vu answered Phong Vu commented

There was a change and it causes the mistake in the sample code. Please modify the code in this function. Change List() to Get().

static private async Task get_message_store_report_archive(String taskId)
{
    Console.WriteLine("Getting report uri ...");
    var resp = await restClient.Restapi().Account().MessageStoreReport(taskId).Archive().Get();
    DateTime value = DateTime.Now;
    ...
}

I will update the sample code soon.

5 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Adam Burgess avatar image Adam Burgess commented ·

For some reason when I filter to SMS, I get nothing. I can Read_MessageStore and filter it to SMS and that come out okay. When I filter this line of code (with your awesome fix), nothing comes up when it is outputted. Is filtering not able to be used when exporting?

        static private async Task CreateMessageStoreReport()
        {
            var bodyParams = new CreateMessageStoreReportRequest
            {
                dateFrom = "2024-03-01T12:00:00.000Z",
                dateTo = "2024-03-01T13:00:00.000Z",
                messageTypes = new[] {"SMS"}
            };

            var response = await restClient.Restapi().Account().MessageStoreReport().Post(bodyParams);
            await GetMessageStoreReportTask(response.id);
        }

        static private async Task GetMessageStoreReportTask(string taskId)
        {
            bool isCompleted = false;
            while (!isCompleted)
            {
                var response = await restClient.Restapi().Account().MessageStoreReport(taskId).Get();
                Console.WriteLine("Task creation status: " + response.status);
                switch (response.status)
                {
                    case "Completed":
                        isCompleted = true;
                        await GetMessageStoreReportArchive(taskId);
                        break;
                    case "AttemptFailed":
                    case "Failed":
                    case "Cancelled":
                        Console.WriteLine("Export message store failed.");
                        return;
                    default:
                        await Task.Delay(10000); // Use non-blocking delay
                        break;
                }
            }
        }

        static private async Task GetMessageStoreReportArchive(string taskId)
        {
            Console.WriteLine("Getting report uri ...");
            var resp = await restClient.Restapi().Account().MessageStoreReport(taskId).Archive().Get();
            var dateStr = DateTime.Now.ToString("yyyy-MM-dd-HH_mm");
            for (var i = 0; i < resp.records.Length; i++)
            {
                var fileName = $"message_store_content_{dateStr}_{i}.zip";
                var contentUrl = $"{resp.records[i].uri}?access_token={restClient.token.access_token}"
0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Adam Burgess commented ·

It should work and it worked for me. I am not sure about your message store and if there is any SMS sent/received between that period of time. And BTW, which zip file did you check? The 0.zip should be the one that contain the SMS message, the x.zip file(s) are for attachments (MMS, Fax, Voicemails etc.) if any.

0 Likes 0 ·
Adam Burgess avatar image Adam Burgess Phong Vu ♦♦ commented ·

I am really not sure what is going on. I am not getting anything even without filtering. I know my auth creds are right and the app has the MessageRead permission (unless it needs more?) I submitted a ticket to dev support, hopefully we can figure it out. I am only getting one Zip back and in that time range there were definitely faxes/vms/sms in that time range.

0 Likes 0 ·
Show more comments

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys