Skip to main content

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

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

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