Create your Auth0 RingCentral App credentials
Create a new private RingCentral app for your Auth0 MFA integration to get your client ID, secret, and JWT access.
const RingCentral = require('@ringcentral/sdk').SDK;
exports.onExecuteSendPhoneMessage = async (event, api) => {
// Setup Connection
var e = event;
var rcsdk = new RingCentral({
'server': e.secrets.RINGCENTRAL_SERVER,
'clientId': e.secrets.RINGCENTRAL_CLIENT_ID,
'clientSecret': e.secrets.RINGCENTRAL_CLIENT_SECRET,
});
// Setup User Auth
var platform = rcsdk.platform();
platform.login({
'jwt': e.secrets.RINGCENTRAL_JWT
});
// Send MFA upon login success
platform.on(platform.events.loginSuccess, function(err){
async function send_sms() {
try {
// Clean numbers (to make sure proper format)
var cleanToNumber = e.message_options.recipient.replace(/[^+0-9]/, '');
if (cleanToNumber.substring(0,1) != '+') { cleanToNumber = '+'+cleanToNumber; }
var cleanFromNumber = e.secrets.RINGCENTRAL_FROM_NUMBER.replace(/[^+0-9]/, '');
if (cleanFromNumber.substring(0,1) != '+') { cleanToNumber = '+'+cleanToNumber; }
// Send SMS
var resp = await platform.post('/restapi/v1.0/account/~/extension/~/sms', {
from: {'phoneNumber': cleanFromNumber},
to: [{'phoneNumber': cleanToNumber}],
text: e.message_options.text
})
return cb(null, {});
} catch (err) {
return cb(new Error(err.message));
}
}
send_sms();
});
}