question

Joseph Spataro avatar image
Joseph Spataro asked Phong Vu answered

Downloading MMS Attachments from incoming messages

I have a project where we have a number that customers will send images too. I'm writing a program thats supposed to download those images and forward them to a company email. I have a webhook setup that works fine for incoming message events. I'm writing this all in java and need to figure out how to download the image from the message using either the URI or any other method. Thanks.

rest apisdk
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

I don't have the code for parsing and downloading attachments from the notification payload. But you can modify this code snippet to work with the notification payload.

public void read_message_store_sms() throws RestException, IOException{
        ListMessagesParameters parameters = new ListMessagesParameters();
        parameters.messageType = new String[] {"SMS"};
        parameters.dateFrom = "2023-05-01T00:00:00.222Z";
        
        var response = restClient.restapi().account().extension().messageStore().list(parameters);
        for (GetMessageInfoResponse record : response.records)
        {
            if (record.attachments != null)
            {
                for (var attachment : record.attachments)
                {
                    var fileName = "./src/test/resources/" + record.attachments[0].id + "_mms";
                    if (attachment.type.equals("MmsAttachment"))
                    {
                        if (attachment.contentType.equals("image/png"))
                            fileName += ".png";
                        else if (attachment.contentType.equals("image/jpeg"))
                            fileName += ".jpg";
                        else
                            fileName += ".xxx"; 
                    var res = restClient.restapi().account().extension().messageStore(record.id.toString()).content(attachment.id.toString()).get();
                    Path path = Paths.get(fileName);
                    Files.write(path, res);
                    }
                }
            }
        }
    }

All you need is to parse the payload, check the "attachments" then use the code above to download it.

Note: This code uses the RingCentral Java SDK.

1 |3000

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

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