§
    ÔŸ’j  ã                  ó>  — d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZ ddlmZmZmZmZmZmZ ddlmZ  edd	g¬
¦  «        Z e¦   «         Ze                     de¬¦  «        d&d„¦   «         Ze                     de¬¦  «        d'd„¦   «         Ze                     de¬¦  «        d(d„¦   «         Ze                     de¬¦  «        d)d„¦   «         Ze                     d¦  «        d*d„¦   «         Ze                     d¦  «         ed ¬!¦  «        fd+d%„¦   «         Zd S ),z-Telegram Enterprise Suite REST API endpoints.é    )Úannotations)ÚAny)Ú	APIRouterÚHeaderÚHTTPExceptionÚstatus)Úget_settings)ÚTelegramAlertRequestÚTelegramProcessCommandRequestÚTelegramResponseÚTelegramSendMessageRequestÚTelegramServiceStatusÚ$TelegramSiteDiaryNotificationRequest)ÚTelegramServicez/v1/telegramzTelegram Suite)ÚprefixÚtagsz/status)Úresponse_modelÚreturnr   c               ƒ  ó8   K  — t                                ¦   «         S )zIReturn the operational status of the Telegram Bot & Notification Gateway.)Útelegram_serviceÚ
get_status© ó    ú5C:\Projects\DSCons\app\api\routers\telegram_routes.pyÚget_telegram_statusr      s   è è € õ ×&Ò&Ñ(Ô(Ð(r   z/send-messageÚpayloadr   r   c              ƒ  ó‚   K  — t                                | j        | j        | j        | j        | j        ¬¦  «        ƒ d{V —†S )z8Send an arbitrary text message or HTML card to Telegram.)ÚtextÚchat_idÚ
parse_modeÚdisable_web_page_previewÚreply_markupN)r   Úsend_messager   r   r    r!   r"   ©r   s    r   Úsend_telegram_messager%      s_   è è € õ
 "×.Ò.ØŒ\Ø”ØÔ%Ø!(Ô!AØÔ)ð /ñ ô ð ð ð ð ð ð ð r   z/send-alertr
   c           	   ƒ  óš   K  — t                                | j        | j        | j        | j        | j        | j        | j        ¬¦  «        ƒ d{V —†S )zRDispatch a structured enterprise alert card for EVM, Invoices, Quality, or Safety.)ÚtitleÚ
alert_typeÚseverityÚproject_nameÚdetailsÚ
action_urlr   N)	r   Ú
send_alertr'   r(   r)   r*   r+   r,   r   r$   s    r   Úsend_telegram_alertr.   ,   sj   è è € õ "×,Ò,ØŒmØÔ%ØÔ!ØÔ)Ø”ØÔ%Ø”ð -ñ ô ð ð ð ð ð ð ð r   z/site-diary-notificationr   c              ƒ  ó²   K  — t                                | j        | j        | j        | j        | j        | j        | j        | j	        | j
        ¬¦	  «	        ƒ d{V —†S )zDBroadcast daily site diary summary to site engineers and management.)	Úproject_coder*   Ú
shift_dateÚweatherÚworkforce_countÚmachine_countÚ
activitiesÚsupervisor_notesr   N)r   Úsend_site_diary_reportr0   r*   r1   r2   r3   r4   r5   r6   r   r$   s    r   Úsend_site_diary_notificationr8   :   sw   è è € õ
 "×8Ò8ØÔ)ØÔ)ØÔ%Ø”ØÔ/ØÔ+ØÔ%Ø Ô1Ø”ð 9ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r   z/process-commandr   údict[str, Any]c              ƒ  óŒ   K  — t                                | j        | j        | j        | j        ¬¦  «        ƒ d{V —†}d| j        |dœS )zNExecute or simulate a Telegram command (/nhatky, /duan, /camay, /ai, /hoadon).)Úcommand_textÚ	user_namer   Ú
project_idNT)ÚokÚcommandÚreply)r   Úprocess_commandr?   r<   r   r=   )r   r@   s     r   Úprocess_telegram_commandrB   L   sr   è è € õ
 #×2Ò2Ø”_ØÔ#Ø”ØÔ%ð	 3ñ ô ð ð ð ð ð ð €Eð Ø”?Øðð ð r   z/webhookN)ÚdefaultÚupdateÚx_telegram_bot_api_secret_tokenú
str | Nonec              ƒ  ó¶   K  — t          ¦   «         j        }|r#|r!||k    rt          t          j        d¬¦  «        ‚t
                               | ¦  «        ƒ d{V —†S )z)Handle incoming Telegram webhook updates.z%Invalid Telegram webhook secret token)Ústatus_codeÚdetailN)r	   Útelegram_webhook_secretr   r   ÚHTTP_403_FORBIDDENr   Úhandle_webhook_update)rD   rE   Úsecrets      r   Útelegram_webhookrN   ^   sy   è è € õ ‰^Œ^Ô3€Fàð
à+ð
ð ,¨vÒ5Ð5åÝÔ1Ø:ð
ñ 
ô 
ð 	
õ "×7Ò7¸Ñ?Ô?Ð?Ð?Ð?Ð?Ð?Ð?Ð?r   )r   r   )r   r   r   r   )r   r
   r   r   )r   r   r   r   )r   r   r   r9   )rD   r9   rE   rF   r   r9   )Ú__doc__Ú
__future__r   Útypingr   Úfastapir   r   r   r   Úapp.core.settingsr	   Úapp.models.telegram_schemasr
   r   r   r   r   r   Úapp.services.telegram_servicer   Úrouterr   Úgetr   Úpostr%   r.   r8   rB   rN   r   r   r   ú<module>rY      s<  ðØ 3Ð 3à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <à *Ð *Ð *Ð *Ð *Ð *ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð :Ð 9Ð 9Ð 9Ð 9Ð 9à	ˆ˜.Ð0@Ð/AÐ	BÑ	BÔ	B€Ø"�?Ñ$Ô$Ð ð ‡‚ˆIÐ&;€Ñ<Ô<ð)ð )ð )ñ =Ô<ð)ð
 ‡‚ˆ_Ð-=€Ñ>Ô>ð
ð 
ð 
ñ ?Ô>ð
ð ‡‚ˆ]Ð+;€Ñ<Ô<ð
ð 
ð 
ñ =Ô<ð
ð ‡‚Ð'Ð8H€ÑIÔIðð ð ñ JÔIðð" ‡‚ÐÑ Ô ðð ð ñ !Ô ðð" ‡‚ˆZÑÔð 39°&ÀÐ2FÑ2FÔ2Fð@ð @ð @ð @ñ Ôð@ð @ð @r   