Enable Zendrive Webhooks
This section describes how to enable Engagement Webhook with the IQL platform, and includes the following topics:
1.0. 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)
2.0. Integrate APNs and FCM
Integrate your backend with a push notification service such as Firebase, OneSignal and so on. Alternatively you can implement a push notification service on your own using a library 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.
3.0. 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