How to capture user name from watson assistant in python API

41 Views Asked by At

I want to capture user name and when the user enters the password, then I want to display his name in the result output. I have tried many if conditions but the if condition does not allow me to capture the user name if I use if condition after user name to authorize password. Please help!

intents = response['intents']
entities = response['entities']
context = response['context']

user_name_captured = False  # Initialize user_name_captured variable as False

 # Initialize user_name_captured variable as False

if entities:
    first_entity = entities[0]['entity']
    
    if first_entity == 'user_name':
        watson_response = "Please enter your password"
        User_name = payload['text']
        print(User_name)
        user_name_captured = True  # Set flag to indicate user name has been captured
    
    if first_entity == 'password':
        User_name = payload['text']  # Capture the user name from the 'password' entity
        print(User_name)
        
        if user_name_captured or User_name:  # Check if user name is already captured or captured from 'password' entity
            watson_response = f"Welcome {User_name}, please select an option to proceed or let me know what's on your mind."
        else:
            watson_response = "User name is missing. Please provide your user name first."

# Create a response payload
    # Create a response payload
    response_payload = {
        'text': watson_response
}


# Create a response payload
response_payload = {
    'text': watson_response
}
    # Return the response payload as JSON
return jsonify(response_payload)```
0

There are 0 best solutions below