Push Notifications API for PubNub Python-Twisted SDK

Deprecated

NOTICE: Based on current web trends and our own usage data, PubNub's Python Twisted SDK is deprecated as of May 1, 2019. Deprecation means we will no longer be updating the Python Twisted SDK but will continue to support users currently using it. Please feel free to use our other Python SDK offerings as they will continue to be supported and maintained. If you would like to use the Python Twisted SDK specifically, we would love to work with you on keeping this project alive!

PubNub's Mobile Push Gateway feature enables developers to bridge native PubNub publishing with 3rd-party push notification services including Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

By using the Mobile Push Gateway, developers can eliminate the need for developing, configuring, and maintaining additional server-side components for third-party push notification providers.

To learn more, read about Push Notifications.

Adding Device to Channel

Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Description

Enable push notifications on provided set of channels.

Method(s)

To run Adding Device to Channel you can use the following method(s) in the Python-Twisted SDK:

pubnub.add_channels_to_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
ParameterTypeRequiredDefaultDescription
push_typePNPushTypeYesn/aThe available push types. Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS, PNPushType.APNS2
channelsListYesn/aThe channels to add the push notifications to.
device_idStringYesn/aThe device ID (token) to associate with the push notifications.
topicStringRequired for PNPushType.APNS2n/aThe topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type is set to PNPushType.APNS2.
environmentStringRequired for PNPushType.APNS2PNPushEnvironment.DEVELOPMENTThe environment where the device should manage the list of channels with enabled notifications. Required only if push_type is set to PNPushType.APNS2.

Basic Usage

Adding Device to Channel

from pubnub.enums import PNPushType

d = pubnub.add_channels_to_push()\
.push_type(PNPushType.GCM)\
.channels(["ch1", "ch2", "ch3"])\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)

Returns

The add_channels_to_push() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.is_error()

Listing Channels For Device

Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Description

Request for all channels on which push notification has been enabled using specified pushToken.

Method(s)

To run Listing Channels For Device you can use the following method(s) in the Python-Twisted SDK:

pubnub.list_push_channels().push_type(PNPushType).device_id(String).topic(String).environment(PNPushEnvironment)
ParameterTypeRequiredDefaultDescription
push_typePNPushTypeYesn/aThe available push types. Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS, PNPushType.APNS2
device_idStringYesn/aThe device ID (token) to associate with the push notifications.
topicStringRequired for PNPushType.APNS2n/aThe topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type is set to PNPushType.APNS2.
environmentStringRequired for PNPushType.APNS2PNPushEnvironment.DEVELOPMENTThe environment where the device should manage the list of channels with enabled notifications. Required only if push_type is set to PNPushType.APNS2.

Basic Usage

Listing Channels For Device

from pubnub.enums import PNPushType

d = pubnub.list_push_channels()\
.push_type(PNPushType.GCM)\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)

Returns

The list_push_channels() operation returns a PNPushListProvisionsResult which contains the following fields:

MethodTypeDescription
ChannelsListList of channels associated for push notifications.

Removing Device From Channel

Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Description

Disable push notifications on provided set of channels. If nil will be passed as channels then client will remove push notifications from all channels which associated with pushToken.

Method(s)

To run Removing Device From Channel you can use the following method(s) in the Python-Twisted SDK:

pubnub.remove_channels_from_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
ParameterTypeRequiredDefaultDescription
push_typePNPushTypeYesn/aThe available push types. Accepted values: PNPushType.GCM, PNPushType.FCM, PNPushType.APNS, PNPushType.APNS2
channelsListYesn/aThe channels to add the push notifications to.
device_idStringYesn/aThe device ID (token) to associate with the push notifications.
topicStringRequired for PNPushType.APNS2n/aThe topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type is set to PNPushType.APNS2.
environmentStringRequired for PNPushType.APNS2PNPushEnvironment.DEVELOPMENTThe environment where the device should manage the list of channels with enabled notifications. Required only if push_type is set to PNPushType.APNS2.

Basic Usage

Removing Device From Channel

from pubnub.enums import PNPushType

d = pubnub.remove_channels_from_push()\
.push_type(PNPushType.GCM)\
.channels("ch1", "ch2", "ch3")\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)

Returns

The remove_channels_from_push() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.is_error().