1515 CommandRegisterEventData ,
1616 NotificationConf ,
1717 MessageResponse ,
18+ NotificationType ,
1819)
1920from app .schemas .types import ModuleType , ChainEventType
2021from app .utils .structures import DictUtils
@@ -451,6 +452,7 @@ def post_message(self, message: Notification, **kwargs) -> None:
451452 return
452453 client : Telegram = self .get_instance (conf .name )
453454 if client :
455+ stop_typing = message .mtype != NotificationType .Agent
454456 if message .file_path :
455457 client .send_file (
456458 file_path = message .file_path ,
@@ -459,13 +461,15 @@ def post_message(self, message: Notification, **kwargs) -> None:
459461 text = message .text ,
460462 userid = userid ,
461463 original_chat_id = message .original_chat_id ,
464+ stop_typing = stop_typing ,
462465 )
463466 elif message .voice_path :
464467 client .send_voice (
465468 voice_path = message .voice_path ,
466469 userid = userid ,
467470 caption = message .voice_caption ,
468471 original_chat_id = message .original_chat_id ,
472+ stop_typing = stop_typing ,
469473 )
470474 else :
471475 client .send_msg (
@@ -478,6 +482,7 @@ def post_message(self, message: Notification, **kwargs) -> None:
478482 original_message_id = message .original_message_id ,
479483 original_chat_id = message .original_chat_id ,
480484 disable_web_page_preview = message .disable_web_page_preview ,
485+ stop_typing = stop_typing ,
481486 )
482487
483488 def post_medias_message (
@@ -502,6 +507,7 @@ def post_medias_message(
502507 buttons = message .buttons ,
503508 original_message_id = message .original_message_id ,
504509 original_chat_id = message .original_chat_id ,
510+ stop_typing = message .mtype != NotificationType .Agent ,
505511 )
506512
507513 def post_torrents_message (
@@ -526,6 +532,7 @@ def post_torrents_message(
526532 buttons = message .buttons ,
527533 original_message_id = message .original_message_id ,
528534 original_chat_id = message .original_chat_id ,
535+ stop_typing = message .mtype != NotificationType .Agent ,
529536 )
530537
531538 def delete_message (
@@ -585,12 +592,14 @@ def edit_message(
585592 continue
586593 client : Telegram = self .get_instance (conf .name )
587594 if client :
595+ stop_typing = not (metadata or {}).get ("agent_managed_typing" )
588596 result = client .edit_msg (
589597 chat_id = chat_id ,
590598 message_id = message_id ,
591599 text = text ,
592600 title = title ,
593601 buttons = buttons ,
602+ stop_typing = stop_typing ,
594603 )
595604 if result :
596605 return True
@@ -665,12 +674,14 @@ def send_direct_message(self, message: Notification) -> Optional[MessageResponse
665674 return None
666675 client : Telegram = self .get_instance (conf .name )
667676 if client :
677+ agent_managed_typing = message .mtype == NotificationType .Agent
668678 if message .voice_path :
669679 result = client .send_voice (
670680 voice_path = message .voice_path ,
671681 userid = userid ,
672682 caption = message .voice_caption ,
673683 original_chat_id = message .original_chat_id ,
684+ stop_typing = not agent_managed_typing ,
674685 )
675686 else :
676687 result = client .send_msg (
@@ -680,13 +691,17 @@ def send_direct_message(self, message: Notification) -> Optional[MessageResponse
680691 userid = userid ,
681692 link = message .link ,
682693 disable_web_page_preview = message .disable_web_page_preview ,
694+ stop_typing = not agent_managed_typing ,
683695 )
684696 if result and result .get ("success" ):
685697 return MessageResponse (
686698 message_id = result .get ("message_id" ),
687699 chat_id = result .get ("chat_id" ),
688700 channel = MessageChannel .Telegram ,
689701 source = conf .name ,
702+ metadata = {"agent_managed_typing" : True }
703+ if agent_managed_typing
704+ else None ,
690705 success = True ,
691706 )
692707 return None
0 commit comments