1 | const rp = require('request-promise-native');
|
2 |
|
3 | module.exports = function(configUrl) {
|
4 | const objrequest = {};
|
5 |
|
6 | objrequest.getEntities = function(id) {
|
7 |
|
8 | const obj = Object.assign({ url: configUrl + 'dialogflow/entities/' + id });
|
9 | return rp(obj);
|
10 | };
|
11 |
|
12 | objrequest.getEntity = function(id) {
|
13 |
|
14 | const obj = Object.assign({ url: configUrl + 'entities/' + id });
|
15 | return rp(obj);
|
16 | };
|
17 |
|
18 | objrequest.getKeywordsFromEntity = function(entityModel) {
|
19 | return new Promise(resolve => {
|
20 | const executor = async () => {
|
21 | const entity = await objrequest.getEntity(entityModel.id);
|
22 |
|
23 | let data = [];
|
24 |
|
25 | entity.entries.forEach(item => {
|
26 | data = data.concat(item.synonyms);
|
27 | });
|
28 |
|
29 | resolve({ key: entity, data: data });
|
30 | };
|
31 |
|
32 | executor();
|
33 | });
|
34 | };
|
35 | return objrequest;
|
36 | };
|