import json import requests # Please insert the ID of the Virtual Agent here # This ID can be found in the URL -> https://trial.cognigy.ai/agent/ AGENT ID /621dffb3213dea7525d38b7a agentId = "" # Please insert the Cognigy API Key here apiKey = "" # Read the JSON content of the downloaded IBM Watson file fileName = "Credit-Card-dialog.json" file = open(fileName) fileJSON = json.load(file) # Initialize the list of intents that will be uploaded to Cognigy.AI intents = [] # Create a new Flow in Cognigy.AI flowResponse = requests.post("https://api-trial.cognigy.ai/new/v2.0/flows?api_key={}".format(apiKey), { "name": fileName.replace(".json", ""), "context": {}, "attachedFlows": [], "attachedLexicons": [], "img": "", "projectId": agentId }, { "Content-Type": "application/json", "Accept": "application/json" }) flowResponse = flowResponse.json() # Loop through all existing IBM Watson intents for intent in fileJSON["intents"]: # Create a new intent inside of the NLU intentReponse = requests.post("https://api-trial.cognigy.ai/new/v2.0/flows/{}/intents?api_key={}".format(flowResponse["_id"], apiKey), { "name": intent["intent"], "rules": [], "tags": [], "confirmationSentences": [], "condition": "", "disambiguationSentence": "", "childFeatures": False, "parent": "", }, { "Content-Type": "application/json", "Accept": "application/json" }) intentReponse = intentReponse.json() # Add all example sentences to the new intent for exampleSentence in intent["examples"]: exampleSentenceResponse = requests.post("https://api-trial.cognigy.ai/new/v2.0/flows/{}/intents/{}/sentences?api_key={}".format(flowResponse["_id"], intentReponse["_id"], apiKey), { "text": exampleSentence["text"], "slots": [] }, { "Content-Type": "application/json", "Accept": "application/json" }) print("\nCongratulations!\nAll IBM Watson intents were successfully uploaded to the Cognigy.AI virtual agent with the ID {}\n".format(agentId))