HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/integrations/__pycache__/push_engage.cpython-310.pyc
o

we�@s,ddlZddlZe�e�ZGdd�d�ZdS)�Nc@sReZdZdZdZdZdZdZgd�Zgd�Z	dd�Z
dd	d
�Zdd�Zd
d�Z
dS)�
PushEngageAPIz7
    Send Push Notifications using PushEngage API.
    ��N)�notification_url�notification_title�notification_message�	image_url�include_segments�exclude_segments�include_countries�exclude_countries�include_states�include_cities�include_device_types�include_browsers�	from_date�to_date�notification_expiry�notification_type�subscriber_hash�
big_image_url�valid_from_utc)�MISSED_CALL�
VOICE_MAIL�TEXT_MESSAGE�FORM_SUBMISSION�PASSWORD_CHANGEcCs$|j�dd�|_|j�dd�|_dS)z�
        Set the endpoint and api key for the push engage api request. 
        :param app: flask app
        :return None: None
        �PUSHENGAGE_ENDPOINTz.https://api.pushengage.com/apiv1/notifications�PUSHENGAGE_API_KEYz$871e2367-0809-4b22-8dd2-32475e4580f3N)�config�get�endpoint�api_key)�self�app�r%�D/home/arjun/projects/buyercall/buyercall/integrations/push_engage.py�init_appszPushEngageAPI.init_appc
Cs|z$d}tj|j|||d�}|rd}|d8}|s"|dkr"|�|||�|WSty=}z
t�|��WYd}~dSd}~ww)NF)�url�data�headers�timeoutT�r)�requests�postr!�send_request�	Exception�log�error)r#r)r*�retriesr+�success�response�er%r%r&r/*s��zPushEngageAPI.send_requestcs�d}|�dd�}|�dd�}|�dd�}|�dd�}|rQ|rQ|rQ|rQ�jdd�}�fdd	�|��D�}t|�D]\}	}
t|
�|d
|	�d�<q7�j||�j�jd�}|rW|��Sd
dd�S)al
        Send push notification
        :param notification_url: Hyperlink for notification
        :param notification_title: Title for notification
        :param notification_message: Message dispalyed in notification body
        :param profile_ids: User(s) who need to receive notifications
        :return: json {'message': 'string', 'status': bool}
        Nrrr�profile_idsz!application/x-www-form-urlencoded)r"zContent-Typecs i|]\}}|�jvr||�qSr%)�pushengage_api_params)�.0�k�v�r#r%r&�
<dictcomp>Ns z8PushEngageAPI.send_push_notification.<locals>.<dictcomp>zprofile_id[�])r3r+FzkBad Request. Required Parameters: notification_url, notification_title, notification_message and profile_id)�status�message)	r r"�items�	enumerate�strr/�request_retries�request_timeout�json)r#�kwargsr5rrrr7r*r)�i�pidr%r<r&�send_push_notification<s	�z$PushEngageAPI.send_push_notificationcKsdS)a�
        schedule push notification
        :param notification_url: URL to open upon clicking on the push notification.
        :param notification_title: Title of the push notification.
        :param notification_message: The message to be displayed in the push notification.
        :param notification_type: This defines the notification status, such as now, later or, draft. In this case, notification_type has always been "later".
        :param valid_from_utc: This defines sent time of schedule notification. it is based on timezone of the configured account. This is valid only notification_type is later.
        :return: json {'message': 'string', 'status': bool}
        Nr%)r#rGr%r%r&�schedule_push_notificationZs
z(PushEngageAPI.schedule_push_notification)r)�__name__�
__module__�__qualname__�__doc__rErDr!r"r8�push_notification_event_typesr'r/rJrKr%r%r%r&rs
r)r-�loggingr1�	getLoggerrLrr%r%r%r&�<module>s