0

I am developing an api.ai bot that will search for the Vendor name in the database.

a ) if vendor exist -> provide username -> provide password

b) if vendor doesn't exist -> (add vendor -> yes ) or (add vendor -> No)

I have a webhook which is checking the vendor exist in database or not .

Bot Scenario: (Example )

Case1:

User: Do Alpha exist as a vendor?
Bot: yes, Alpha exist in Database. Please Provide User Name.
User: abc@gmail.com
Bot: Please Provide Password?
User: abcdef
Bot : Welcome

Case 2:

User: Do Beta exist as a vendor ?
Bot: No Beta is not a vendor. Do you want to Register?

Case 1:
       User: Yes
       Bot: Please fill this Form.
Case 2:
       User: No
       Bot: Is there any other way I can help

One thing I have figured out, I have to use output context to trigger the intent. But how can I do it in this complex case? and how can I call multiple to follow up intent using Output Context?

I might be using a bad approach, Is there any other way to solve this ?

I do have a follow-up question.

  • when we pass the fulfillment response back to dialogue flow. The response print on bot console will be the default text response, how can I get "fulfillmentText" to be the Response.

Thank you Guys. This is the followup Intent scenario.

enter image description here

Prisoner
  • 49,922
  • 7
  • 53
  • 105
Ayush Agrawal
  • 75
  • 2
  • 10

1 Answers1

2

This is not complex, you are doing it wrong by having two intents for collecting username/password.

Try the following way

enter image description here

When you detect that your vendor is present - set the context in webhook, as say, "vendor-present"

When the vendor is not present - set the context in webhook, as say, "vendor-new"

Use lifespan (the number at the left side of the context) to set the lifetime or validity of the context.

Create a separate intent for existing vendor - say "Vendor Data Collection" for collecting username and password. Set input context as "vendor-present" in the Dialogflow. Here you will collect these as parameters in the same intent (see image below). Mark these parameters as 'required' so that they must be collected by your bot. Use the Prompt section to put your response question for collecting information like "Please provide username".

enter image description here enter image description here If the vendor is not present, use existing intents and set input context as "vendor-new" in the Dialogflow.

Now, few things to note - the username parameter can be collected using the system entity @sys.given-name. But it is not very accurate with the Non-American/English names. I am not sure if this is improved or not. Secondly, there is no system entity to collect passwords, so you need to set the entity as @sys.any and in the webhook, you need to use regex to extract passwords on your own. BTW - you are not supposed to share passwords!

Hope this helped you!

Abhinav Tyagi
  • 5,158
  • 3
  • 30
  • 60
  • where should i make the bot to ask me "Please provide username". – Ayush Agrawal Jul 19 '18 at 15:53
  • see the image.. use the Prompts on the right of the parameters. You can put response there. Or if using the webhook, enable slot filing and send the response from webhook. – Abhinav Tyagi Jul 19 '18 at 15:55
  • I have to send a response from webhook also, "Vendor Exist in Database", Then ask the follow up question "Please Provide the Username " , How can i do that ? – Ayush Agrawal Jul 19 '18 at 15:56
  • add lifespan also "outputContexts":[ { "name":"Vendor-Present", "lifespanCount":5, "parameters":{ "param":"param value" } } ] – Abhinav Tyagi Jul 20 '18 at 08:46
  • Hi, this is what I am sending back as my Fulfillment Response: `return{ "fulfillmentText":speech, "source":"Check_Vendor", "outputContexts": [{ "name": "Vendor-Present", "parameters": {}, }], }` And I am getting: Webhook call failed. Error: Webhook response was empty. – Ayush Agrawal Jul 20 '18 at 08:46
  • Better to use some client like NodeJS client for your webhook. Playing with JSON is a bit complicated. client libraries will help a lot in development and reduce efforts and time. – Abhinav Tyagi Jul 20 '18 at 08:48
  • So, i figured out the issues, If we are responding with Fullfullment in V2 dialogue flow, output context should be of the Format `Format: projects//agent/sessions//contexts/` – Ayush Agrawal Jul 22 '18 at 12:47