
    rki                     ^    d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	  G d d      Z
 e
       Zy)    N)ListDictAnyOptional)settings)ProfileSearchResultc                       e Zd Zedefd       Zdeeef   dee	   fdZ
dededeeef   fdZ	 dded	ed
eeeef      deeef   fdZy)
BotServicereturnc                 @    t         j                  j                  d      S )N/)r   BOT_SERVICE_URLrstrip)selfs    :/home/www/utuvibe.miabetepe.com/app/bot_service/service.py	_base_urlzBotService._base_url   s    ''..s33    criteriac           	      N  K   | j                    d}|j                         D ci c]  \  }}|	|| }}}t        j                         4 d {   }	 t	        d| d|        |j                  ||d       d {   }|j                          |j                         }|j                  dg       }	|	D 
cg c]  }
t        d
i |
 c}
cd d d       d {    S c c}}w 7 7 hc c}
w 7 # t        j                  $ rW}t	        d|j                  j                   d|j                  j                          g cY d }~cd d d       d {  7   S d }~wt        $ r,}t	        d	|        g cY d }~cd d d       d {  7   S d }~ww xY w# 1 d {  7  sw Y   y xY ww)Nz/api/search-profileszSending request to z with criteria: g      N@jsontimeoutresultszBot Service HTTP Error:  - zBot Service Error:  )r   itemshttpxAsyncClientprintpostraise_for_statusr   getr   HTTPStatusErrorresponsestatus_codetext	Exception)r   r   urlkvcleaned_criteriaclientr$   dataresults_dataitemes               r   search_profileszBotService.search_profiles   s      45-5^^-=OTQAqDOO$$& 	 	&+C50@AQ@RST!'S7GQU!VV))+}}#xx	26@LM+3d3M	 	 	 P	 W
 N	 (( 01G1G0HAJJOOK\]^		 	 	  +A3/0		 	 		 	 	s   #F%
CCF%C%F%F(C0>C'?:C09C)C0F%C.F%'C0)C0.F%0F:E=F>FF%EF%F!F0F1F5F%FF%FFF"FF"F%tomessagec                   K   | j                    d}||d}t        j                         4 d {   }	 |j                  ||d       d {   }|j	                          |j                         cd d d       d {    S 7 R7 77 	# t        j                  $ rn}t        d|j                  j                   d|j                  j                          d|j                  j                  dcY d }~cd d d       d {  7   S d }~wt        $ r8}t        d	|        dt        |      dcY d }~cd d d       d {  7   S d }~ww xY w# 1 d {  7  sw Y   y xY ww)
Nz/api/send-message)r2   r3         >@r   z%Bot Service send_message HTTP Error: r   Fsuccesserrorz Bot Service send_message Error: r   r   r   r    r!   r   r#   r   r$   r%   r&   r'   str)r   r2   r3   r(   payloadr,   r$   r0   s           r   send_messagezBotService.send_message!   s7      120$$& 
	; 
	;&	;!'Sw!MM))+}}	
	; 
	; 
	;M
	;
 (( D=ajj>T>T=UUXYZYcYcYhYhXijk#(1::??CC
	; 
	; 
	;  ;8<=#(3q6::
	; 
	; 
	;;
	; 
	; 
	;s   -E BE EBB#B0E <B=E BE EAD,E-E1E =D >E EE+E,E0E <D?=E EEEEEE Ncontent_sid	variablesc                   K   | j                    d}|||xs i d}t        j                         4 d {   }	 |j                  ||d       d {   }|j	                          |j                         cd d d       d {    S 7 R7 77 	# t        j                  $ rn}t        d|j                  j                   d|j                  j                          d|j                  j                  dcY d }~cd d d       d {  7   S d }~wt        $ r8}t        d	|        dt        |      dcY d }~cd d d       d {  7   S d }~ww xY w# 1 d {  7  sw Y   y xY ww)
Nz/api/send-template-message)r2   r=   r>   r5   r   z.Bot Service send_template_message HTTP Error: r   Fr6   z)Bot Service send_template_message Error: r9   )	r   r2   r=   r>   r(   r;   r,   r$   r0   s	            r   send_template_messagez BotService.send_template_message1   sE       :;&"b
 $$& 
	; 
	;&	;!'Sw!MM))+}}	
	; 
	; 
	;M
	;
 (( DFqzzG]G]F^^abcblblbqbqarst#(1::??CC
	; 
	; 
	;  ;A!EF#(3q6::
	; 
	; 
	;;
	; 
	; 
	;s   2E%BE%EBB	#B5E%BE%	BE%E AD	1E2E6E%DE%	EE0E1E5E%EE%EEE"EE"E%)N)__name__
__module____qualname__propertyr:   r   r   r   r   r   r1   r<   r   r@   r   r   r   r
   r
      s    43 4 4d38n FYAZ *;S ;3 ;4S> ;( /3	;; ; DcN+	;
 
c3h;r   r
   )r   typingr   r   r   r   app.core.configr   app.search.schemasr   r
   bot_servicer   r   r   <module>rI      s*     , , $ 2A; A;H lr   