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

v0.9 #4

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions services/bot/bot/custom/conditions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from chatsky.script import Context
from chatsky import Context, BaseCondition


def is_upper_case(ctx: Context, pipeline):
return ctx.last_request.text.isupper()
class IsUpperCase(BaseCondition):
async def call(self, ctx: Context) -> bool:
return ctx.last_request.text.isupper()
14 changes: 7 additions & 7 deletions services/bot/bot/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from chatsky.pipeline import Pipeline
from chatsky import Pipeline
from chatsky.context_storages import context_storage_factory
from chatsky.messengers.telegram import LongpollingInterface

Expand All @@ -27,12 +27,12 @@ def get_variable(var_name: str):
messenger_interface = LongpollingInterface(token=TG_BOT_TOKEN)


pipeline = Pipeline.from_script(
getattr(script, "SCRIPT"),
start_label=getattr(script, "START_NODE"),
fallback_label=getattr(script, "FALLBACK_NODE", None),
pre_services=getattr(script, "PRE_SERVICES", []),
post_services=getattr(script, "POST_SERVICES", []),
pipeline = Pipeline(
script=script.SCRIPT,
start_label=script.START_NODE,
fallback_label=script.FALLBACK_NODE,
pre_services=script.PRE_SERVICES,
post_services=script.POST_SERVICES,
context_storage=context_storage_factory(DB_URI) if DB_URI else None,
messenger_interface=messenger_interface,
)
37 changes: 22 additions & 15 deletions services/bot/bot/script.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
from chatsky.script import Message
from chatsky.script import RESPONSE, TRANSITIONS, LOCAL
from chatsky.script.conditions import exact_match, true
from chatsky import Message, RESPONSE, TRANSITIONS, LOCAL, Transition as Tr
import chatsky.conditions as cnd

from .custom.conditions import is_upper_case
from .custom.conditions import IsUpperCase
from .custom.services import pre_service, post_service


# todo: change this script to yours
SCRIPT = {
"technical_flow": {
"start_node": {
TRANSITIONS: {
("main_flow", "greeting_node"): exact_match("/start"),
},
TRANSITIONS: [
Tr(
dst=("main_flow", "greeting_node"),
cnd=cnd.ExactMatch("/start")
)
],
},
"fallback": {
RESPONSE: Message("Error."),
RESPONSE: "Error.",
},
},
"main_flow": {
LOCAL: {
TRANSITIONS: {
"upper": is_upper_case,
"response": true(),
},
TRANSITIONS: [
Tr(
dst="upper",
cnd=IsUpperCase()
),
Tr(
dst="response",
)
]
},
"greeting_node": {
RESPONSE: Message("Hi, please say something."),
RESPONSE: "Hi, please say something.",
},
"upper": {
RESPONSE: Message("Don't scream, please."),
RESPONSE: "Don't scream, please.",
},
"response": {
RESPONSE: Message("Thank you."),
RESPONSE: "Thank you.",
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion services/bot/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
chatsky[telegram,sqlite]~=0.8
chatsky[telegram,sqlite]~=0.9
pytest