The Widget provides some API that allow developer to control it out of widget. It is based on postMessage API.
Find the widget iframe and use postMessage
to send command and data:
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-new-call',
phoneNumber: `phone number`,
toCall: true,
}, '*');
This feature can be used for Click to Dial
. If you set toCall
to ture, it will start the call immediately.
If you are using Adapter JS way, just you can just call RCAdapter.clickToCall('phonenumber')
.
Here is tutorial to use RingCentral C2D library to quick implement Click to Dial
feature.
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-new-sms',
phoneNumber: `phone number`,
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-new-sms',
phoneNumber: `phone number`,
conversation: true, // will go to conversation page if conversation existed
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-new-sms',
phoneNumber: `phone number`,
text: `your text`,
}, '*');
If you are using Adapter JS way, just you can just call RCAdapter.clickToSMS('phonenumber')
.
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-auto-populate-conversation',
text: `your text`,
}, '*');
Notice: This only works when user is on SMS conversation detail page. It will add your text
into user's conversation input.
Following APIs need to work with Web phone call event to get callId
.
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'answer',
callId: `call id`
}, '*');
// callId comes from web phone call event
// answer the current ringing call, call id default is current ringing call id.
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'answer',
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'reject',
callId: `call id`
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'toVoicemail',
callId: `call id`
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'forward',
callId: `call id`,
options: {
forwardNumber: 'forward_number'
}
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'hangup',
callId: `call id`
}, '*');
// hangup current active call
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'hangup',
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'hold',
callId: `call id`
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'unhold',
callId: `call id`
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'transfer',
callId: `call id`,
options: {
transferNumber: 'transfer_number'
}
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'startRecord',
callId: `call id`
}, '*');
Notice: this only works after call started (Inbound call accepted/Oubound call connected)
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'stopRecord',
callId: `call id`
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'mute',
callId: `call id`
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-control-call',
callAction: 'unmute',
callId: `call id`
}, '*');
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-logout'
}, '*');
App will open login popup window after getting this command. Follow here to disable popup window, and receive oauth uri.
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-login'
}, '*');
Notice: this command only works when user isn't logged.
Only for Adapter JS way:
Minimize:
RCAdapter.setMinimized(true);
// RCAdapter.setMinimized(false); // maximize
You can also disable
Minimize
feature by following here.
Hide:
RCAdapter.setClosed(true);
// RCAdapter.setClosed(false); // Show
Remove:
RCAdapter.dispose();
Only for Adapter JS way and popup window feature enabled:
RCAdapter.popupWindow(); // popup the widget in a standalone window
Navigate to path:
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-navigate-to',
path: '/messages', // '/meeting', '/dialer', '//history', '/settings'
}, '*');
// meeting info
const meetingBody = {
topic: "Embbnux Ji's Meeting",
meetingType: "Scheduled",
password: "",
schedule: {
startTime: 1583312400368,
durationInMinutes: 60,
timeZone: {
id: "1"
}
},
allowJoinBeforeHost: false,
startHostVideo: false,
startParticipantsVideo: false,
audioOptions: [
"Phone",
"ComputerAudio"
]
};
// send a request to schedule meeting
const requestId = Date.now().toString();
document.querySelector("#rc-widget-adapter-frame").contentWindow.postMessage({
type: 'rc-adapter-message-request',
requestId: requestId,
path: '/schedule-meeting',
body: meetingBody,
}, '*');
// listen response
window.addEventListener('message', function (e) {
var data = e.data;
if (data && data.type === 'rc-adapter-message-response') {
if (data.responseId === requestId) {
console.log(data.response);
}
}
});