/Users/alexpower/Code/Projects/teleingest/node_modules/@rc-ex/ws/lib/subscription.js:22
this.wse.ws.addEventListener('message', this.eventListener);
^
TypeError: Cannot read properties of undefined (reading 'addEventListener')
at Subscription.setupWsEventListener (/Users/alexpower/Code/Projects/teleingest/node_modules/@rc-ex/ws/lib/subscription.js:22:21)
at new Subscription (/Users/alexpower/Code/Projects/teleingest/node_modules/@rc-ex/ws/lib/subscription.js:19:14)
at WebSocketExtension.subscribe (/Users/alexpower/Code/Projects/teleingest/node_modules/@rc-ex/ws/lib/index.js:315:30)
at Subscription.<anonymous> (/Users/alexpower/Code/Projects/teleingest/node_modules/@ringcentral/subscriptions/lib/Subscriptions.js:89:58)
at step (/Users/alexpower/Code/Projects/teleingest/node_modules/@ringcentral/subscriptions/lib/Subscriptions.js:48:23)
at Object.next (/Users/alexpower/Code/Projects/teleingest/node_modules/@ringcentral/subscriptions/lib/Subscriptions.js:29:53)
at fulfilled (/Users/alexpower/Code/Projects/teleingest/node_modules/@ringcentral/subscriptions/lib/Subscriptions.js:20:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
const sendMessage = require("./src/sendMessage");
const { SDK } = require("@ringcentral/sdk");
const { Subscriptions } = require("@ringcentral/subscriptions");
const logger = require('pino')(
{
messageKey: "message",
formatters: {
level: (label) => {
return { level: label };
},
}
}
);
const sdk = new SDK({
server: process.env.RC_ENV !== "production" ? SDK.server.sandbox : SDK.server.production,
clientId: process.env.RC_CLIENT,
clientSecret: process.env.RC_SECRET
});
const platform = sdk.platform();
const subscriptions = new Subscriptions({
sdk: sdk,
});
const main = async () => {
// login
await platform.login({
jwt: process.env.RC_JWT,
});
// 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/~/telephony/sessions']).register();
// trigger events
subscription
.register()
.then(() => logger.info("Subscribed to events."))
.catch((err) => {
logger.error({ err }, err.message)
});
};
main();