I have some forms that asks for user details like id, age, and phone number. Now at the point of asking for user id, i want to use the id to query my database to get username, then return a question with the name of the user based on the id in the prompt or chat widget. Then the user will need to check whether the name is correct or not. If its correct the bot proceeds to the next form info (age) but if not the bot should tell the user that the id doesn’t match any name, so user should retype the id. An example conversation flow is this:
Bot: Whats is user id?
User: 2345
Bot: Is Mark James the name of the user: Yes/No
User: No
Bot: Please check the user id again
Bot: Whats is user id?
Currently, my story looks like this:
- action: id_form
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: action_validate_id_form
- intent: deny
- action: action_restart
- or:
- intent: affirm
- action: age_form
This is the action for validating id
class ActionValidateIdForm(FormValidationAction):
def name(self) -> Text:
return "action_validate_id_form"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
user_id = tracker.get_slot('id')
response_name = "Mark James"
# response_name = requests.get("https://www.noname.com/api/v1/names") # suppose to call APi but will be implemented later
buttons = [
{"title": "Yes", "payload": "/affirm", type: "postBack"},
{"title": "No", "payload": "/deny", type: "postBack"}
]
dispatcher.utter_message(text="Is {} the name of the user:".format(response_name), buttons=buttons)
return []
NB: It is highly important that its the user that validate the id form (click yes or no). That’s the requirement from the product owner