forked from tonydiaz/wa-react-native-minimal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssistant.js
More file actions
39 lines (35 loc) · 924 Bytes
/
Assistant.js
File metadata and controls
39 lines (35 loc) · 924 Bytes
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
import base64 from 'react-native-base64'
import { USERNAME, PASSWORD, URL, SKILL_ID } from 'react-native-dotenv'
// Watson Assistant API documentation:
// https://console.bluemix.net/apidocs/assistant
MessageRequest = (input, context = {}) => {
let body = {
alternate_intents: true,
input: {
'text': input
}
};
if (context) {
body.context = context;
}
return fetch(URL + '/v1/workspaces/' + SKILL_ID + '/message?version=2018-09-20', {
method: 'POST',
headers: {
Authorization: 'Basic ' + base64.encode(USERNAME + ":" + PASSWORD),
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
})
.then((response) => response.json())
.then((responseJson) => {
// console.log(responseJson);
return responseJson;
})
.catch((error) => {
console.error(error);
});
}
module.exports = {
MessageRequest
}