U
    XHg(                     @   sJ   d dl mZmZ d dlmZmZ d dlmZmZ d dl	Z	G dd dZ
dS )    )db_model
app_logger)campaign_scheduler_utilsconfig_parser)EXOTEL_CALLS_PERMITTEDSERVER_TYPENc                   @   s   e Zd ZdddZdd ZdS )CallAttemptServiceFc                 C   s   t jt}|r|j dkrR|j}|j}d| d| dt d}t	
d| d S |j}|j}	t|dstjjj|j|j}
|
j}n|jj}|rtd |jd	d  }tj|j||||	|d
}| ||| |S )NFALSEz&Call scheduling failed for user phone z and campaign id z( due to disabled call scheduling in the z1 environment. Please enable it to schedule calls.zCall attempt service: %scontent_version   i)ignore_check)r   SystemConfigurationUtilparse_configr   valueupperphoneidr   r   warningmax_retry_flaghasattrr   r
   ContentVersionquery.get_content_version_by_content_and_language_id
content_idlanguage_idexotel_appidtimesleepprovider_numberr   	make_callupdate_campaign_response)self
experiencecampaignpre_calculated_campaign_dataZignore_out_of_window_checkZexotel_calls_allowed
user_phonecampaign_iderror_messager   r
   r   r   campaign_response r)   H/var/www/dostadmin/dostadmin/services/scheduling/call_attempt_service.pyattempt_call   sF    	

 
	  zCallAttemptService.attempt_callc                 C   sd  | d|_| drntd|j d| d | d|_| d|_| d|_| d	|_| d
|_nt	d|j d|j
 d|  | dtjjj}| d|_|tjjjkrtd|j d|j d tj|jtjjj d|_|jtjjjkr|j|_nR|jtjjjkr*|j|_n6|jtjjjkrF|j|_n|jtjjjkr`|j|_d S )Nattempted_timestampconnectz6Call Attempt Service: Got campaign response for phone z& after attempting the call. Response: .callsidcall_statuscall_start_time	to_numberZfrom_numberz@Call Attempt Service: Campaign response failed for phone number z and campaign_id z. The response details are: fail_statuszMarking experience id z as DND for user phone number F) getr,   r   infouser_numberr/   r0   r1   r   r   r   r   CampaignStatusFAILED_SYSTEMstatus
FAILED_DNDexperience_id
Experienceupdate_experience_statusDND_WAITis_eligible_to_callscheduled_byScheduledByCRON_REGULAR previous_regular_campaign_statusCRON_MISSED_CALL$previous_missed_call_campaign_status
CRON_NUDGEprevious_nudge_campaign_status	UI_MANUAL#previous_blast_call_campaign_status)r!   r(   r#   r$   r3   r)   r)   r*   r    ;   sP    
  z+CallAttemptService.update_campaign_responseN)F)__name__
__module____qualname__r+   r    r)   r)   r)   r*   r      s    
3r   )	dostadminr   r   utilsr   r   configr   r   r   r   r)   r)   r)   r*   <module>   s   