Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple messenger interface support #332

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open

Conversation

pseusys
Copy link
Collaborator

@pseusys pseusys commented Mar 1, 2024

Description

Multiple user interface support added.

Checklist

  • I have performed a self-review of the changes

To Consider

  • Add tests (if functionality is changed)
  • Update API reference / tutorials / guides
  • Update CONTRIBUTING.md (if devel workflow is changed)
  • Update .ignore files, scripts (such as lint), distribution manifest (if files are added/deleted)
  • Search for references to changed entities in the codebase

@pseusys pseusys changed the title no message subscription prototype Multiple messenger interface support Mar 3, 2024
@RLKRo RLKRo added the enhancement New feature or request label Mar 5, 2024
Copy link
Member

@RLKRo RLKRo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

dff/pipeline/pipeline/actor.py Outdated Show resolved Hide resolved
@@ -62,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: fix docs

dff/pipeline/pipeline/pipeline.py Outdated Show resolved Hide resolved
dff/script/conditions/std_conditions.py Outdated Show resolved Hide resolved
dff/script/core/context.py Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add tests for launching pipeline with multiple http interfaces and running them at the same time on different ports.

tutorials/messengers/web_api_interface/1_fastapi.py Outdated Show resolved Hide resolved
tutorials/messengers/multiple_interfaces.py Outdated Show resolved Hide resolved
dff/pipeline/pipeline/pipeline.py Outdated Show resolved Hide resolved
@pseusys
Copy link
Collaborator Author

pseusys commented Mar 12, 2024

Could you please remind me our final decision: do we pass interfaces as dict or as array only (with default or user-specified names)?

@RLKRo
Copy link
Member

RLKRo commented Mar 12, 2024

The latter.

interface = CLIMessengerInterface()
self.messenger_interfaces = {interface.name: interface}
else:
self.messenger_interfaces = {iface.name: iface for iface in messenger_interfaces}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check for duplicates.

@abc.abstractmethod
async def connect(self, pipeline_runner: PipelineRunnerFunction):
async def connect(self, pipeline_runner: PipelineRunnerFunction, iface_id: str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this parameter when it is always self.name?

@@ -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"]]]],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this.



# %%
telegram_interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tutorial is currently broken due to calling infinity_polling in this interface.

#328 also uses self.application.run_polling to start the bot, so I'm assuming it would also cause issues.

See the tip:
https://docs.python-telegram-bot.org/en/v21.1.1/telegram.ext.application.html#telegram.ext.Application.run_polling

@RLKRo RLKRo mentioned this pull request Aug 2, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants