Home / DialogFlow / How to create new Dialogflow agent programmatically
DialogFlow

How to create new Dialogflow agent programmatically

Some people have asked me if it is possible to programmatically create a new Dialogflow agent. Until recently, this wasn’t possible. But Dialogflow recently added a method to their v2 API which allows this.

  1. Disclaimer

    This tutorial tells you how to achieve a specific task. If you blindly follow this tutorial without understanding the ramifications for your billing/resource quote etc. then you are solely responsible for the outcomes.

  2. Login to your Google cloud account

    If you remain logged in to your Google Cloud account, all these steps will go faster.

  3. Go to the agent creation documentation page

    First go to the appropriate link. This is the page which describes the next steps.
    Notice that you have an API explorer on the right side.

  4. Go to Google Cloud console and create a new project

    Log in to your Google Cloud Console. Click on “Create new project”

  5. Copy the project ID

    You need to get the projectID and not the project name.

  6. Go the API explorer browser window and paste the project ID

    Type the following in the API explorer textbox called parent (See image):
    projects/<project-id>

  7. Go the Request body textbox and click on the plus sign

    You will see that there is a dropdown with some kind of intellisense inside the Request body textbox.

  8. Add a field for the displayName

    This will become the name of your agent.

  9. Click on the Execute button

    Scroll down and click on the Execute button at the bottom of the page.

  10. Authenticate with the API explorer

    You will also give permission to the API explorer to execute these commands on your account’s behalf.

  11. Verify that you get a success message

    If you see a success message, your new Dialogflow agent has been created.

  12. Now do the same from your code

    Remember that everything you can do from the API explorer can also be done programmatically.

Now, there are a few things we haven’t considered here.

Can we use an existing projectID to create a new agent? (No, because it will overwrite it)

Can we create multiple agents per project using this method? (No, for the same reason as above)

How can we automatically create a new Google cloud project in the first place so we can automate the whole thing end to end?

You can follow similar steps and use this API method, but make sure you really understand the ramifications of creating new Google Cloud projects on your billing and quote etc.

FREE COURSES

Related Posts