Skip to main content
Question

Set a custom user greeting using RingCentral SDK in Node.js


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;
}

2 replies

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • 2313 replies
  • July 13, 2022

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)
  }
}

  • Author
  • Participating Frequently
  • 5 replies
  • July 13, 2022

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings