-
Notifications
You must be signed in to change notification settings - Fork 18
Multiple messenger interface support #332
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
base: dev
Are you sure you want to change the base?
Changes from all commits
e4a2d61
97c54a8
738adff
8f96abb
2a280a5
087dfbf
f4c4eeb
3c02196
90037a2
d32691f
81d5cd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| all, | ||
| negation, | ||
| has_last_labels, | ||
| from_interface, | ||
| true, | ||
| false, | ||
| agg, | ||
|
|
||
pseusys marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # %% [markdown] | ||
| """ | ||
| # Multiple interfaces | ||
| """ | ||
|
|
||
| # %pip install dff[telegram] | ||
|
|
||
| # %% | ||
| import os | ||
|
|
||
| from dff.messengers.common.interface import CLIMessengerInterface | ||
| from dff.script import conditions as cnd | ||
| from dff.script import RESPONSE, TRANSITIONS, Message | ||
| from dff.messengers.telegram import PollingTelegramInterface | ||
| from dff.pipeline import Pipeline | ||
| from dff.utils.testing.common import is_interactive_mode | ||
|
|
||
|
|
||
| # %% [markdown] | ||
| """ | ||
| """ | ||
|
|
||
|
|
||
| # %% | ||
| script = { | ||
| "greeting_flow": { | ||
| "start_node": { | ||
| TRANSITIONS: {"greeting_node": cnd.exact_match(Message("/start"))}, | ||
| }, | ||
| "greeting_node": { | ||
| RESPONSE: Message("Check out responses from different interfaces!"), | ||
| TRANSITIONS: { | ||
| "console_node": cnd.from_interface(CLIMessengerInterface), | ||
| "telegram_node": cnd.from_interface(PollingTelegramInterface) | ||
| }, | ||
| }, | ||
| "console_node": { | ||
| RESPONSE: Message("Hi from CLI!"), | ||
| TRANSITIONS: {"greeting_node": cnd.true()} | ||
| }, | ||
| "telegram_node": { | ||
| RESPONSE: Message("Hi from Telegram!"), | ||
| TRANSITIONS: {"greeting_node": cnd.true()} | ||
| }, | ||
| "fallback_node": { | ||
| RESPONSE: Message("Please, repeat the request"), | ||
| TRANSITIONS: {"greeting_node": cnd.exact_match(Message("/start"))}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| # this variable is only for testing | ||
| happy_path = ( | ||
| (Message("/start"), Message("Hi")), | ||
| (Message("Hi"), Message("Hi")), | ||
| (Message("Bye"), Message("Hi")), | ||
| ) | ||
|
|
||
|
|
||
| # %% | ||
| telegram_interface = PollingTelegramInterface(token=os.environ["TG_BOT_TOKEN"]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tutorial is currently broken due to calling #328 also uses See the tip: |
||
|
|
||
| console_interface = CLIMessengerInterface() | ||
|
|
||
|
|
||
| # %% | ||
| pipeline = Pipeline.from_script( | ||
| script=script, | ||
| start_label=("greeting_flow", "start_node"), | ||
| fallback_label=("greeting_flow", "fallback_node"), | ||
| messenger_interfaces=[telegram_interface, console_interface], | ||
| # The interface can be passed as a pipeline argument. | ||
| ) | ||
|
|
||
|
|
||
| def main(): | ||
| pipeline.run() | ||
|
|
||
|
|
||
| if __name__ == "__main__" and is_interactive_mode(): | ||
| # prevent run during doc building | ||
| main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: fix docs