|
| 1 | +### StateMachine |
| 2 | +The `StateMachine` class is defined in the 'state_machine.py' script. It is in charge of keeping track of the current intervention state. It also receive different types of events as defined in the 'Event' class, and decides which function of the state to activate depending on the event type. |
| 3 | +6 events have been defined: |
| 4 | +- DIALOG_COMPLETED: a dialog has been completed in Rasa by the user. The completion is tracked and the logic to manage it is activated in the specific state |
| 5 | +- DIALOG_RESCHEDULED: a dialog has been rescheduled. The specific state manages the actions to take |
| 6 | +- DIALOG_STARTED: a dialog has started. The starting time and the event are tracked |
| 7 | +- NEW_DAY: a new day has started. Some of the intervention states take different actions depending on the time dimension. |
| 8 | +- USER_TRIGGER = a dialog has been triggered by the user in Rasa. The specific state manages the actions to be taken. |
| 9 | + |
| 10 | +Each user is associated with the instance of a StateMachine. |
| 11 | +The state machine is coupled with the `user_state_machine` table on the DB. Every time an event occurs, the state machine is populated with the data stored in the DB, the event is consumed, and the new parameters of the state machine are updated on the DB. |
| 12 | + |
| 13 | +### Controller |
| 14 | +In the `controller.py` each possible state is fully defined. Each state is an implementation of the abstract `State` class defined in `state.py`. Each state implements a different logic for managing the events sent by the StateMachine, and defines the rules for changing state. |
| 15 | + |
| 16 | +### celery_tasks |
| 17 | +In `celery_tasks.py` the possible celery tasks are defined and implemented. These tasks can be triggered both from Rasa and the states of the state machine. |
1 | 18 | [Celery](https://docs.celeryproject.org/en/stable/) is used to schedule tasks. |
2 | 19 |
|
3 | 20 | ## How to run |
4 | 21 | Start the main application, see instructions in [virtual-coach-main](https://github.com/PerfectFit-project/virtual-coach-main). |
5 | 22 |
|
6 | 23 | In the Docker output for the Celery worker, you should see something like below: |
7 | 24 | ``` |
8 | | -scheduler_1 | [2021-10-14 11:34:16,227: INFO/Beat] Scheduler: Sending due task trigger-rasa-reminder (celery_tasks.trigger_rasa_reminder) |
9 | | -scheduler_1 | [2021-10-14 11:34:16,232: INFO/MainProcess] Task celery_tasks.trigger_rasa_reminder[f4c08d73-b866-4640-94be-503483c8e87d] received |
10 | | -niceday_api_1 | POST /messages/ 200 0.982 ms - - |
| 25 | +scheduler_1 | [2021-10-14 11:34:16,227: INFO/Beat] Scheduler: Sending due task celery_tasks.trigger_intervention_component (celery_tasks.trigger_rasa_reminder) |
| 26 | +scheduler_1 | [2021-10-14 11:34:16,232: INFO/MainProcess] Task celery_tasks.trigger_intervention_component[f4c08d73-b866-4640-94be-503483c8e87d] received |
11 | 27 | scheduler_1 | [2021-10-14 11:34:16,400: INFO/ForkPoolWorker-2] Task celery_tasks.trigger_rasa_reminder[f4c08d73-b866-4640-94be-503483c8e87d] succeeded in 0.16701790000661276s: None |
12 | 28 | ``` |
13 | 29 | which means Celery works successfully! |
14 | | - |
15 | | -So Celery periodically sends a `EXTERNAL_trigger_ask_foreseen_hrs` intent to RASA to trigger RASA to utter `ask_foreseen_hrs` to user. |
16 | | - |
17 | | - |
18 | | -## How to manually trigger RASA? |
19 | | -Manually trigger RASA to start foreseen HRS conversation |
20 | | -``` |
21 | | -curl --location --request POST 'http://localhost:5005/conversations/38527/trigger_intent?output_channel=niceday_trigger_input_channel' \ |
22 | | ---header 'Content-Type: application/json' \ |
23 | | ---data-raw '{ |
24 | | - "name": "EXTERNAL_trigger_ask_foreseen_hrs" |
25 | | -}' |
26 | | -``` |
27 | | -You should see a big json response with something like this in it: |
28 | | -``` |
29 | | -{"tracker":{"sender_id":"Kees" ... |
30 | | - "latest_message": { |
31 | | - "intent": { |
32 | | - "name": "EXTERNAL_trigger_ask_foreseen_hrs" |
33 | | - },}]} |
34 | | -``` |
0 commit comments