Exemplo n.º 1
0
def test_json_parse_followup():
    # DOCS MARKER FollowupAction
    evt = \
        {
            'event': 'followup',
            'name': 'my_action'
        }
    # DOCS END
    assert Event.from_parameters(evt) == FollowupAction("my_action")
Exemplo n.º 2
0
    def run(self, dispatcher: LineDispatcher, tracker, domain):
        medicine_list = tracker.get_slot("medicine_list")
        medicine_reminders = tracker.get_slot("medicine_reminders")
        time_tuple = dispatcher.reminder_data.get("time_tuple")

        if medicine_list and medicine_reminders and time_tuple:
            medicine_to_remind = []

            # Time and Meal text to send push
            time_text = medicine_reminders[time_tuple]["time_text"]
            if time_tuple[1]:
                meal_text = " " + medicine_reminders[time_tuple]["meal_text"]
            else:
                meal_text = ""

            for medicine in medicine_list:
                times = medicine["time"].split("_")
                meal = medicine["meal"]
                for time in times:
                    if (time, meal) == time_tuple:
                        medicine_to_remind.append(medicine["name"])

            number_to_remind = len(medicine_to_remind)
            if number_to_remind > 0:
                if number_to_remind == 1:  # For one medicine, send as one line text
                    text = "สวัสดีค่ะ คุณทาน{} ตอน{}{} หรือยังคะ".format(
                        medicine_to_remind[0], time_text, meal_text)
                else:  # For multiple medicines, send them as a list
                    text = "สวัสดีค่ะ คุณทาน\n"
                    for medicine in medicine_to_remind:
                        text += "❥ " + medicine + "\n"
                    text += "ตอน{}{} หรือยังคะ".format(
                        time_text, meal_text)
                dispatcher.line_template(
                    "line_medicine_reminder_push", tracker, text=text)
            medicine_reminders[time_tuple]["job_id"] = None

            return [SlotSet("medicine_reminders", medicine_reminders), FollowupAction("custom_medicine_reminder_update")]

        else:
            logger.warning("medicine_list:{}, medicine_reminders:{}, time_tuple:{}".format(
                medicine_list, medicine_reminders, time_tuple
            ))

        return []
Exemplo n.º 3
0
    def submit(self, dispatcher: LineDispatcher, tracker, domain):
        """Define what the form has to do
            after all required slots are filled"""

        medicine_list = tracker.get_slot("medicine_list")

        if medicine_list is None:
            new_medicine_list = []
        else:
            new_medicine_list = medicine_list.copy()

        new_medicine_name = tracker.get_slot("new_medicine_name")
        new_medicine_time = tracker.get_slot("new_medicine_time")
        new_medicine_meal = tracker.get_slot("new_medicine_meal")

        new_medicine_list.append({
            "name": new_medicine_name,
            "time": new_medicine_time,
            "meal": new_medicine_meal,
            "uuid": uuid.uuid4()
        })

        medicine_time_text = DEFAULT_MEDICINE_TEXT.get(
            new_medicine_time, new_medicine_time)
        medicine_meal_text = DEFAULT_MEDICINE_TEXT.get(new_medicine_meal, None)
        medicine_info_text = medicine_time_text
        medicine_info_text += " " + medicine_meal_text if medicine_meal_text else ""

        # utter submit template
        dispatcher.line_template('line_add_new_medicine_success', tracker,
                                 medicine_info_text=medicine_info_text
                                 )

        events = [
            SlotSet("medicine_list", new_medicine_list),
            SlotSet("new_medicine_name", None),
            SlotSet("new_medicine_time", None),
            SlotSet("new_medicine_meal", None),
            FollowupAction("custom_medicine_reminder_update")
        ]

        return events
Exemplo n.º 4
0
    def run(self, dispatcher: LineDispatcher, tracker, domain):

        old_medicine_list = tracker.get_slot("medicine_list")
        new_medicine_list = []

        remove_medicine_uuid = next(tracker.get_latest_entity_values(
            "remove_medicine_uuid"), None)

        removed_medicine = None
        for medicine_dict in old_medicine_list:
            if medicine_dict.get("uuid") == uuid.UUID(remove_medicine_uuid):
                removed_medicine = medicine_dict
            else:
                new_medicine_list.append(medicine_dict)

        if removed_medicine is not None:
            dispatcher.line_template(
                'line_remove_medicine_success', tracker, medicine_name=removed_medicine["name"])
        else:
            dispatcher.line_template('line_remove_medicine_already', tracker)

        return [SlotSet("medicine_list", new_medicine_list), FollowupAction("custom_medicine_reminder_update")]
Exemplo n.º 5
0
        "name": "greet",
        "confidence": 1.0
    }, []), UserUttered("/goodbye", {
        "name": "goodbye",
        "confidence": 1.0
    }, [])),
    (SlotSet("my_slot", "value"), SlotSet("my__other_slot", "value")),
    (Restarted(), None),
    (AllSlotsReset(), None),
    (ConversationPaused(), None),
    (ConversationResumed(), None),
    (StoryExported(), None),
    (ActionReverted(), None),
    (UserUtteranceReverted(), None),
    (ActionExecuted("my_action"), ActionExecuted("my_other_action")),
    (FollowupAction("my_action"), FollowupAction("my_other_action")),
    (BotUttered("my_text",
                "my_data"), BotUttered("my_other_test", "my_other_data")),
    (AgentUttered("my_text",
                  "my_data"), AgentUttered("my_other_test", "my_other_data")),
    (ReminderScheduled("my_action", datetime.now()),
     ReminderScheduled("my_other_action", datetime.now())),
])
def test_event_has_proper_implementation(one_event, another_event):
    # equals tests
    assert one_event != another_event, \
        "Same events with different values need to be different"
    assert one_event == copy.deepcopy(one_event), \
        "Event copies need to be the same"
    assert one_event != 42, \
        "Events aren't equal to 42!"