Skip to content

Commit 6998a47

Browse files
committed
add dialplan vars
1 parent 60b3c1c commit 6998a47

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

example/config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ module.exports = {
55
processing: {
66
totalAttempts: 2,
77
playGreeting: true,
8-
playBeepBeforeRecording: true //use system beep
8+
playBeepBeforeRecording: false //use system beep
99
},
1010
asterisk: {
1111
sounds: {
1212
onErrorBeforeFinish: 'invalid',
1313
onErrorBeforeRepeat: 'invalid',
1414
greeting: 'tt-monkeysintro'
15+
},
16+
recognitionDialplanVars: {
17+
result: 'RECOGNITION_RESULT',
18+
channel: 'RECOGNITION_CHANNEL'
1519
}
1620
},
1721
record: {

lib/configSchema.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ var ConfigSchema = Joi.object().keys({
1616
onErrorBeforeFinish: Joi.string(),
1717
onErrorBeforeRepeat: Joi.string(),
1818
greeting: Joi.string()
19+
}).required(),
20+
recognitionDialplanVars: Joi.object().keys({
21+
result: Joi.string().required(),
22+
channel: Joi.string().required()
1923
}).required()
2024
}).required(),
2125
record: Joi.object().keys({

lib/handler.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var Handler = function (source, recognizer, config) {
1010
var counter = 1;
1111
var logger;
1212
var sounds = config.asterisk['sounds'];
13+
var dialplanVars = config.asterisk['recognitionDialplanVars'];
1314

1415
var getCallId = function () {
1516
var length = 7;
@@ -101,11 +102,25 @@ var Handler = function (source, recognizer, config) {
101102
return contextWrapper.streamFile(sounds['onErrorBeforeRepeat'], '#');
102103
};
103104

105+
var stepSuccess = function (object) {
106+
console.log(object);
107+
log('stepSuccess', object);
108+
return contextWrapper.setVariable(dialplanVars['result'], 'SUCCESS')
109+
.then(function () {
110+
return contextWrapper.setVariable(dialplanVars['channel'], object.channel);
111+
});
112+
};
113+
114+
var stepSetFailedVars = function () {
115+
log('stepSetFailedVars');
116+
return contextWrapper.setVariable(dialplanVars['result'], 'FAILED');
117+
};
118+
104119
var FlowProcess = function () {
105120
return stepRecord()
106121
.then(stepRecognize)
107122
.then(stepLookup)
108-
.then(stepDial)
123+
.then(stepSuccess)
109124
.then(stepFinish)
110125
};
111126

@@ -135,7 +150,8 @@ var Handler = function (source, recognizer, config) {
135150
contextWrapper.on('variables')
136151
.then(function () {
137152
log('-- start processing');
138-
return stepGreeting();
153+
return stepSetFailedVars()
154+
.then(stepGreeting);
139155
})
140156
.then(function () {
141157
return loop(FlowProcess);

spec/HandlerSpec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ describe('Handler', function () {
2727
};
2828

2929
var logger = {
30-
info: function (module, callId, message, object){
31-
//console.log(module, callId, message, object);
32-
}
30+
info: function (module, callId, message, object) {}
3331
};
3432

3533
var config = {
@@ -108,8 +106,8 @@ describe('Handler', function () {
108106
handler.handle(context);
109107
});
110108

111-
it('should use context dial method', function (done) {
112-
context.dial = function (channel) {
109+
it('should use context setVariable method', function (done) {
110+
context.setVariable = function (varname, value) {
113111
done();
114112
};
115113
handler.handle(context);

0 commit comments

Comments
 (0)