66from pydantic import Field
77
88from steamship import Block
9- from steamship .agents .schema import AgentContext , EmitFunc , Metadata
9+ from steamship .agents .schema import Agent , AgentContext , EmitFunc , Metadata
1010from steamship .experimental .package_starters .web_agent import SteamshipWidgetAgentService
1111from steamship .experimental .package_starters .web_bot import response_for_exception
1212from steamship .experimental .transports import TelegramTransport
@@ -20,18 +20,20 @@ class TelegramBotConfig(Config):
2020class TelegramAgentService (SteamshipWidgetAgentService , ABC ):
2121 config : TelegramBotConfig
2222 telegram_transport : TelegramTransport
23+ incoming_message_agent : Agent
2324
2425 @classmethod
2526 def config_cls (cls ) -> Type [Config ]:
2627 """Return the Configuration class."""
2728 return TelegramBotConfig
2829
29- def __init__ (self , ** kwargs ):
30+ def __init__ (self , incoming_message_agent : Agent , ** kwargs ):
3031 super ().__init__ (** kwargs )
3132 self .api_root = f"https://api.telegram.org/bot{ self .config .bot_token } "
3233 self .telegram_transport = TelegramTransport (
3334 bot_token = self .config .bot_token , client = self .client
3435 )
36+ self .incoming_message_agent = incoming_message_agent
3537
3638 def instance_init (self ):
3739 """This instance init method is called automatically when an instance of this package is created. It registers the URL of the instance as the Telegram webhook for messages."""
@@ -62,7 +64,7 @@ def respond(self, **kwargs) -> InvocableResponse[str]:
6264 if len (context .emit_funcs ) == 0 :
6365 context .emit_funcs .append (self .build_emit_func (chat_id = chat_id ))
6466
65- response = self .run_agent (context )
67+ response = self .run_agent (self . incoming_message_agent , context )
6668 if response is not None :
6769 self .telegram_transport .send (response , metadata = {})
6870 else :
0 commit comments