This looks great, but I think I still need some help to implement it in the right way. Please check the format of my class CheckWorkingHours!
This is what I have done:
stories.md
## story_greet
* greet
- action_check_working_hours
- utter_introduction
- utter_how_can_I_help_you
*how_much
- action_check_working_hours
- utter_money
domain.yml
intents:
- greet
- how_much
actions:
- utter_introduction
- utter_how_can_I_help_you
- utter_money
- action_check_working_hours
templates:
utter_introduction:
- text: "hi, I am your bot."
utter_how_can_I_help_you
- text: "My dear customer. How can I help you?"
utter_money:
- text: "the price is only 1 Dollar"
-utter_night:
- text: "Sorry my dear customer. Our service time starts at 7am and ends at 7 pm. This chat will end now. Please contact us later."
actions.py
from datetime import datetime
import datetime as dt
class CheckWorkingHours(Action):
def name(self): # type: () -> Text
return "action_check_working_hours"
def run(self, dispatcher, tracker, domain):
# type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict[Text, Any]]
now = datetime.datetime.now()
today18pm = now.replace(hour=18, minute=0, second=0, microsecond=0)
today13am = now.replace(hour=13, minute=0, second=0, microsecond=0)
if today13am > now < today18pm:
message = 'Sorry my dear customer. Our service time starts at 7am and ends at 7 pm. This chat will end now. Please contact us later.'
else:
message = 'How can I help you?'
dispatcher.utter_message(message)
return []
I have also changed the story in order to call the action class. Is this the correct way?
Note, I know for sure, that the customer will always start with the intent greet. This is for sure due to some other reasons. Would it be enough, if my action class will be called only at this point? If the time is in between service time, the chatbot will run as usuall. Otherwise the chatbot will ask the customer to come back later. Done!
At the moment I get the following error message:
rasa_core.actions.action - Failed to run custom action 'action_check_working_hours'. Action server responded with a non 200 status code of 500. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 500 Server Error: INTERNAL SERVER ERROR for url: http://localhost:5055/webhook
2019-06-13 14:28:51 ERROR rasa_core.processor - Encountered an exception while running action 'action_check_working_hours'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.