I would like to initiate a story from a Python program, based on an external event. This is inspired by the example Reminderbot from @koaning . Assume I have rasa server and rasa actions running.
Assume I have a Python program main.py as follows:
import requests
def do_stuff():
pass
def sensor_plant():
# "reads sensor plant"
event_plant_dry = True
return event_plant_dry
def do_more_stuff():
pass
def run():
do_stuff()
event_plant_dry = sensor_plant()
if event_plant_dry:
payload = {"intent": "EXTERNAL_dry_plant"}
r = requests.post("http://localhost:5002/webhooks/rest/webhook", json=payload)
# expected response Your plant needs water! Let me know if you are done.
print(str(r.json()))
do_more_stuff()
if __name__ == "__main__":
run()
Assume I have an Python program actions.py as follows:
from rasa_sdk import Action, Tracker
from typing import Any, Text, Dict, List, TextIO, Union
from rasa_sdk.executor import CollectingDispatcher
class ActionWarnDry(Action):
"""Informs the user that a plant needs water."""
def name(self) -> Text:
return "action_warn_dry"
async def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict[Text, Any]]:
dispatcher.utter_message("Your plant needs water! Let me know if you are done.")
return []
Further yml files include the following:
nlu.yml no specific additions as in reminderbot
rules.yml:
- rule: warn dry plant
steps:
- intent: EXTERNAL_dry_plant
- action: action_warn_dry
domain.yml
intents:
- EXTERNAL_dry_plant
- all other intents as in reminderbot
actions:
- action_warn_dry
- all other actions as in reminderbot
stories.yml
- story: water the plant
steps:
- intent: EXTERNAL_dry_plant
- action: action_warn_dry
Then if I run main.py, I would expect the response r to be “Your plant needs water! Let me know if you are done”
However, I get a different unrelated response. Do I need to change the payload, and if so how, to trigger the desired response “Your plant needs water! Let me know if you are done”, which should allow to proceed the dialogue? A second question would be: are the story and rule definitions not redundant?