Skip to content

Push Notifications

Push Notifications provide a way to deliver some information to users while they are not using your app actively. The following use cases can be covered additionally with push notifications:

  • send a chat message when a recipient is offline (a push notification will be initiated automatically in this case)
  • make a video call with offline opponents (need to send a push notification manually)

Configuration

In order to start work with push notifications you need to configure it.

For iOS application that uses Apple Push Notifications you must have APNS certificate uploaded via the ConnectyCube Dashboard Console panel.

For Android application that uses Firebase Cloud Messaging (FCM) you need to obtain API Key and set it on ConnectyCube Dashboard Console panel.

Subscribe

In order to start receiving push notifications you need to subscribe your current device as follows:

const params = {
notification_channels: "apns", // or 'gcm' for Android
device: {
platform: "ios",
udid: "2b6f0cc904d137be2e1730235f5664094b831186",
},
push_token: {
environment: "development",
client_identification_sequence: "2b6f0cc9...4b831186",
},
};
ConnectyCube.pushnotifications.subscriptions
.create(params)
.then((result) => {})
.catch((error) => {});

Response example from ConnectyCube.pushnotifications.subscriptions.create(params) - see

Send push notifications

You can manually initiate a push notification to user/users on any event in your application. To do so you need to form a push notification parameters (payload) and set the push recipients:

const payload = JSON.stringify({
message: "Alice is calling you",
ios_badge: 1,
// ios_voip: 1
});
const pushParameters = {
notification_type: "push",
user: { ids: [21, 12] }, // recipients.
environment: "development", // environment, can be 'production'.
message: ConnectyCube.pushnotifications.base64Encode(payload),
};
ConnectyCube.pushnotifications.events
.create(pushParameters)
.then((result) => {})
.catch((error) => {});

Response example from ConnectyCube.pushnotifications.events.create(pushParameters) - see

Receive push notifications

The flow how you receive push notifications depends on what platform you use: NativeScript, React Native or something else. Please refer to the push notifications documentation of these platforms.

Unsubscribe

In order to unsubscribe and stop receiving push notifications you need to list your current subscriptions and then choose those to be deleted:

const deleteSubscription = (subscriptions) => {
const subscriptionId = subscriptions[0].subscription.id;
return ConnectyCube.pushnotifications.subscriptions.delete(subscriptionId);
};
ConnectyCube.pushnotifications.subscriptions
.list()
.then(deleteSubscription)
.catch((error) => {});

Response example from ConnectyCube.pushnotifications.subscriptions.list() - see

VoIP push notifications

ConnectyCube supports iOS VoIP push notifications via same API described above:

  • for VoIP pushes it requires to generate a separated VoIP device token.
  • then when token is retrieved, you need to subscribe to voip pushes by passing a notification_channel: apns_voip channel in a subscription request
  • then when you want to send a voip push notification, use ios_voip: 1 parameter in a push payload in a create event request.