How to create stories or flow based api action

I am trying to create a banking chat bot

where i need one of the story for balance inquiry.

If the customer is having single account i can simply continue with the flow. But there are cases where the customer can have multiple accounts. So for that purpose to find out weather the customer is having multiple accounts or not … i need to do a small api call … If there are multiple accounts for the customer i need ask for last 4 digits of account number and match with account number that i got from api call and then proceed.

What is the best way of writing or handling this situation ? If it was only a single account the story would be straight forward. I am facing difficulty for the usage for multiple account

Here is a small flow that i could think of

balenq_path

  • greet
    • utter_greet
  • inform{“facility_type”: “bal_enq”}
    • find_bal_enq
    • utter_bal
  • thankyou
    • utter_noworries

how would flow look like if there are multiple accounts and i have a api to find weather person is having multiple accounts or not. If there is multiple account i have to utter a message and ask them for last 4 digits of account number that they wish to find balance for.

How can i fit these two situations in a flow. or is there any other way of handing it ? (BTW this is my first project on rasa)

One of the possible solutions is to add custom action after utter_greet that would query an api and set a slot whether account is unique. Then create 2 different stories depending on whether the slot value is true or false

Hi @Ghostvv i intuitively got what you were trying to tell and thanks.

Can you write a small snippet for the 2 stories and a dummy custom action which sets the slot. I’m new to framework and this is my first project.

Thanks @Ghostvv For idea

I figured out my self … In case if anyone needs the same. Here are small snippets of code

dummy custom action:

from rasa_sdk.actions import Action
from rasa_sdk.events import SlotSet
import requests

class FetchProfileAction(Action):
    def name(self):
        return "fetch_profile"

    def run(self, dispatcher, tracker, domain):
        url = "http://myprofileurl.com"
        data = requests.get(url).json
        return [SlotSet("account_type", data["account_type"])]

stories file

# story_01
* greet
  - action_fetch_profile
  - slot{"account_type" : "multiple"}
  - utter_multiple_accounts
  - utter_enter_last_4_digits
* last_4_digits_entered
  - action_balance_api

# story_02
* greet
  - action_fetch_profile
  - slot{"account_type" : "single"}
  - action_balance_api

And finally the domain

slots:
   account_type:
      type: categorical
      values:
      - single
      - multiple

Need to change the values based on our needs

1 Like