From 5ffbe311739ff81141df150cf1762668dd735445 Mon Sep 17 00:00:00 2001 From: Roman Zlobin Date: Wed, 3 Jul 2024 18:16:47 +0300 Subject: [PATCH] v0.8 (#3) --- README.md | 12 ++++++------ services/bot/Dockerfile | 2 +- services/bot/bot/custom/conditions.py | 2 +- services/bot/bot/pipeline.py | 8 ++++---- services/bot/bot/script.py | 8 ++++---- services/bot/requirements.txt | 2 +- services/bot/test.py | 5 ++--- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e17a438..4dbff02 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ -# DFF Project Template +# Chatsky Project Template -This repository is a template for DFF projects. +This repository is a template for Chatsky projects. ## How to use it ### Clone the repo: ```shell -git clone https://github.com/deeppavlov/DFF-template.git -cd DFF-template +git clone https://github.com/deeppavlov/chatsky-template.git +cd chatsky-template ``` Alternatively, you can create a new repository using this one as a template via GitHub: -https://github.com/new?template_name=DFF-template&template_owner=deeppavlov +https://github.com/new?template_name=chatsky-template&template_owner=deeppavlov ### Edit project files @@ -22,7 +22,7 @@ https://github.com/new?template_name=DFF-template&template_owner=deeppavlov (cd services/bot && pip install -r requirements.txt) ``` 1. Write your custom functions (e.g. custom responses, custom services) into `bot/custom`. -2. Edit DFF script at `bot/script.py`. +2. Edit Chatsky script at `bot/script.py`. 3. Save Telegram bot token into `secrets/tg_token.txt`. (currently this template only supports telegram bots) ### Test the bot diff --git a/services/bot/Dockerfile b/services/bot/Dockerfile index 8bfb995..e54fdf4 100644 --- a/services/bot/Dockerfile +++ b/services/bot/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 FROM python as base -WORKDIR /dff_pipeline +WORKDIR /chatsky_pipeline COPY requirements.txt requirements.txt RUN ["python", "-m", "pip", "install", "-r", "requirements.txt"] diff --git a/services/bot/bot/custom/conditions.py b/services/bot/bot/custom/conditions.py index a5cc376..000d740 100644 --- a/services/bot/bot/custom/conditions.py +++ b/services/bot/bot/custom/conditions.py @@ -1,4 +1,4 @@ -from dff.script import Context +from chatsky.script import Context def is_upper_case(ctx: Context, pipeline): diff --git a/services/bot/bot/pipeline.py b/services/bot/bot/pipeline.py index 0320587..b0a3b66 100644 --- a/services/bot/bot/pipeline.py +++ b/services/bot/bot/pipeline.py @@ -1,8 +1,8 @@ import os -from dff.pipeline import Pipeline -from dff.context_storages import context_storage_factory -from dff.messengers.telegram import PollingTelegramInterface +from chatsky.pipeline import Pipeline +from chatsky.context_storages import context_storage_factory +from chatsky.messengers.telegram import LongpollingInterface from . import script @@ -24,7 +24,7 @@ def get_variable(var_name: str): messenger_interface = None if TG_BOT_TOKEN is not None: - messenger_interface = PollingTelegramInterface(token=TG_BOT_TOKEN) + messenger_interface = LongpollingInterface(token=TG_BOT_TOKEN) pipeline = Pipeline.from_script( diff --git a/services/bot/bot/script.py b/services/bot/bot/script.py index 6dbc2d4..9473119 100644 --- a/services/bot/bot/script.py +++ b/services/bot/bot/script.py @@ -1,6 +1,6 @@ -from dff.script import Message -from dff.script import RESPONSE, TRANSITIONS, LOCAL -from dff.script.conditions import exact_match, true +from chatsky.script import Message +from chatsky.script import RESPONSE, TRANSITIONS, LOCAL +from chatsky.script.conditions import exact_match, true from .custom.conditions import is_upper_case from .custom.services import pre_service, post_service @@ -11,7 +11,7 @@ "technical_flow": { "start_node": { TRANSITIONS: { - ("main_flow", "greeting_node"): exact_match(Message("/start")), + ("main_flow", "greeting_node"): exact_match("/start"), }, }, "fallback": { diff --git a/services/bot/requirements.txt b/services/bot/requirements.txt index b32017f..397ec3a 100644 --- a/services/bot/requirements.txt +++ b/services/bot/requirements.txt @@ -1,2 +1,2 @@ -dff[telegram,sqlite]~=0.7 +chatsky[telegram,sqlite]~=0.8 pytest \ No newline at end of file diff --git a/services/bot/test.py b/services/bot/test.py index 94f51e1..3fe9478 100644 --- a/services/bot/test.py +++ b/services/bot/test.py @@ -1,8 +1,7 @@ from json import load from pathlib import Path -from dff.utils.testing import check_happy_path -from dff.script import Message +from chatsky.utils.testing import check_happy_path import pytest from .bot.pipeline import pipeline @@ -22,4 +21,4 @@ "happy_path", TEST_CASES ) def test_happy_paths(happy_path: str): - check_happy_path(pipeline, tuple(map(lambda l: (Message(text=l[0]), Message(text=l[1])), TEST_DATA[happy_path]))) + check_happy_path(pipeline, TEST_DATA[happy_path])