-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteIntents.ts
More file actions
63 lines (54 loc) · 1.81 KB
/
deleteIntents.ts
File metadata and controls
63 lines (54 loc) · 1.81 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import axios from 'axios'
import * as limit from 'simple-rate-limiter'
const dialogFlowAPIBasePath = 'https://api.dialogflow.com/v1'
const intentsEndpoint = '/intents'
const versioningParam = '?v=20170712'
const DEVELOPER_ACCESS_TOKEN = process.argv[2] === 'prod' ? '249f1ae954f0421ab2b3e84979d066fa' : '4e911d4bfbce43dbbc7cda08bcead4c8'
const intentsToDeletePerCall = 50;
axios({
method: 'get',
url: dialogFlowAPIBasePath + intentsEndpoint + versioningParam,
headers: {
'Authorization': 'Bearer ' + DEVELOPER_ACCESS_TOKEN
}
})
.then((resp) => {
console.log(`Starting deletion of ${resp.data.length} intents`)
deleteIntents(resp.data);
})
.catch((err) => {
console.log(err.response.data)
})
function deleteIntents(intents: any) {
const deleteIntentFromDialogflow = limit((intentId, index) => {
axios({
method: 'delete',
url: dialogFlowAPIBasePath + intentsEndpoint + '/' + intentId + versioningParam,
headers: {
'Authorization': 'Bearer ' + DEVELOPER_ACCESS_TOKEN
}
})
.then(() => {
console.log(`Deleted intent ${index}`);
})
.catch((err) => {
console.log(err.response.status, err.response.statusText)
})
}).to(45).per(1000*60)
intents.forEach((intent, index) => {
if(!intent.name.includes('Default')) {
deleteIntentFromDialogflow(intent.id, index)
}
})
// const intents2DList = _.chunk(intents, intentsToDeletePerCall)
// await intents2DList.forEach((intentsList, index) => {
// setTimeout(async (intentsList, index) => {
// console.log(`Deleting Intents of sublist ${index}`)
// await intentsList.forEach(async (intent, intentIndex) => {
// if(intent.name.indexOf('Default') == -1){
//
// }
// })
// }, index*30000, intentsList, index)
// })
}