This repository was archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgoogleDF.py
More file actions
46 lines (34 loc) · 2.39 KB
/
googleDF.py
File metadata and controls
46 lines (34 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import requests
from configBot import *
def addIntentAndUtteranceDF(DFIntent,DFUtterances):
url = "https://console.dialogflow.com/api/intents"
string=[{"isTemplate":False,"data":[{"text":DFUtterances[i]}],"count":0,"id":None,"updated":None}
for i in range(len(DFUtterances))]
#Training utterances have to be sent in the above format. Hence saved for all trian utterances in a string and passed it on the payload.
payload = {"name":DFIntent,"auto":True,"contexts":[],"templates":[],"responses":[{"parameters":[],"resetContexts":False,"affectedContexts":[],"messages":[],"speech":[],"defaultResponsePlatforms":{}}],"source":None,"priority":500000,"cortanaCommand":{"navigateOrService":"NAVIGATE","target":""},"events":[],"userSays":string}
headers = {
'authorization': "Bearer "+Token_DF,#Fetched from config file.
'content-type': "application/json;charset=UTF-8",
}
try:
response = requests.post( url, json=payload, headers=headers,params= {"lang":lang.replace("_","-")})
addFallbackIntent()
except:
raise Exception("Error while adding intent and utterances for google")
def addFallbackIntent():
url = "https://console.dialogflow.com/api/intents"
querystring ={"lang":lang.replace("_","-")}
payload = "{\"name\":\"Default Fallback Intent\",\"auto\":true,\"contexts\":[],\"templates\":[],\"responses\":[{\"parameters\":[],\"resetContexts\":false,\"affectedContexts\":[],\"messages\":[{\"type\":0,\"speech\":[]}],\"speech\":[],\"defaultResponsePlatforms\":{}}],\"source\":null,\"priority\":500000,\"cortanaCommand\":{\"navigateOrService\":\"NAVIGATE\",\"target\":\"\"},\"fallbackIntent\":true,\"events\":[],\"followupEvent\":null,\"endInteraction\":false,\"userSays\":[]}"
headers = {
'authorization': "Bearer "+Token_DF,#Fetched from config file.
'content-type': "application/json;charset=UTF-8",
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
def getIntentsInBot():
url = "https://console.dialogflow.com/api/intents"
headers = {
'authorization': "Bearer "+botIdDF,
'cookie': "zUserAccessToken=55222461-14c3-4d71-ad86-39df2d2b6a81"
}
response = requests.get( url, headers=headers)
print(response.text)