3

I want to take the user inputs through api.ai(dialog flow) chatbot and store it in MySQL database like asking the user details of name, age, contact num through chatbot and then the user details are to be stored in my database i.e.., MySQL database. After storing, at last, the chatbot should show the summary to the user for confirmation. I am able to interact and continue the conversation with my chatbot but unable to store the user's inputs.

I was searching at different places but I can't get the right process. I am comfortable with PHP to get the data from api.ai and to store in MySQL database.

Any help would be appreciated. "Thanks in Advance!"

Phani Sai Ram
  • 47
  • 3
  • 10

1 Answers1

2

You need to create a webhook to handle fulfillment from Dialogflow. This will be a publicly accessible URL that can take an HTTPS POST, with a JSON body. In your case, this will be your Heroku URL that you will enter into the Fulfillment tab in Dialogflow.

See https://dialogflow.com/docs/fulfillment for information about the JSON you are sent, the JSON you'll need to reply with, and other information you need to setup fulfillment.

In your PHP code - you can do whatever you want with the data being sent to you, including storing it in MySQL. You'll then send back JSON (see the above URL for the format) indicating how you want to reply to the user.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Hi @Prisoner, that was really nice and yeah I have my webhook enabled public url which was deployed in heroku, now where should I use this in PHP to get json data so that I can decode json data and send it to my MYSQL database. Please help me with it. – Phani Sai Ram Dec 09 '17 at 09:43
  • Also, Am I with the right URL? Is it the URL generated using Heroku? or Dialogflow(my agent)? Please help me with it. """"Thanks in Advance!""" – Phani Sai Ram Dec 09 '17 at 09:58
  • I updated my answer to clarify a little, but the URL will be entered into Dialogflow's Fulfillment tab. Your PHP that runs at this location will get the JSON. – Prisoner Dec 09 '17 at 12:22
  • I uploaded my index.php file into Heroku and generated an URL, I placed that URL in fulfillment tab of Dialogflow. I enabled web demo in integrations in dialogflow and opened to test it. When I replied with "hi" I put the disiplayText parameter of json as "hello am from Heroku". But it was giving "Webhook call failed. Error: 500 Internal Server Error". This is my PHP file, (https://www.dropbox.com/s/gciu8mjxz3ngb2d/index.php?dl=0) Please help me with it. – Phani Sai Ram Dec 09 '17 at 12:45