
    Lho                         d dl Z d dlmZ d dlmZ d dlmZmZ d dlmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ  G d	 d
e      Zy)    N)BaseService)HTTPException)datetimetimezone)AdvisorNotificationsCallsLog)get_twillio_client)create_offline_message)get_app_urlc                   <     e Zd Z fdZddededededef
dZ xZS )	UltravoxServicec                 $    t         |   |       y )N)super__init__)selfdb	__class__s     O/var/www/html/DP/alpha_backend/app/advisor_service/services/ultravox_service.pyr   zUltravoxService.__init__   s        advisor_namemessagecustomer_namecall_idreturnc                 L   | j                  t        d|      }|j                  }| j                  j	                  t
              j                  t
        j                  j                  d| d            j                         }|st        dd      t        | j                  ||||       | j                  t        |j                  |j                  dd| |||d	|t!        j"                  t$        j&                        t!        j"                  t$        j&                        d
       y)a6  
        Create an offline message and notification for an advisor
        
        Args:
            advisor_name: Name of the advisor
            message: Message content
            customer_name: Name of the customer (defaults to "Unknown")
            customer_phone: Phone number of the customer
        r   %i  zAAdvisor not found, message not saved and no notification created.)status_codedetail)r   r   customer_noter   customer_phoneoffline_messagezNew Message from F)user_id
advisor_idnotification_typetitler   r   r!   is_readr   
created_at
updated_atN)get_by_fieldr	   caller_numberr   queryr   filter	full_nameilikefirstr   r   creater   r#   idr   nowr   utc)r   r   r   r   r   call_logr!   advisors           r   r   z&UltravoxService.create_offline_message   s     $$Xy'B!//''--(//##a~Q$78

%' 	 Z 
 	ww'!%)	
 	M!**!2(8*,",,x||4",,x||4$
 	r   )UnknownN)__name__
__module____qualname__r   strdictr   __classcell__)r   s   @r   r   r      s7    +3 + +UX +or +  C +r   r   )os)app.advisor_service.services.base_servicer   fastapir   r   r   app.common.modelsr   r   r	   app.common.twillio_helperr
   *app.retell_service.services.retell_servicer   app.utils.helpers.commonr   r    r   r   <module>rF      s,    	 A ! ' > > 8 M 0/k /r   