Setting Slots within Form Action

Hi everyone! I’m trying to set slots via a Form Action but running into some trouble.

For a bit of background info, the bot’s purpose is to help users set appointments. An example conversation might look like this:

  • Bot: Hi, this is Adam from X. Are you available to chat today regarding Y?
  • User: Yes
  • Bot: Great, when works best for you?
  • User: Let’s talk tomorrow at 5pm
  • Bot: Perfect. We’ll call you tomorrow at 5!

I’m using Duckling to extract the time from messages, but the problem is sometimes (unlike the example above) users will simply say they want to talk “tomorrow” rather than a specific time such as “tomorrow at 5pm.” In these cases, we need to save tomorrow’s date, then ask for a specific time as well.

So far, my solution to handle this has been:

Create 4 slots:

  • time - this is the one Duckling will extract parsed times to
  • call_date - the date a call will happen
  • call_hhmmss - the time a call will happen
  • call_time - the full timestamp for when a call should happen

Use some custom logic in the required_slots function to determine if a date and/or time have been extracted, and save these values along the way. (Click here to see the code for my required_slots function)

However, this logic requires me to set slots along the way, and I’m not actually sure if that’s possible within the required_slots function. In my code you can see quite a few SlotSet(name, value) calls, but looking through the debugging info it appears they don’t do anything.

Some research on the forums shows SlotSet (or a list of SlotSets) is usually returned by a custom action, but I can’t return that here because the required_slots function needs to return a list of the required slots.

Is there any way I can actually set slot values on the client side from within this function? Or does anyone have any suggestions on how else I can achieve this? I believe I also saw a tracker._set_slot() function somewhere, but it looked like that only set the slots on the server-side.

Thanks everyone!

1 Like

I looked around a bit more into how I could execute custom actions while a form is active, and found this forum post in which it is suggested you override the request_next_slot function to accomplish things like this.

Is that considered good practice, or is there a better way?

For anyone else that might have this issue:

I was able to accomplish what I needed by overriding the request_next_slot() function, essentially using the same logic I was trying to use in required_slots().

1 Like

@adboio could you please detail out the solution. I am working on similar kind of problem where SlotSet isn’t working in formActions.