Contents

Ring Central - Sending an MMS With Node.JS

Contents

I previously showed you how to create and send an SMS using Ring Centraland Node.JS, but in this post I want to show you how to send an MMS. It’s pretty similar to the previous example, but there are a few differences that I wanted to point out.

Note: There is a combined limit of 1.5M bytes for all attachments and a limit of 10 attachments for any request.
The full process is well documented on their developer portal. The first step is to pull in the modules and create an instance of the SDK object and platform:

const SDK = require('ringcentral')
const FormData = require('form-data')
const rcsdk = new SDK({
  server: "server_url", appKey: "client_id", appSecret: "client_secret"
})
const platform = rcsdk.platform()

Next, login to the platform (using your own credentials):

platform.login({
  username: "username", extension: "extension_number", password: "password"
}).then(response => {
  
}).catch(e => {
  console.error(e)
})

Now in the login callback, create the MMS body, construct a new FormData object that includes the file that you want to post to the MMS recipient and post the form!

const body = {
    from: { phoneNumber: "username" },
    to: [ { phoneNumber: "recipient_number" } ],
    text: 'Hello world'
}
const formData = new FormData()
file = {filename: 'request.json', contentType: 'application/json'};
formData.append('json',
              Buffer.from(JSON.stringify(body)),
              {filename: 'request.json', contentType: 'application/json'})
formData.append('attachment',
              require('fs').createReadStream('./test.jpg'))
platform.post('/account/~/extension/~/sms', formData)
    .then(response => {
        console.log('MMS sent: ' + response.json().id)
    })
    .catch(e => {
        console.error(e)
    })

And that’s all it takes to send an MMS with Java and Ring Central!

Image by cocoparisienne from Pixabay