0

I'm using fulfillment webhooks to store analytics data on my servers, so I need it enabled on every possible intent. So far I've been doing it by manually checking "Enable webhook call for this intent" on every intent. That is kinda dangerous though, as it would be easy to forget doing it on an intent. Is there any global way to have it enabled for all intents?

manugarciac
  • 185
  • 1
  • 12

1 Answers1

0

There is no direct way to do this, but I have made a python script to do the same.
You need to follow below steps to get it done:

  • Export your agent
    Go to settings of your agent, select Export and Import tab and select Export as zip.
    This will give you zip file of your agent
  • Put the zip file in the same folder where your python script file will be present
  • Run the python script
  • A folder named zipped will be created
  • Go inside that folder and select all the files and folders present in that folder and zip them
  • Restore your agent
    Go to settings of your agent, select Export and Import tab and select Restore from zip, select the zip file which you created in above step.

Python code:

import zipfile
import json
import os
import glob

cwd = os.getcwd()

zip_ref = zipfile.ZipFile(cwd + '/your_agent.zip', 'r')
zip_ref.extractall('zipped')
zip_ref.close()

cwd = cwd + '/zipped/intents'

files = glob.glob(cwd + "/*.json")
for file in files:
    print(file)
    if "usersay" not in file:
        json_data= json.loads(open(file).read())
        json_data['webhookUsed'] = True
        with open(file, 'w') as outfile:
            json.dump(json_data, outfile)
print('Done')

Hope it helps.

sid8491
  • 6,622
  • 6
  • 38
  • 64
  • I understand your approach. I was thinking on implementing something similar, but making use of the API to have it fully automated: https://cloud.google.com/dialogflow-enterprise/docs/reference/rest/v2/projects.agent – manugarciac Feb 20 '19 at 14:18
  • @manugarciac then either you need to create intents using API and specify to enable webhook at that time, or use update_intent API, in that give list of intent names and specify the code to enable the webhook. update_intent API can be your option here but that would be more complicated than the one i mentioned in asnwer – sid8491 Feb 20 '19 at 19:03