How to pass parameters to a custom action

Hi,

I need to make a Custom Action that can be configured through parameters. I have been unable to use slots for my use case. For example, I have a custom action that can open a web page in browser. But, I want it to open a different webpage on different occasions. So, I can write a story like this:

  - story: First time I want to open google.com. Second time I want to open facebook.com
    steps:
      - intent: open_browser
      - action: action_open_browser
      - intent: open_browser
      - action: action_open_browser

You can see that I am trying to use the same custom action for different use cases. Making multiple custom actions doesn’t makes sense because only the URL will be different and adding more URLs will make it impossible to scale up.

Now, what I want is to set a slot myself in the story. Or use some other technique so that I can pass in a value to my custom action to decide which URL to open. Following is an invalid story but demonstrates what I want to achieve:

  - story: First time I want to open google.com. Second time I want to open facebook.com
    steps:
      - intent: open_browser
      - set_slot: {url: google.com}
      - action: action_open_browser
      - intent: open_browser
      - set_slot: {url: facebook.com}
      - action: action_open_browser

Basically, the user (talking to the bot) cannot tell which page to visit. So, I cannot extract entities and set slots like that. I need to integrate this logic myself in stories/rules.

I have gone through this issue: How to pass parameters to a custom action · Issue #1950 · RasaHQ/rasa · GitHub But, I am unable to understand the solution of using factories - which seems like Rasa 1.x based implementation.

Also found a solution on stackoverflow which didn’t work. But, this is the kind of thing I am looking for: How can I save user preference in messenger bot built by rasa - Stack Overflow

then you can set your slot value in your stories like below.

visitor_resp{"language":"english"}

And the your language slot value is set.

Is it possible to add this kind of step in a story?

Hello @MoosaSaadat , thanks for your question!

Your use case is currently not possible in the training data. Would setting the slot in the custom action itself be an option? Depending on your different use cases, you could maintain some sort of state in the action server, and decide which URL to open after the previous N ones.

Thanks for the quick response @m-vdb

Setting the slots in the custom action won’t be helpful because the flexibility of changing URLs need to be with the person writing stories/YAML files. So, I was looking for something simple that won’t require much changes in the action server for different use cases.

Seems like maintaining states in action server is the only option for now.

Thank you for the help!