Dialogflow Chatbot Generator (from decision tree)

This script generates an agent zip file that can be directly imported into DialogFlow.

Getting Started

CSV File

The CSV file represents a decision tree. The flow of the conversation will be determined through this decision tree. The first line of the CSV file must contain the following header:

Questions,Yes,No,Clarification,Unique Identifier

Questions: The question to prompt the user with
Yes (Optional): What the chatbot should reply with if the user replied with yes
No (Optional): What the chatbot should reply with if the user replied with no
Clarification (Optional): What the chatbot should reply with if the user requests clarification or expresses confusion. Some examples of a user input that would cause the chatbot to reply with this clarification would be "Can you elaborate?", "What is that?", "I'm a bit confused"
If Yes and No are left blank, it indicates that the flow of the conversation should move to the next line of the CSV file regardless of what a user inputs. If you choose to do this, you must manually specify training phrases in your DialogFlow Agent
Unique Identifier: A unique short (~1-8 words) text that uniquely identifies each question

The following is an example of a decision tree and its corresponding CSV file

Decision Tree

Questions,Yes,No,Clarification,Unique Identifier
What’s your name?,,,What name should I call you by?,name
What is your email?,,,,email
Do you like Asian food?,1 line down,Eat some pasta,Asian food refers to Asian cuisine. Is this something you enjoy eating?,asian food
Do you like Chinese food?,Eat some dumplings,Eat some ramen,,chinese food

The following is an example of a conversation between a user and a chatbot made from the above CSV file

User    : Hi
Chatbot : What's your name?
User    : My name is Ryan
Chatbot : What is your email?
User    : It's myname@example.com
Chatbot : Do you like Asian food?
User    : Huh?
Chatbot : Asian food refers to Asian cuisine. Is this something you enjoy eating?
User    : Oh. Yes, I like Asian cuisine
Chatbot : Do you like Chinese food?
User    : Not really
Chatbot : Eat some ramen   

How to run script

  1. Update the questions-formatted.csv file provided in the root directory
  2. In your terminal, navigate to the root directory of the chatbot generator
  3. Run python3 chatbot-generator.py to generate the agent files. This will generate a target folder containing a chatbot.zip file and a chatbot folder. The zip file will be imported directly into DialogFlow, and the chatbot folder contains the files and directories in the zip file (this folder can be ignored)
  4. If you plan to utilise webhooks/fulfillment, then in chatbot-generator.py, change the value of WEBHOOK_USED to True. This will generate the same chatbot files as in step 3, but will automatically enable Fulfillment in the chatbot files generated and will generate an additional agent.js file in the target folder. This file can be used as boilerplate for your webhook server.

How to import into DialogFlow

  1. Log in to your DialogFlow account then create a new agent
  2. Navigate to agent settings then navigate to Export and Import
  3. Click Restore from zip then select the chatbot.zip file that was generated by the script. Type RESTORE then click the Restore button.
    Warning: If you are using a preexisting agent, this step will replace the current agent version with a new one. All the intents and entities in the older version will be deleted.

Generated Dialogflow Agent Notes

Some useful notes about your agent

  1. All intents that end with ...- Initial (except the Welcome Intent) requires your to manually enter training phrases in the DialogFlow console. These training phrases correspond to the intent's input context.
    E.g. if the input context is "contact-name", the training phrases might include "the contact name is Ryan", "his name is John" etc.
  2. In the agent code generated, mongoUtil is a utility class used to configure a MongoDB connection. Likewise, var db is our MongoDB database connection that was started in our mongoUtil module. These variables will likely not be relevant to you, and it is safe to remove these lines.

Author

License

This project is licensed under the MIT License- see the LICENSE.md file for details