pablocom
pablocom

Reputation: 141

Enable webhook for all intents

I would like to know if there is any way to activate the webhook for all intents (other than activating it one by one). Thank you!

Upvotes: 4

Views: 499

Answers (3)

sid8491
sid8491

Reputation: 6800

There is no such functionality as of now, but I had similar problem and this is how I solved it:

  1. Download the zip file of all the intents
  2. Write a program (I wrote in python) to go through all files (ignoring files that ends with usersays
  3. change "webhookUsed": false, to "webhookUsed": true,
  4. Upload the zip file replacing existing intents using Restore from zip option

UPDATE 1:
Below is the code:

import zipfile
import json
import os
import glob

cwd = os.getcwd()

zip_ref = zipfile.ZipFile(cwd + '/filename.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)

Place the zip file you get from dialogflow in the directory same as where you place above code and run the python program.
After running this code, navigate to directory named zipped and zip all the contents of the file and follow step 4.

UPDATE 2:
Updated the code to make it compatible to multiple languages Dialogflow agent.

Hope it helps.

Upvotes: 4

pablocom
pablocom

Reputation: 141

@sid8491 thank you so much, this worked for me!

I had to make some changes so that it worked correctly. Your answer has been very helpful. This is my final script:

import zipfile
import json
import os
import glob

cwd = os.getcwd()


zip_ref = zipfile.ZipFile(cwd + '/Bill.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, encoding="utf8").read())
        json_data['webhookUsed'] = True
        with open(file, 'w') as outfile:
            json.dump(json_data, outfile)
    else:
        print("Usersay file", file)

Upvotes: 0

Prisoner
Prisoner

Reputation: 50711

Aside from activating it one by one, or downloading the zip file, setting it one by tone in the JSON, and uploading the results - no.

Upvotes: 1

Related Questions