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
Set a custom user greeting using RingCentral SDK in Node.js
Tags: rest api, custom greeting
Jul 13, 2022 at 12:41pm   •   1 replies  •  0 likes
Kamron Clark

I'm trying to set a custom user greeting using the RingCentral SDK but every method I try gives me the error "unsupported media type". It would be very helpful if someone could provide an example of how to generate a request for this endpoint using the RingCentral SDK in Node.js. My current code is attempting to use another Node.js package to read file contents.

platform.on(platform.events.loginSuccess, function(e){
    console.log("User logged in successfully");
    set_greeting(get_file());
});

async function set_greeting(binary) {
    console.log(binary);
    try {
      var resp = await platform.post('/restapi/v1.0/account/~/extension/~/greeting', {
        'type': 'Introductory',
        'binary': binary
      });
      

      var jsonObj = await resp.json();
      console.log('Greeting set successfully.');
      console.log(jsonObj);
    } catch (e) {
      console.log(e.message);
    }
  }

async function get_file()
    let binaryData = fs.readFileSync('C:/Users/user/Desktop/RingCentralApps/project/example.mp3', "binary");
    
    return binaryData;
}
1 Answer
answered on Jul 13, 2022 at 1:43pm  

Here you go for using the RingCentral JS SDK

async function create_greeting(){
  try{
    var FormData = require('form-data');
    formData = new FormData();
    var body = {
        type: "HoldMusic"
    }

    formData.append('json', new Buffer.from(JSON.stringify(body)), {
          filename: 'request.json',
          contentType: 'application/json'
          });

    formData.append('binary', require('fs').createReadStream('your-audio_file.mp3'));
    var resp = await platform.post('/restapi/v1.0/account/~/extension/~/greeting?apply=false', formData)
    var jsonObj = await resp.json()
    console.log(JSON.stringify(jsonObj))
  }catch(e){
    console.log(e.message)
  }
}

 0
on Jul 13, 2022 at 2:04pm   •  0 likes

Thank you! Do you know of a type of a type of user greeting that will play the media as soon as the users call is answered? I'm trying to use the RingOut endpoint and have the custom greeting play as soon as the call is accepted. I've tried Introductory and Announcement and neither of them worked as intended.

on Jul 13, 2022 at 2:21pm   •  0 likes

I don't think that is possible with current greeting settings. In that case, you may have to implement your own SIP phone and down play the audio to the line. You can read this series blogs to learn more how to build a SIP phone.

https://medium.com/ringcentral-developers/pjsip-and-ringcentral-part-1-get-started-67df16b10956

https://medium.com/ringcentral-developers/pjsip-and-ringcentral-part-2-handle-audio-medias-c26b8ea61319

https://medium.com/ringcentral-developers/pjsip-and-ringcentral-part-3-dtmf-30b9cab12599

on Jul 14, 2022 at 6:08am   •  0 likes

I think the custom greeting is giving me the behavior I desire at the moment. However, the create custom user greeting endpoint isn't overwriting the current greeting the user has. Is that the intended functionality, or is there something I'm missing? I'd like to use the endpoint to change the user's custom greeting to a new one.

on Jul 14, 2022 at 8:13am   •  0 likes

Simply change the path param 'apply=true'

/restapi/v1.0/account/~/extension/~/greeting?apply=true



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