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?
@Roel in the future, could you add markdown syntax to your posts with code highlighting? That way it’s much easier to distinguish between code and text. For a tutorial on this, check out this guide.
Also, you can ping me on this forum by adding a @ in front of my alias, like @koaning.
Just so I understand the context better, what responses did you get back?
Thanks I will certainly make the post more readable. I just found out how to edit it.
Regarding the response: If I used as message one of the other intents of the various intents I have, e.g., what is the time? then the response is the actual time. So far so good.
r = requests.post("http://localhost:5002/webhooks/rest/webhook", json=payload)
Is asking a custom action to run. You should get a response with information.
You seem to expect that sending a payload to the action server causes an update in a conversation. Is this true? The action server is designed to merely respond to Rasa Open Source, it doesn’t know anything about where certain conversations are happening.
"Sensor measures dry plant"
Bot: You need to water the plant. Please let me know if you are done.
Me: I have watered the plant
Bot: That is great. Did you water the other plant too?
Me: No.
Bot: Please do so and let me know if you watered both plants.
Me: I have now watered both plants
Bot: Thank you
Thus the initiative is with the bot, based on external event. I would like to know what the best way is to accomplish this.