This project is a proxy project to the WebSocket Extension of the RingCentral Extensible project.
For new users, you are recommended to use this project directly.
Please do read this article: Create WebSocket subscriptions using RingCentral JavaScript SDKs.
Your RingCentral app needs to have the "WebSocket Subscriptions" permission. If you don't know how to enabled it, please contact dev support.
yarn add @ringcentral/sdk @ringcentral/subscriptions
import {SDK} from '@ringcentral/sdk';
import {Subscriptions} from '@ringcentral/subscriptions';
// init
const sdk = new SDK({
server: process.env.RINGCENTRAL_SERVER_URL,
clientId: process.env.RINGCENTRAL_CLIENT_ID,
clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
});
const platform = sdk.platform();
const subscriptions = new Subscriptions({
sdk: sdk,
});
const main = async () => {
// login
await platform.login({
username: process.env.RINGCENTRAL_USERNAME,
extension: process.env.RINGCENTRAL_EXTENSION,
password: process.env.RINGCENTRAL_PASSWORD,
});
// subscribe
const subscription = subscriptions.createSubscription();
subscription.on(subscription.events.notification, evt => {
console.log(JSON.stringify(evt, null, 2));
});
await subscription
.setEventFilters(['/restapi/v1.0/account/~/extension/~/message-store'])
.register();
// trigger events
const r = await platform.get('/restapi/v1.0/account/~/extension/~');
const ext = await r.json();
platform.post('/restapi/v1.0/account/~/extension/~/company-pager', {
from: {extensionId: ext.id},
to: [{extensionId: ext.id}],
text: 'Hello world!',
});
};
main();
Let's say you just want to use plain HTML and JavaScript without any fancy technology such as webpack/parcel/TypeScript...etc.
Please refer to the RingCentral SPA Demo.
Simply put:
<script type="text/javascript" src="https://unpkg.com/@ringcentral/sdk@latest/dist/ringcentral.js"></script>
<script type="text/javascript" src="https://unpkg.com/@ringcentral/[email protected]/dist/ringcentral-subscriptions.js"></script>
...
const rc = new RingCentral.SDK({
server,
clientId,
});
...
const subscriptions = new RingCentral.Subscriptions({
sdk: rc
});
const subscription = subscriptions.createSubscription();
...
@ringcentral/[email protected]
was the latest nightly build when I was writing this documentation.
Please choose a proper version yourself.