Push Notifications

A popular end user notification is the push notification. This will send a message to the end user’s phone as a pop-up associated with their banking application.

Accomplishing this requires the end user to opt in to receive push notifications.

Note

An end user may have registered their device through a different process. If this is the case, it is still best to re-register the device for your use case. Only the device registered specifically for your workflow should be used. It is important to have the end user re-register their device for this specific workflow. This will prevent the end user from feeling spammed by notifications and encourage a higher response rate.

The Tecton function enrollPush is used to enroll and identify a device for future use.

Tecton enrollPush documentation

Once the device is registered, it can be fetched from the database using the PushNotificationTargets DbObject.

Finally, the notification can be sent, either externally through the Caliper API, or an SDK extension via the SendNotification HQ method. Below is an example of an SDK extension sending the push notification.

Note

Push notifications are currently not enabled in the sandbox environments. The code will run without error, but the notification will not be sent. This will resolve when the code is deployed to the Q2 data center.

from q2_sdk.hq.hq_api.q2_api import SendNotification5


async def default(self):
    target_nickname = "TestingPushNotifications"
    registered_devices = await self.db.push_notification_targets.get(self.online_user.user_id)
    target_device = None
    for device in registered_devices:
        if device.Nickname.text == target_nickname:
            target_device = device
            break
    else:
        self.logger.error("No registered device found")

    self.logger.info(f"Push Target ID found: {target_device.PushTargetID.text}")
    parameters = SendNotification5.ParamsObj(self.logger,
                                             "PUSH",  # notification_type
                                             target_device.GcmToken.text,  # target_address
                                             "Subject",  # message subject
                                             "Message Body",  # message body
                                             "USA",  # target_country_iso_code_a3
                                             None,  # notification_flavor
                                             self.online_user.user_id,  # target_user_id
                                             None,  # notification_time
                                             hq_credentials=self.hq_credentials)

    await SendNotification5.execute(parameters)
    return "Success"