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__/bw_sms_inbound.cpython-310.pyc
o

�we�/�@s�dZddlmZddlZddlmZmZmZmZm	Z
ddlmZddl
mZmZddlmZddlmZe�e�Zed	ed
d�ZdZejd
ddgd�ejdd���Zdd�Zejdddgd�ejdd���ZdS)z7
Governs the logic of the incoming lead text messages.
�)�print_functionN)�	Blueprint�request�jsonify�
make_response�current_app)�Block)�csrf�db)�and_)�	load_only�bw_sms_inbound�	templates)�template_folder�	bandwidthz/bw/sms�GET�POST)�methodscCshddlm}|tj�}|r"tj}t|�d}tdd�}t||�}|Std�d}tdd�}t||�}|S)	a Entry point for the incoming SMS or MMS messages. This is specifically for Bandwidth API V2. A Location
    exist with 2 application attach to it. One is for SMS/MMS and the other for Voice. This call-back url
    is specified on the SMS.MMS application.
    r��authenticate_bw_request���Authentication passed.��message�Authentication failed��Authentication failed.)	�buyercall.lib.util_bandwidthrr�headers�json�lead_inbound_messagerr�print)r�
authenticated�args�status_coder�response�r&�I/home/arjun/projects/buyercall/buyercall/blueprints/sms/bw_sms_inbound.py�inbound_smss




r(c+CsZ|d�dd�}|�dd�}|d�dd�}|d�dd�}|�dd�}|��}|�dd�}|r3d	}nd
}|rXddlm}	|	j�|	j|k���}
|
rN|
j}nt	�
d
�|��dSt	�
d�|��dSt�
|
j|�}|rut	�
d�|��dSddlm}
|
|
j|
j||||t�}|s�t	�d�Sddlm}|j�t|j|jk|j|k����}gd�}||vr�ddlm}ddlm}|j�|j|k��td����}t	�
|j�|}ddlm}|jd||�dd}||
j||dd�dSgd�}||v�r|�rd|_ t!j"�#�dSt	�d�||
j��dS|j �r+|}ddlm}d }||
j||dd�dSgd!�}||v�rQ|�r@d"|_ t!j"�#�n
t	�d�||
j��t	�
d#�dSdd$lm$}|j%|
j|jgdd%�|
j&�d&��r�|
j&�d'��r�dd(l'm(}|
j&�d)�d*}|
j&�d+d�}|�r�|�)d,d-�d.�)d/�d�*d0d1�}t+j,d2}dd3l-m.} | ||�}||
j|||�|
j&�d&��r�|
j&�d4��r�dd(l'm(}|}|}!|
j&�d5���}"|
j&�d6�}#|
j&�d7�}$|
j&�d8�}%|
j&�d9�}&|
j&�d:�}'|"�r�|"|v�r�t	�
d;�|"��|#d
k�r|$d<k�r|!�r||
j|!|%dd=�n	t	�/d>�|
j��|#d
k�rQ|$d?k�rQdd@l0m1}(|&�rH|(j�|(j|&k���})||
j|)j|%dd=�n	t	�/dA�|
j��|#d
k�rq|$dBk�rq|'�rh||
j|'|%dd=�n	t	�/dC�|
j��|#dDk�r�|$d<k�r�ddlm}|j�|j2|!k��|j|k���}*d"|*_ t!j"�3|*�t!j"�#�dSt	�
dE�|
j��dS)FNrr��from�to�description�text�media�mms�sms�)�Phonez9Unable to match a BC number to to_ field number. args: {}z?Something went wrong with receiving a sms/mms message. args: {}zBThis phone number: {} was blocked and the message was not received�)�add_bw_message_leadzfSomething went wrong with adding the inbound message to the database. Most likely a field length issue)�Contact)z helpzhelp �help)�bw_send_sms)�PartnershipAccount�name)�format_phone_number_bracketz
: Help at z. z4Msg&data rates may apply. Reply STOP to unsubscribe.)�
agent_list)�unstopz unstopzunstop �startz startzstart �nonarretFz�A contact id was not found for the message being sent from: {} using phone number {}and we were unable to unsubscribe the contact from receiving messagesz|You replied with the word "STOP" which blocks all texts sent from this number. Text back "UNSTOP" to receive messages again.)	�stopz stopzstop �unsubscribez unsubscribezunsubscribe zun-subscribe�unsubcribed�arretTzEMessage not sent due to unsubscribe keyword in received message text.)�bw_forward_sms�r#�	countdown�configSMSSetup�SMSAutoReply)�send_text_message�SMSAutoReplyTextz Reply STOP to unsubscribe.�SMSAutoReplyImageUrl�/�����?z%20� �
MMS_BUCKET)�generate_presigned_aws_url�
SMSRuleOne�SMSRuleOneKeyword�SMSRuleOneAction�SMSRuleOneRecipientType�SMSRuleOneSMSBody�SMSRuleOneRecipientAgent�SMSRuleOneRecipientCustomz!the keyword: {} is in the message�lead)r.zRThere 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: {}r@z4The SMS Rule is turned off for this phone number: {})4�get�lower�phonenumbers.modelsr2�query�filter�phonenumber�first�partnership_account_id�log�info�formatr�blocked�id�bw_sms_tasksr4�provider�error�contacts.modelsr5r�
contact_id�sms.bw_sms_tasksr7�partnership.modelsr8�optionsrr9�filtersr:�is_unsubscriber
�session�commitrC�apply_async�routing_config�	sms.viewsrH�split�replace�app�config�buyercall.lib.util_boto3_s3rQ�warning�
agents.modelsr[�
phonenumber_1�add)+r#r�from_�to_�delivery_descriptionr-�lowercase_text_bodyr.�message_typer2�inboundrd�is_number_blockedr4�
added_messager5�contact�help_keyword_listr7r8�account�senderr:�return_text�subscribe_keyword_list�unsubscribed_keyword_listrCrH�	text_body�	media_url�	media_key�bucketrQrY�keyword�action�	recipient�
rule_sms_body�rule_sms_agent�rule_sms_customr[�agent_no�contact_leadr&r&r'r 8s�
���

�
�

�
"


����
�r z/bw/sms/status/callbackcCs�ddlm}|tj�}|r\tjptj}t|�d}|d�dd�}|�dd�}|d�dd�}|d�dd�}|d�d	d�}d
dlm	}	|	j
||||gdd
�tdd�}t||�}
|
Std�d}tdd�}t||�}
|
S)a Entry point for the incoming SMS or MMS messages status callback. This is specifically for Bandwidth API
    V2. A Location exist with 2 application attach to it. One is for SMS/MMS and the other for Voice. This call-back url
    is specified on the SMS.MMS application.
    rrrrr)ri�	errorCoder,�typer1)�update_msg_recordr3rDrrrrr)
rrrrrr#r!r]ror�rvrr)rr"r#r$r�msg_id�
delivery_coder��
delivery_typer�r%r&r&r'�sms_status_callback�s*




r�)�__doc__�
__future__r�logging�flaskrrrrrr{�)buyercall.blueprints.block_numbers.modelsr�buyercall.extensionsr	r
�
sqlalchemyr�sqlalchemy.ormr�	getLogger�__name__rer
rk�route�exemptr(r r�r&r&r&r'�<module>s*
�(