Skip to content

Commit 46a5ef1

Browse files
committed
добавил возможность использования config.js
1 parent 87427c4 commit 46a5ef1

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

bin/agi.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/node
22
const program = require('commander');
3+
const path = require('path');
34
const Voicer = require('./../apps/agi/index');
45

56
program
@@ -8,7 +9,8 @@ program
89
.option('-t, --type [type]', 'recognition service type, like google, yandex, witai')
910
.option('-k, --key [key]', 'recognition service auth key')
1011
.option('-d, --path [path]', 'path to peernames.json')
11-
.helpOption('-h, --help', 'read more information');
12+
.option('-c, --config [config]', 'path to config.js')
13+
.helpOption('-h, --help', 'read more information')
1214

1315
program.parse(process.argv);
1416

@@ -17,19 +19,27 @@ if (!program.port) {
1719
// program.help();
1820
}
1921

20-
let config = {
21-
agi: {
22-
port: program.port || 3000,
23-
},
24-
record: { directory: program.records || '/var/records', type: 'wav', duration: 3 },
25-
recognize: {
26-
directory: program.records || '/var/records',
27-
type: program.type || 'witai', // ['yandex', 'google', 'witai']
28-
options: {
29-
developer_key: program.key || '6SQV3DEGQWIXW3R2EDFUMPQCVGOEIBCR',
22+
let config;
23+
24+
if (program.config) {
25+
if (path.resolve(program.config)) {
26+
config = require(program.config);
27+
}
28+
} else {
29+
config = {
30+
agi: {
31+
port: program.port || 3000,
32+
},
33+
record: { directory: program.records || '/var/records', type: 'wav', duration: 3 },
34+
recognize: {
35+
directory: program.records || '/var/records',
36+
type: program.type || 'witai', // ['yandex', 'google', 'witai']
37+
options: {
38+
developer_key: program.key || '6SQV3DEGQWIXW3R2EDFUMPQCVGOEIBCR',
39+
},
3040
},
31-
},
32-
};
41+
};
42+
}
3343

3444
// console.log('config', config);
3545
const voicer = new Voicer(config);

0 commit comments

Comments
 (0)