-
Notifications
You must be signed in to change notification settings - Fork 0
/
abbott-app-client.js
58 lines (50 loc) · 1.59 KB
/
abbott-app-client.js
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
const fetch = require('node-fetch');
const readline = require('readline');
const util = require('util');
// const baseAddress = 'http://localhost:3000';
const baseAddress = 'https://abbott-platform-info-botapp-dot-ciandt-cognitive-sandbox.appspot.com';
const makeRequest = (message) => {
const abbottWebhook = `${baseAddress}/abbott/receive?collectPipeData=true`;
var payload = {
query: message,
originalRequest: {
source: 'abbott',
user: {
userId: 123456
}
}
};
return fetch(abbottWebhook, {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
}).then((res) => {
return res.json();
}).then((res) => {
return res.message;
});
};
console.log('Hi, i\'am the Abbott Platform Chat, You can exit this chat any time just saying "exit"! Let\'s talk...\n');
process.stdout.write('YOU: ');
var rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false });
rl.on('line', function (line) {
if (line === 'exit') {
console.log('Exiting the chat...');
// These two lines together allow the program to terminate. Without
// them, it would run forever.
rl.close();
process.stdin.destroy();
} else {
makeRequest(line).then((res) => {
process.stdout.write(`ABBOTT: ${res.text}\n\n`);
if (res.pipeData) {
process.stdout.write('ABBOTT (PIPE-DATA): \n');
console.log(util.inspect(res.pipeData, {depth: null, colors: true}));
process.stdout.write('\n\n');
}
process.stdout.write('YOU: ');
});
}
});