Rasa Core - How to make strories for uniq input?

I want make my Chatbot login using database.

I make database: userId, userName, userPaket This my Action Code

class ActionCheckCustomer(Action):

def name(self): return “action_check_customer”

def run(self,dispatcher,tracker,domain): conn = sqlite3.connect(‘customer.db’) conn.row_factory = sqlite3.Row c = conn.cursor()

  userId = tracker.get_slot('userId')
  c.execute("SELECT * FROM customer WHERE userId="+userId+"")
  result= c.fetchone()

  userId = result['userId']
  userName = result['userName']
  userPaket = result['userPaket']

  response = """{} paket anda saat ini {}""".format(userName, userPaket)

  dispatcher.utter_message(response)
  return [SlotSet("userId",userId)]

Stories:

## Generated Story -7935206030812678059
  • info_paket
    • utter_verifikasinointernet
  • enter_data{“userId”: “1111”}
    • slot{“userId”: “1111”}
    • action_check_customer
    • slot{“userId”: “1111”}
  • thankyou
    • utter_thankyou

How make stories for uniq input? If the value of userId not definein stories, my bot cannt understand the input. Thankyou

You can try defining a few more UserID’s in your story with OR statements. Like so:

    info_paket
    utter_verifikasinointernet
    enter_data{“userId”: “1111”} OR enter_data{“userId”: “1211”} OR  enter_data{“userId”: “1121”} OR enter_data{“userId”: “1121”} OR enter_data{“userId”: “1112”}
    slot{“userId”: “1111”} <!----delete this, it'll set automatically----!>
    action_check_customer
    slot{“userId”: “1111”} <!----same here----!>
    thankyou
    utter_thankyou

Thanks Remy, that stories output from rasa.core.train interactive.

I have 100 userIDs in the database, should I define 100 userIDs in the story?

If you want to be absolutely sure that the bot recognises all the ID’s, yes. However, I’ve found that in a similar case in our bot, the Core model generalizes pretty well with around 7 or 8 unique examples.

is that correct if I define data.md like this

intent: enter_data

  • [1111] (userId)
  • [2222] (userId)
  • my number [3333] (userId)

yep!

edit: To add to this response. Since you have a set number of login codes, you might want to add a lookup table in your data.md file that contains all possible numbers. This trains the bot to only see these combinations as viable userID’s. it looks like this:

lookup: userID

  • 1111
  • 1112
  • 1113
  • 1114 etc.

wah thanks Remy, thats work for my Project!

solved

Sorry, I want ask again, I have intent info_package and info_bill that access slot{“userId”:“1111”},

I want to create a stories when the user asks info_package then enter useId 1111 --> slot{“userId”:“1111”} , can I access previous slot for next intent -->info_bill

I made a story like this, but it didn’t work

Generated Story Paket 3

  • info_paket
    • utter_verifikasinointernet
  • enter_data{“userId”: “1111”} OR enter_data{“userId”: “2222”} OR enter_data{“userId”: “3333”} OR enter_data{“userId”: “4444”} OR enter_data{“userId”: “5555”} OR enter_data{“userId”: “666666”}
    • action_check_customer
  • info_tagihan
    • action_check_tagihan
  • thankyou
    • utter_thankyou
    • action_slot_reset

You’ll need to handle that in you action ‘check_tagihan’. If you make that action check what value occupies the slot, the story will most likely work.

I set ‘Action_check_tagihan’ to tracker.get_slot, so like:

userId = tracker.get_slot('userId')
  c.execute("SELECT * FROM customer WHERE userId="+userId+"")
  result= c.fetchone()

  userId = result['userId']
  userName = result['userName']
  userPackage = result['userPaket']
  userBill = result['userBill']

  response = """{} paket anda saat ini {}""".format(userName, userPackage)  #this for package
  #response = """{} paket anda saat ini {}""".format(userName, userPackage)  #this for bill

  dispatcher.utter_message(response)
  return [SlotSet("userId",userId)]

This stories works:

Generated Story Tagihan

  • info_tagihan
    • utter_verifikasinointernet
  • enter_data{“userId”: “1111”} OR enter_data{“userId”: “2222”} OR enter_data{“userId”: “3333”} OR enter_data{“userId”: “4444”} OR enter_data{“userId”: “5555”} OR enter_data{“userId”: “666666”}
    • action_check_tagihan

Generated Story Tagihan

  • info_tagihan{“userId”: “1111”} OR enter_data{“userId”: “2222”} OR enter_data{“userId”: “3333”} OR enter_data{“userId”: “4444”} OR enter_data{“userId”: “5555”} OR enter_data{“userId”: “666666”}
    • action_check_package

Generated Story Paket

  • info_paket
    • utter_verifikasinointernet
  • enter_data{“userId”: “1111”} OR enter_data{“userId”: “2222”} OR enter_data{“userId”: “3333”} OR enter_data{“userId”: “4444”} OR enter_data{“userId”: “5555”} OR enter_data{“userId”: “666666”}
    • action_check_customer

but its didn’t work for

  • info_paket
    • utter_verifikasinointernet
  • enter_data{“userId”: “1111”} OR enter_data{“userId”: “2222”} OR enter_data{“userId”: “3333”} OR enter_data{“userId”: “4444”} OR enter_data{“userId”: “5555”} OR enter_data{“userId”: “666666”}
    • action_check_customer
  • info_tagihan
    • action_check_tagihan
  • thankyou
    • utter_thankyou
    • action_slot_reset

I want the user only enter_data user_id once, so if user has enter_data user_id the user can access all the next_action without enter_data user_id again