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/blueprints/sms/__pycache__/tw_sms_inbound.cpython-310.pyc
o

�wey#�@s�dZddlmZddlZddlmZmZddlmZddl	m
Z
ddlmZm
Z
e�e�Zeded	d
�ZdZejdd
dgd�ejdd���ZdS)aY
Governs the logic of the incoming lead calls and lead/agent interations.

At any given moment the call is in one of the following states:

* 'NEW': New inbound call
* 'CALLBACK': Callback call, agent called first
* 'LEAD_ONHOLD': Lead selected a routing, placed on hold until agent answers
* 'AGENT_ONHOLD': In a scheduled callback, the agent is called first and placed
  on hold.
* 'CALLBACK_PROMPT': Lead has been waiting for a while and is asked if he wants
  to be called back.
* 'ONGOING': Agent answered/call ongoing.
* 'MISSED': Call ended/lead missed.
* 'CAPTURED': Call ended/lead captured.
�)�print_functionN)�	Blueprint�request)�format_phone_number)�Block)�csrf�db�tw_sms_inbound�	templates)�template_folder�twilioz'/twiml/inbound/message/<int:inbound_id>�GET�POST)�methodsc)	Cs�t�|tj�dd��}|r"t�d�tj�dd�tj�dd���dSddlm	}|j
�|j|k��
�}t�|j�t�|j�d��|j}ddlm}m}|j
�|j|k��
�}|j
�|j|jk��
�}tj}	t�d	�|	��d
dlm}
|
|jjj|j�}tj�dd�}t�d
�|��|�|���}
tj�dd�}tj�dd�}tj�dd�}|r�ddlm}||||||
�n
ddlm}|||||
�|j�d�r�|j�d�r�ddlm }|j�d�d}|j�d�}t�d�|��|||||�n	t�d�|j!��|j�d��r�|j�d��r�|�"�}t#tj�dd��}|j�d�}|j�d��"�}|j�d�}|j�d�}|j�d�}|j�d�}|j�d�}|j�d �}|j�d!�}|j�d"�}|�r�||v�r�t�d#�|��|d$k�r�|d%k�r�t�d&�|||��d
d'l$m%} | �&|||�|d(k�r�|d%k�r�ddlm }d}!|�r�|||||!�nt�'d)�|��|d(k�r�|d*k�r�ddlm }dd+l(m)}"|�r�|"j
�|"j|k��
�}#d}!|||#j!||!�nt�'d,�|��|d(k�r|d-k�rddlm }|�rd}!|||||!�nt�'d.�|��|d/k�r:|d%k�r:dd0l*m+}$|$j
�|$j,|k��|$j|k��
�}%d1|%_-t.j/�0|%�t.j/�1�|d2k�rx|d%k�rxdd0l*m+}$dd3l2m3}&|$j
�|$j,|k��|$j|k��
�}%|%j4�rp|&|%j4|%j5|||	�nt�'d4�|��|d2k�r�|d*k�r�dd+l(m)}"dd3l2m3}&|�r�|"j
�|"j|k��
�}'|&|'j4|'j5|||	�|d2k�r�|d-k�r�dd3l2m3}&d}(|&||(|||	�dSt�d5�|j!��dS)6N�From�zGThis phone number: {} was blocked and this message: [ {} ] was not sent�Body�)�Phone�configSMSSetup)�Partnership�PartnershipAccountzThe sms info is {}r)�subaccount_client�
MessageSidzmessage sid is {}�	MediaUrl0)�tw_forward_mms)�tw_forward_sms�SMSAutoReply)�send_text_message�SMSAutoReplyTextz Reply STOP to unsubscribe.�SMSAutoReplyImageUrlzThe image url is {}z:The SMS Auto Reply is turned off for this phone number: {}�
SMSRuleOne�SMSRuleOneCallAgent�SMSRuleOneKeyword�SMSRuleOneAction�SMSRuleOneRecipientType�SMSRuleOneSMSBody�SMSRuleOneRecipientAgent�SMSRuleOneRecipientCustom�SMSRuleOneEmailBody�SMSRuleOneEmails�SMSRuleOneEmailAgentz!the keyword: {} is in the message�call�leadzCthe action is: {} and the contact is: {} and the lead number is: {})�sms_rule_call_lead�smszRThere is no lead phone number set to receive the sms rule base sms. Inbound id: {}�agent)�AgentzFThere is no agent set to receive the sms rule base sms. Inbound id: {}�customzTThere is no custom phone number set to receive the sms rule base sms. Inbound id: {}�unsubscribe)�ContactT�email)�send_sms_rule_emailz5There is no contact email address for phone number {}z4The SMS Rule is turned off for this phone number: {})6r�blockedr�form�get�log�info�format�phonenumbers.modelsr�query�filter�id�first�
friendly_name�routing_config�partnership_account_id�partnership.modelsrr�partnership_id�buyercall.lib.util_twilior�partnership_account�subscription�twilio_subaccount_sid�messages�fetch�sms.tw_sms_tasksrr�	sms.viewsr�phonenumber�lowerr�%buyercall.blueprints.sms.tw_sms_tasksr.�delay�warning�
agents.modelsr1�contacts.modelsr4�
phonenumber_1�is_unsubscriber�session�add�commit�	sms.tasksr6r5�	firstname))�
inbound_id�is_number_blockedr�inboundrDrr�partner_account�partnerr;r�
twilio_client�message_sid�message_lookup�bodyr-�	media_urlrrr�text�	text_body�
call_agent�keyword�action�contact�
rule_sms_body�rule_sms_agent�rule_sms_custom�rule_sms_email_body�custom_email_addresses�email_agentr.�img_urlr1�agent_nor4�contact_leadr6r0�custom_name�rw�I/home/arjun/projects/buyercall/buyercall/blueprints/sms/tw_sms_inbound.py�lead_inbound_message#s���
�����
�����ry)�__doc__�
__future__r�logging�flaskrr�buyercall.blueprints.filtersr�)buyercall.blueprints.block_numbers.modelsr�buyercall.extensionsrr�	getLogger�__name__r:r	�provider�route�exemptryrwrwrwrx�<module>s
�