End of Life announcement for PubNub push notifications
RingCentral will be discontinuing support of PubNub notifications on March 31, 2024 and is recommending the use of WebSockets as its replacement. PubNub is used for creating and sending push notifications to software “listeners.”
The PubNub way
The current way to use a push notification with RingCentral’s API and PubNub can be shown in the following PHP code sample. This will be similar when writing code within RingCentral’s other supported SDKs.
use RingCentral\SDK\Subscription\Events\NotificationEvent;
use RingCentral\SDK\Subscription\Subscription;
$sdk = new RingCentral\SDK\SDK($client_id, $client_secret, $server);
$sdk->platform()->login( [ "jwt" => $jwt_key ] );
$subscription = $sdk->createSubscription('Pubnub');
$subscription->addEvents(array('/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS'));
$subscription->addListener(Subscription::EVENT_NOTIFICATION, function (NotificationEvent $e) {
print_r($e->payload()['body']);
});
$subscription->setKeepPolling(true);
$subscription->register();
The first two lines of code after the ‘use’ statements create a connection to the API through the SDK using a JWT access key. Read about how to create a JWT access key here. The third line of code and following is creating a subscription connection to the API with ‘Pubnub’ as its type of connection. In this sample, the code is simply sending the notification that it receives out to the browser screen with the print_r function call.
The WebSockets approach
If you are using code similar to that shown in the section above then the change over to using WebSockets is dead-simple. You just have to change a few lines of code. Here is the new code. You can compare it with the old code listed above to see the changes. Most notable is the addition of the WebSocket ‘use’ line and the removal of the ‘Pubnub’ string in the createSubscription method call.
use RingCentral\SDK\WebSocket\WebSocket;
use RingCentral\SDK\Subscription\Events\NotificationEvent;
use RingCentral\SDK\Subscription\Subscription;
$sdk = new RingCentral\SDK\SDK($client_id, $client_secret, $server);
$sdk->platform()->login( [ “jwt” => $jwt_key ] );
$websocket = $sdk->initWebSocket();
$websocket->connect();
$subscription = $sdk->createSubscription();
$subscription->addEvents(array('/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS'));
$subscription->addListener(Subscription::EVENT_NOTIFICATION, function (NotificationEvent $e) {
print 'Notification ' . print_r($e->payload(), true) . PHP_EOL;
});
$subscription->register();
So, with changing as little as four lines of code you can make the move to WebSockets. One other small change that you have to make is in the RingCentral app that is making use of the API. In your developer environment be sure to edit the settings of the app and in the security section [1] add the “WebSocket Subscriptions” [2] option.
When you have fully tested out the migration remember to come back here and remove the “PubNub Subscriptions” option.
For more detail you can see the full discussion in the RingCentral Developers Guide here.