Set slot value in custom action

Hey

My goal is to set the slot value directly in my custom action.

stories.md

## story_greet      
* greet 
 - action_check_working_hours
 -  slot{"service_time" : "online"}
 - utter_introduction
 - utter_how_can_I_help_you 

## story_greet_2      
* greet 
 - action_check_working_hours
 - slot{"service_time" : "offline"}
-  utter_bye

## more_stories
*how_much
- utter_money

domain.yml

intents:
 - greet
 - how_much

slots:
  service_time:
    type: categorial 
    values:
    - online
    - offline  

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."

-utter_bye:
- text: "Goodbye"

actions.py

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 = dt.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, we are offline.'
            service='offline'
            #service=tracker.get_slot('online')
        else:
            message = 'We are open. How can I help you?'
            service='online'
            #service=tracker.get_slot('offline')
    
        dispatcher.utter_message(message)
        #return []
        return[SlotSet("service_time", service)]

Problem:

I get this error message: TypeError: 'NoneType' object is not callable

I guess, the way I set my slots is not correct. Can anybody help me with that?

Are you importing Slotset into your actions.py?

We’re gonna need bigger stacktrace here. Which line throws this error exactly?

As an aside, why is there 18pm? Why even mix 24 hour clock and AM/PM?

@akshay2000 I think this was my fault. I have provided an example of comparing different times for the Thread Opener and I think he copy pasted this sample :slight_smile:

@Chatbot_Ra As already questioned - do you import:

from rasa_sdk.events import SlotSet

? If not, you should do it. This won’t work:

service=tracker.get_slot(‘online’)

because your slot is service_time and you are calling it upon a value of the slot but I think as you commented it out, you already got that.

The least I could assume is, that you are not import:

import datetime as dt

? If this does not solve your problem, we need more information!

Regards

Hey

Thank you all very much for your help.

Yes, I have imported from rasa_sdk.events import SlotSet.

I found my problem. Its was a stupid misstake.

If you look closely, I wrote:

slots:
  service_time:
    type: categorial 
    values:
    - online
    - offline  

However, correct would be:

slots:
  service_time:
    type: categorical
    values:
    - online
    - offline  

Do you spot the difference? :slight_smile:

I think my problem is solved. Thank you very much for your help!!!

@Chatbot_Ra a missing c in categorial :smiley: