Creating a single story for multiple entities based on the entity value

Hello Folks

I’m quite new to RASA and I am trying to build a chatbot on a sales domain. One functionality of the chatbot is supposed to accept a timeframe value (weekly/monthly/quarterly) and return the corresponding revenue figures

Currently, I am doing it by creating separate actions and stories for each of the timeframe values. However, there are a lot of combinations of stories, and somewhere I feel that managing these many stories would be difficult

Currently, I do not have any entities in my code. While I’m sure that I can make a timeframe as an entity and assign multiple values to it. But what I’m not sure is how do I cater to all the entities in one story itself?

Any help in the form of resources to follow or code snipped would be much appreciated

If your bot is in English, you can use duckling to extract dates or timeframes. There’s a general post on entity extraction here.

Also, the financial-demo bot is an example extracting time using duckling. Duckling also supports duration in addition to time. You can then pass this to a custom action to do the query so you don’t need a lot of stories.

Thank You @stephens for the response. The entity creation and extraction post were quite helpful!

However, one thing I am still not clear about is can we write a single story to cater to all the values of an entity?

In my case, I want to write a single story for all the entity values (weekly/monthly/quarterly). Would something like this work?

story: todays sales greet goodbye
  steps:
  - intent: begin_main_menu
  - action: utter_main_menu
  - intent: order_menu
  - action: utter_order_menu
  - intent: sales_for_a_particular_timeframe
  - action: utter_timeframe_menu
  - intent: today's_order
    entities:
    - entity_name: cs_timeframe
  - action: time_based_sales_figures
  - action: utter_timeframe_menu
  - intent: goodbye
  - action: utter_goodbye

Here, the action time_based_sales_figures is coded as follows:

class ActionTimeframeSalesFigures(Action):

    def name(self):
        return "time_based_sales_figures"

    def run(self, dispatcher, tracker, domain):
        
        timeframe = next(tracker.get_latest_entity_values("cs_timeframe", None))

        if timeframe == "today's":
            dispatcher.utter_message("Todays Sales figures are 100$")

            return []

        elif timeframe == "weekly":
            dispatcher.utter_message("Current week's sales figures are 100$")

            return []


        elif timeframe == "monthly":
            dispatcher.utter_message("Current month's sales figures are 100$")

            return []

        elif timeframe == "quarterly":
            dispatcher.utter_message("Current quarter's sales figures are 100$")

            return []

        else:
            dispatcher.utter_message("Please enter the correct timeframe")

            return []

Yes, you should be able to do this. The financial demo does something like this and there’s some useful code here.