Integrate Webhooks for User Engagement
Webhooks are specially designed integrations that allow the Zendrive IQL platform to communicate events and data directly to your backend system in real-time. This is an efficient mechanism that helps keep your application's data in sync with Zendrive’s IQL data. Upon capturing significant events or reaching specific milestones (like the completion of a trip), the IQL platform triggers these webhooks.
By listening to these webhooks, developers can effectively engage users through various communication channels, such as sending push notifications, SMS, or emails, and perform other tailored actions based on the data received. This system ensures timely and relevant engagement, enhancing user experience and promoting continued interaction with the application.
First Trip Completion Notification
Enable Zendrive Webhooks
This section describes how to enable Engagement Webhook
with the IQL platform, and includes the following topics:
Create Endpoint of Engagement
Create a new endpoint in your backend that will be configured as an engagement webhook with Zendrive’s IQL platform. The IQL platform will call this endpoint to allow you to engage with your users via SMS, email, push notifications and so on.
In this section, you will learn how to create an engagement endpoint for push notifications.
@api_view(['POST'])
def engagement_webhook(request):
try:
authenticate(None, request)
driver_id = request.data['driver_id']
driver = User.objects.get(driver_id=driver_id)
push_payload = EngagementService.get_push_payload(request.data)
if push_payload:
push_service = PushService()
push_service.send_push(
driver=driver,
message=push_payload["message"],
extra=push_payload["extra"])
return Response(status=status.HTTP_200_OK)
except User.DoesNotExist:
logger.error("Engagement web-hook was sent for a non-existent user" +
driver_id)
return Response(status=status.HTTP_400_BAD_REQUEST)
except EngagementService.Error as e:
logger.exception(e)
return Response(status=status.HTTP_200_OK)
except PushService.Error as e:
logger.exception(e)
return Response(status=status.HTTP_200_OK)pyth
Integrate Push Notifications
You can integrate a push notification service such as Firebase
, OneSignal
, Iterable
, and so on. Alternatively you can implement a push notification service on your own that can interface with Apple Push Notification Service (APNs) and Firebase Cloud Messaging (FCM). The reference implementation uses the django push notifications package to send push notifications to mobile applications.
For iOS, you will need to create a PEM or P12 file or a P8 key for sending push notifications.
For Android, you will need to create the FCM server key for your application using the
Firebase
console. Configure it with your own implementation or with the external push service to enable the sending of push notifications to your users.
Configure Engagement Webhook
Contact Zendrive to configure your engagement endpoint with Zendrive's IQL platform. The same engagement webhook will be called for all types of engagement triggers. You will need to share the configuration detailed in the following table to help Zendrive set up the webhooks as per your requirement.
Activity-based Engagement Webhook Configuration
Inactivity
inactivity_days
3
interval_in_days
1
number_of_times
3
No-click
days_list
[2, 3, 5, 7, 14, 30, 60, 90, 120, 150]
Milestone-based Engagement Webhook Configuration
Opt-In days
days_list
[3,6,15,22,29]
Trip-based
trip_count
1
Below is an example of how to listen for a webhook and send a notification to users upon the completion of their first trip milestone.
First Trip Completion Notification
This webhook is sent for users who just took their first trip. You can identify type of notification by passing the metadata field to the can_handle_webhook
method mentioned in the following code snippet:
class FirstTripWebhookHandler(AbstractEngagementWebhookHandler):
def __init__(self, data):
if not self.can_handle_webhook(data):
raise EngagementService.IncorrectHandlerError()
super().__init__(data)
@staticmethod
def can_handle_webhook(data):
type = data["type"]
subtype = data["subtype"]
return type == 'milestone_based' and subtype == 'trip-1'
def get_push_payload(self):
push_payload = super().get_push_payload()
push_payload["message"] = {
"title":
"Congratulations on your 1st trip",
"body":
"Continue driving to increase your chances of being qualified for an offer."
}
return push_payload
Refer here for all types of webhooks available.