News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Downloading MMS Attachments from incoming messages
Tags: sdk, rest api
Oct 20, 2023 at 11:30am   •   1 replies  •  0 likes
Joseph Spataro

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.

1 Answer
answered on Oct 20, 2023 at 1:05pm  

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.


 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us