-
Notifications
You must be signed in to change notification settings - Fork 1
/
Discovery_Function.json
59 lines (59 loc) · 1.55 KB
/
Discovery_Function.json
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
/**
*
* @param {object} params
* @param {string} params.iam_apikey
* @param {string} params.url
* @param {string} params.username
* @param {string} params.password
* @param {string} params.environment_id
* @param {string} params.collection_id
* @param {string} params.configuration_id
* @param {string} params.input
*
* @return {object}
*
*/
const assert = require('assert');
const DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
/**
*
* main() will be run when you invoke this action
*
* @param Cloud Functions actions accept a single parameter, which must be a JSON object.
*
* @return The output of this action, which must be a JSON object.
*
*/
function main(params) {
return new Promise(function (resolve, reject) {
let discovery;
if (params.iam_apikey){
discovery = new DiscoveryV1({
'iam_apikey': params.iam_apikey,
'url': params.url,
'version': '2019-03-25'
});
}
else {
discovery = new DiscoveryV1({
'username': params.username,
'password': params.password,
'url': params.url,
'version': '2019-03-25'
});
}
discovery.query({
'environment_id': params.environment_id,
'collection_id': params.collection_id,
'natural_language_query': params.input,
'passages': true,
'count': 3,
'passages_count': 3
}, function(err, data) {
if (err) {
return reject(err);
}
return resolve(data);
});
});
}