diff --git a/dff/pipeline/pipeline/pipeline.py b/dff/pipeline/pipeline/pipeline.py index e4f2a654a..8118ab82e 100644 --- a/dff/pipeline/pipeline/pipeline.py +++ b/dff/pipeline/pipeline/pipeline.py @@ -63,7 +63,7 @@ class Pipeline: - key: :py:class:`~dff.script.ActorStage` - Stage in which the handler is called. - value: List[Callable] - The list of called handlers for each stage. Defaults to an empty `dict`. - :param messenger_interface: An `AbsMessagingInterface` instance for this pipeline. + :param messenger_interfaces: An `AbsMessagingInterface` instance for this pipeline. :param context_storage: An :py:class:`~.DBContextStorage` instance for this pipeline or a dict to store dialog :py:class:`~.Context`. :param services: (required) A :py:data:`~.ServiceGroupBuilder` object, @@ -229,7 +229,7 @@ def from_script( parallelize_processing: bool = False, handlers: Optional[Dict[ActorStage, List[Callable]]] = None, context_storage: Optional[Union[DBContextStorage, Dict]] = None, - messenger_interface: Optional[MessengerInterface] = None, + messenger_interfaces: Optional[Union[MessengerInterface, Iterable[MessengerInterface], Dict[str, MessengerInterface]]] = None, pre_services: Optional[List[Union[ServiceBuilder, ServiceGroupBuilder]]] = None, post_services: Optional[List[Union[ServiceBuilder, ServiceGroupBuilder]]] = None, ) -> "Pipeline": @@ -261,7 +261,7 @@ def from_script( :param context_storage: An :py:class:`~.DBContextStorage` instance for this pipeline or a dict to store dialog :py:class:`~.Context`. - :param messenger_interface: An instance for this pipeline. + :param messenger_interfaces: An instance for this pipeline. :param pre_services: List of :py:data:`~.ServiceBuilder` or :py:data:`~.ServiceGroupBuilder` that will be executed before Actor. :type pre_services: Optional[List[Union[ServiceBuilder, ServiceGroupBuilder]]] @@ -282,7 +282,7 @@ def from_script( verbose=verbose, parallelize_processing=parallelize_processing, handlers=handlers, - messenger_interface=messenger_interface, + messenger_interfaces=messenger_interfaces, context_storage=context_storage, components=[*pre_services, ACTOR, *post_services], ) diff --git a/dff/pipeline/types.py b/dff/pipeline/types.py index b8c782471..668686232 100644 --- a/dff/pipeline/types.py +++ b/dff/pipeline/types.py @@ -252,7 +252,7 @@ class ExtraHandlerRuntimeInfo(BaseModel): PipelineBuilder: TypeAlias = TypedDict( "PipelineBuilder", { - "messenger_interface": NotRequired[Optional["MessengerInterface"]], + "messenger_interfaces": NotRequired[Optional[Union["MessengerInterface", Iterable["MessengerInterface"], Dict[str, "MessengerInterface"]]]], "context_storage": NotRequired[Optional[Union[DBContextStorage, Dict]]], "components": ServiceGroupBuilder, "before_handler": NotRequired[Optional[ExtraHandlerBuilder]], diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index 5f633c500..64bdf4b8a 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -74,7 +74,7 @@ class and [telebot](https://pytba.readthedocs.io/en/latest/index.html) script=script, start_label=("greeting_flow", "start_node"), fallback_label=("greeting_flow", "fallback_node"), - messenger_interface=interface, + messenger_interfaces=interface, # The interface can be passed as a pipeline argument. ) diff --git a/tutorials/messengers/telegram/2_buttons.py b/tutorials/messengers/telegram/2_buttons.py index 6e5817fe0..bc1fd9542 100644 --- a/tutorials/messengers/telegram/2_buttons.py +++ b/tutorials/messengers/telegram/2_buttons.py @@ -180,7 +180,7 @@ class is used to represent telegram message, script=script, start_label=("root", "start"), fallback_label=("root", "fallback"), - messenger_interface=interface, + messenger_interfaces=interface, ) diff --git a/tutorials/messengers/telegram/3_buttons_with_callback.py b/tutorials/messengers/telegram/3_buttons_with_callback.py index 10d54927f..842cde787 100644 --- a/tutorials/messengers/telegram/3_buttons_with_callback.py +++ b/tutorials/messengers/telegram/3_buttons_with_callback.py @@ -168,7 +168,7 @@ class is used to represent telegram message, script=script, start_label=("root", "start"), fallback_label=("root", "fallback"), - messenger_interface=interface, + messenger_interfaces=interface, ) diff --git a/tutorials/messengers/telegram/4_conditions.py b/tutorials/messengers/telegram/4_conditions.py index d856e3056..267373044 100644 --- a/tutorials/messengers/telegram/4_conditions.py +++ b/tutorials/messengers/telegram/4_conditions.py @@ -134,7 +134,7 @@ script=script, start_label=("greeting_flow", "start_node"), fallback_label=("greeting_flow", "fallback_node"), - messenger_interface=interface, + messenger_interfaces=interface, ) diff --git a/tutorials/messengers/telegram/5_conditions_with_media.py b/tutorials/messengers/telegram/5_conditions_with_media.py index 144ef9c32..b35eb7c9c 100644 --- a/tutorials/messengers/telegram/5_conditions_with_media.py +++ b/tutorials/messengers/telegram/5_conditions_with_media.py @@ -190,7 +190,7 @@ def extract_data(ctx: Context, _: Pipeline): # A function to extract data with script=script, start_label=("root", "start"), fallback_label=("root", "fallback"), - messenger_interface=interface, + messenger_interfaces=interface, pre_services=[extract_data], ) diff --git a/tutorials/messengers/telegram/6_conditions_extras.py b/tutorials/messengers/telegram/6_conditions_extras.py index c154a2ed7..9a2bd5ec5 100644 --- a/tutorials/messengers/telegram/6_conditions_extras.py +++ b/tutorials/messengers/telegram/6_conditions_extras.py @@ -113,7 +113,7 @@ script=script, start_label=("greeting_flow", "start_node"), fallback_label=("greeting_flow", "fallback_node"), - messenger_interface=interface, + messenger_interfaces=interface, ) diff --git a/tutorials/messengers/telegram/7_polling_setup.py b/tutorials/messengers/telegram/7_polling_setup.py index d070e4728..92170c42a 100644 --- a/tutorials/messengers/telegram/7_polling_setup.py +++ b/tutorials/messengers/telegram/7_polling_setup.py @@ -50,7 +50,7 @@ # %% pipeline = Pipeline.from_script( *TOY_SCRIPT_ARGS, - messenger_interface=interface, + messenger_interfaces=interface, # The interface can be passed as a pipeline argument ) diff --git a/tutorials/messengers/telegram/8_webhook_setup.py b/tutorials/messengers/telegram/8_webhook_setup.py index a7f4fd68f..15917bc69 100644 --- a/tutorials/messengers/telegram/8_webhook_setup.py +++ b/tutorials/messengers/telegram/8_webhook_setup.py @@ -44,7 +44,7 @@ # %% pipeline = Pipeline.from_script( *TOY_SCRIPT_ARGS, - messenger_interface=interface, + messenger_interfaces=interface, # The interface can be passed as a pipeline argument ) diff --git a/tutorials/messengers/web_api_interface/1_fastapi.py b/tutorials/messengers/web_api_interface/1_fastapi.py index 2bacce327..23180868a 100644 --- a/tutorials/messengers/web_api_interface/1_fastapi.py +++ b/tutorials/messengers/web_api_interface/1_fastapi.py @@ -81,10 +81,10 @@ """ # %% -messenger_interface = CallbackMessengerInterface() +messenger_interfaces = CallbackMessengerInterface() # CallbackMessengerInterface instantiating the dedicated messenger interface pipeline = Pipeline.from_script( - *TOY_SCRIPT_ARGS, messenger_interface=messenger_interface + *TOY_SCRIPT_ARGS, messenger_interfaces=messenger_interfaces ) @@ -102,7 +102,7 @@ async def respond( user_id: str, user_message: Message, ): - context = await messenger_interface.on_request_async(user_message, user_id) + context = await messenger_interfaces.on_request_async(user_message, user_id) return {"user_id": user_id, "response": context.last_response} diff --git a/tutorials/messengers/web_api_interface/2_websocket_chat.py b/tutorials/messengers/web_api_interface/2_websocket_chat.py index 0cd6020a4..7dca3efaf 100644 --- a/tutorials/messengers/web_api_interface/2_websocket_chat.py +++ b/tutorials/messengers/web_api_interface/2_websocket_chat.py @@ -35,9 +35,9 @@ # %% -messenger_interface = CallbackMessengerInterface() +messenger_interfaces = CallbackMessengerInterface() pipeline = Pipeline.from_script( - *TOY_SCRIPT_ARGS, messenger_interface=messenger_interface + *TOY_SCRIPT_ARGS, messenger_interfaces=messenger_interfaces ) @@ -93,7 +93,7 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int): data = await websocket.receive_text() await websocket.send_text(f"User: {data}") request = Message(data) - context = await messenger_interface.on_request_async( + context = await messenger_interfaces.on_request_async( request, client_id ) response = context.last_response.text diff --git a/tutorials/pipeline/2_pre_and_post_processors.py b/tutorials/pipeline/2_pre_and_post_processors.py index bc8fe5625..ea6a399ae 100644 --- a/tutorials/pipeline/2_pre_and_post_processors.py +++ b/tutorials/pipeline/2_pre_and_post_processors.py @@ -70,7 +70,7 @@ def pong_processor(ctx: Context): context_storage={}, # `context_storage` - a dictionary or # a `DBContextStorage` instance, # a place to store dialog contexts - messenger_interface=CLIMessengerInterface(), + messenger_interfaces=CLIMessengerInterface(), # `messenger_interface` - a message channel adapter, # it's not used in this tutorial pre_services=[ping_processor], diff --git a/tutorials/pipeline/3_pipeline_dict_with_services_full.py b/tutorials/pipeline/3_pipeline_dict_with_services_full.py index e24999ab9..609442a14 100644 --- a/tutorials/pipeline/3_pipeline_dict_with_services_full.py +++ b/tutorials/pipeline/3_pipeline_dict_with_services_full.py @@ -131,7 +131,7 @@ def postprocess(ctx: Context, pl: Pipeline): "script": TOY_SCRIPT, "start_label": ("greeting_flow", "start_node"), "fallback_label": ("greeting_flow", "fallback_node"), - "messenger_interface": CLIMessengerInterface( + "messenger_interfaces": CLIMessengerInterface( intro="Hi, this is a brand new Pipeline running!", prompt_request="Request: ", prompt_response="Response: ",