Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alvagi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
alvagi
Commits
19444536
Commit
19444536
authored
Jul 05, 2015
by
antirek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add commands object with rules for args
parent
8eacaa0b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
398 additions
and
211 deletions
+398
-211
command.js
lib/command.js
+354
-0
commandB.js
lib/commandB.js
+17
-0
context.js
lib/context.js
+25
-209
index.js
test/index.js
+2
-2
No files found.
lib/command.js
0 → 100644
View file @
19444536
module
.
exports
=
[
{
name
:
"
exec
"
,
command
:
"
EXEC
"
,
params
:
10
},
{
name
:
"
databaseDel
"
,
command
:
"
DATABASE DEL
"
,
params
:
2
},
{
name
:
"
databaseDelTree
"
,
command
:
"
DATABASE DELTREE
"
,
params
:
2
},
{
name
:
"
databaseGet
"
,
command
:
"
DATABASE GET
"
,
params
:
2
},
{
name
:
"
databasePut
"
,
command
:
"
DATABASE PUT
"
,
params
:
3
},
{
name
:
"
speechCreate
"
,
command
:
"
SPEECH CREATE
"
,
params
:
1
},
{
name
:
"
speechDestroy
"
,
command
:
"
SPEECH DESTROY
"
,
params
:
0
},
{
name
:
"
speechActivateGrammar
"
,
command
:
"
SPEECH ACTIVATE GRAMMAR
"
,
params
:
1
},
{
name
:
"
speechDeactivateGrammar
"
,
command
:
"
SPEECH DEACTIVATE GRAMMAR
"
,
params
:
1
},
{
name
:
"
speechLoadGrammar
"
,
command
:
"
SPEECH LOAD GRAMMAR
"
,
params
:
2
},
{
name
:
"
speechUnloadGrammar
"
,
command
:
"
SPEECH UNLOAD GRAMMAR
"
,
params
:
1
},
{
name
:
"
speechSet
"
,
command
:
"
SPEECH SET
"
,
params
:
2
},
{
name
:
"
speechRecognize
"
,
command
:
"
SPEECH RECOGNIZE
"
,
params
:
3
},
{
name
:
"
getVariable
"
,
command
:
"
GET VARIABLE
"
,
params
:
1
},
{
name
:
"
getFullVariable
"
,
command
:
"
GET FULL VARIABLE
"
,
params
:
2
},
{
name
:
"
getData
"
,
command
:
"
GET DATA
"
,
params
:
3
},
{
name
:
"
getOption
"
,
command
:
"
GET OPTION
"
,
params
:
3
,
paramRules
:
[
null
,
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
receiveChar
"
,
command
:
"
RECEIVE CHAR
"
,
params
:
1
},
{
name
:
"
receiveText
"
,
command
:
"
RECEIVE TEXT
"
,
params
:
1
},
{
name
:
"
setAutoHangup
"
,
command
:
"
SET AUTOHANGUP
"
,
params
:
1
},
{
name
:
"
setCallerID
"
,
command
:
"
SET CALLERID
"
,
params
:
1
},
{
name
:
"
setContext
"
,
command
:
"
SET CONTEXT
"
,
params
:
1
},
{
name
:
"
setExtension
"
,
command
:
"
SET EXTENSION
"
,
params
:
1
},
{
name
:
"
setPriority
"
,
command
:
"
SET PRIORITY
"
,
params
:
1
},
{
name
:
"
setMusic
"
,
command
:
"
SET MUSIC
"
,
params
:
1
},
{
name
:
"
setVariable
"
,
command
:
"
SET VARIABLE
"
,
params
:
2
,
paramRules
:
[
null
,
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
sendImage
"
,
command
:
"
SEND IMAGE
"
,
params
:
1
},
{
name
:
"
sendText
"
,
command
:
"
SEND TEXT
"
,
params
:
1
,
paramRules
:
[
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
channelStatus
"
,
command
:
"
CHANNEL STATUS
"
,
params
:
1
},
{
name
:
"
answer
"
,
command
:
"
ANSWER
"
,
params
:
0
},
{
name
:
"
verbose
"
,
command
:
"
VERBOSE
"
,
params
:
2
,
paramRules
:
[
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
tddMode
"
,
command
:
"
TDD MODE
"
,
params
:
1
},
{
name
:
"
noop
"
,
command
:
"
NOOP
"
,
params
:
0
},
{
name
:
"
gosub
"
,
command
:
"
GOSUB
"
,
params
:
4
},
{
name
:
"
recordFile
"
,
command
:
"
RECORD FILE
"
,
params
:
7
,
paramRules
:
[
{
default
:
"
#
"
,
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
},
null
,
null
,
{
prepare
:
function
(
value
)
{
return
value
*
1000
;
}
}
]
},
{
name
:
"
sayNumber
"
,
command
:
"
SAY NUMBER
"
,
params
:
2
,
paramRules
:
[
null
,
{
default
:
"
#
"
,
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
sayAlpha
"
,
command
:
"
SAY ALPHA
"
,
params
:
2
,
paramRules
:
[
null
,
{
default
:
"
#
"
,
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
sayDate
"
,
command
:
"
SAY DATE
"
,
params
:
2
,
paramRules
:
[
null
,
{
default
:
"
#
"
,
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
sayTime
"
,
command
:
"
SAY TIME
"
,
params
:
2
,
paramRules
:
[
null
,
{
default
:
"
#
"
,
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
sayDateTime
"
,
command
:
"
SAY DATETIME
"
,
params
:
4
,
paramRules
:
[
null
,
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
sayDigits
"
,
command
:
"
SAY DIGITS
"
,
params
:
2
,
paramRules
:
[
null
,
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
}
}
]
},
{
name
:
"
sayPhonetic
"
,
command
:
"
SAY PHONETIC
"
,
params
:
2
,
paramRules
:
[
null
,
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
controlStreamFile
"
,
command
:
"
CONTROL STREAM FILE
"
,
params
:
7
},
{
name
:
"
streamFile
"
,
command
:
"
STREAM FILE
"
,
params
:
2
,
paramRules
:
[
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
},
{
prepare
:
function
(
value
)
{
return
'
"
'
+
value
+
'
"
'
;
}
}
]
},
{
name
:
"
waitForDigit
"
,
command
:
"
WAIT FOR DIGIT
"
,
params
:
1
},
{
name
:
"
hangup
"
,
command
:
"
HANGUP
"
,
params
:
0
},
{
name
:
"
asyncAGIBreak
"
,
command
:
"
ASYNCAGI BREAK
"
,
params
:
0
}
];
\ No newline at end of file
lib/commandB.js
0 → 100644
View file @
19444536
var
commands
=
require
(
'
./command
'
);
console
.
log
(
commands
);
var
q
=
{};
commands
.
map
(
function
(
command
)
{
q
[
command
.
name
]
=
function
()
{
var
args
=
[].
slice
.
call
(
arguments
,
0
,
command
.
params
);
return
command
.
command
+
"
"
+
args
.
join
(
"
"
);
};
});
console
.
log
(
q
.
databaseDel
(
"
1
"
,
"
2
"
,
"
3
"
,
"
4
"
));
console
.
log
(
q
.
databaseDelTree
(
"
1
"
,
"
2
"
,
"
3
"
,
"
4
"
));
console
.
log
(
commands
.
length
)
\ No newline at end of file
lib/context.js
View file @
19444536
...
...
@@ -2,6 +2,7 @@ var Readable = require('readable-stream');
var
EventEmitter
=
require
(
'
events
'
).
EventEmitter
;
var
state
=
require
(
'
./state
'
);
var
Q
=
require
(
'
q
'
);
var
commands
=
require
(
'
./command
'
);
var
Context
=
function
(
stream
,
debug
)
{
EventEmitter
.
call
(
this
);
...
...
@@ -119,218 +120,33 @@ Context.prototype.onEvent = function (event) {
return
defer
.
promise
;
};
Context
.
prototype
.
exec
=
function
()
{
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
0
);
return
this
.
sendCommand
(
'
EXEC
'
+
args
.
join
(
'
'
));
};
Context
.
prototype
.
dial
=
function
(
num
,
timeout
,
params
)
{
return
this
.
exec
(
'
Dial
'
,
num
+
'
,
'
+
timeout
+
'
,
'
+
params
);
};
Context
.
prototype
.
databaseDel
=
function
(
family
,
key
)
{
return
this
.
sendCommand
(
'
DATABASE DEL
'
+
family
+
'
'
+
key
);
};
Context
.
prototype
.
databaseDelTree
=
function
(
family
,
keytree
)
{
return
this
.
sendCommand
(
'
DATABASE DELTREE
'
+
family
+
'
'
+
keytree
);
};
Context
.
prototype
.
databaseGet
=
function
(
family
,
key
)
{
return
this
.
sendCommand
(
'
DATABASE GET
'
+
family
+
'
'
+
key
);
};
Context
.
prototype
.
databasePut
=
function
(
family
,
key
,
value
)
{
return
this
.
sendCommand
(
'
DATABASE PUT
'
+
family
+
'
'
+
key
+
'
'
+
value
);
};
Context
.
prototype
.
speechCreate
=
function
(
engine
)
{
return
this
.
sendCommand
(
'
SPEECH CREATE
'
+
engine
);
};
Context
.
prototype
.
speechDestroy
=
function
()
{
return
this
.
sendCommand
(
'
SPEECH DESTROY
'
);
};
Context
.
prototype
.
speechActivateGrammar
=
function
(
name
)
{
return
this
.
sendCommand
(
'
SPEECH ACTIVATE GRAMMAR
'
+
name
);
};
Context
.
prototype
.
speechDeactivateGrammar
=
function
(
name
)
{
return
this
.
sendCommand
(
'
SPEECH DEACTIVATE GRAMMAR
'
+
name
);
};
Context
.
prototype
.
speechLoadGrammar
=
function
(
name
,
path
)
{
return
this
.
sendCommand
(
'
SPEECH LOAD GRAMMAR
'
+
name
+
'
'
+
path
);
};
Context
.
prototype
.
speechUnloadGrammar
=
function
(
name
)
{
return
this
.
sendCommand
(
'
SPEECH UNLOAD GRAMMAR
'
+
name
);
};
Context
.
prototype
.
speechSet
=
function
(
name
,
value
)
{
return
this
.
sendCommand
(
'
SPEECH SET
'
+
name
+
'
'
+
value
);
};
Context
.
prototype
.
speechRecognize
=
function
(
prompt
,
timeout
,
offset
)
{
return
this
.
sendCommand
(
'
SPEECH RECOGNIZE
'
+
prompt
+
'
'
+
timeout
+
'
'
+
offset
);
};
Context
.
prototype
.
getVariable
=
function
(
name
)
{
return
this
.
sendCommand
(
'
GET VARIABLE
'
+
name
);
};
Context
.
prototype
.
getFullVariable
=
function
(
variable
,
channel
)
{
return
this
.
sendCommand
(
'
GET FULL VARIABLE
'
+
variable
+
'
'
+
channel
);
};
Context
.
prototype
.
getData
=
function
(
file
,
timeout
,
maxdigits
)
{
return
this
.
sendCommand
(
'
GET DATA
'
+
file
+
'
'
+
timeout
+
'
'
+
maxdigits
);
};
Context
.
prototype
.
getOption
=
function
(
file
,
escape_digits
,
timeout
)
{
return
this
.
sendCommand
(
'
GET OPTION
'
+
file
+
'
"
'
+
escape_digits
+
'
"
'
+
timeout
);
};
Context
.
prototype
.
receiveChar
=
function
(
timeout
)
{
return
this
.
sendCommand
(
'
RECEIVE CHAR
'
+
timeout
);
};
Context
.
prototype
.
receiveText
=
function
(
timeout
)
{
return
this
.
sendCommand
(
'
RECEIVE TEXT
'
+
timeout
);
};
Context
.
prototype
.
setAutoHangup
=
function
(
seconds
)
{
return
this
.
sendCommand
(
'
SET AUTOHANGUP
'
+
seconds
);
};
Context
.
prototype
.
setCallerID
=
function
(
number
)
{
return
this
.
sendCommand
(
'
SET CALLERID
'
+
number
);
};
Context
.
prototype
.
setContext
=
function
(
context
)
{
return
this
.
sendCommand
(
'
SET CONTEXT
'
+
context
);
};
Context
.
prototype
.
setExtension
=
function
(
extension
)
{
return
this
.
sendCommand
(
'
SET EXTENSION
'
+
extension
);
};
Context
.
prototype
.
setPriority
=
function
(
priority
)
{
return
this
.
sendCommand
(
'
SET PRIORITY
'
+
priority
);
};
Context
.
prototype
.
setMusic
=
function
(
musicclass
)
{
return
this
.
sendCommand
(
'
SET MUSIC
'
+
musicclass
);
};
Context
.
prototype
.
setVariable
=
function
(
name
,
value
)
{
return
this
.
sendCommand
(
'
SET VARIABLE
'
+
name
+
'
"
'
+
value
+
'
"
'
);
};
Context
.
prototype
.
sendImage
=
function
(
image
)
{
return
this
.
sendCommand
(
'
SEND IMAGE
'
+
image
);
};
Context
.
prototype
.
sendText
=
function
(
text
)
{
return
this
.
sendCommand
(
'
SEND TEXT "
'
+
text
+
'
"
'
);
};
Context
.
prototype
.
channelStatus
=
function
(
name
)
{
return
this
.
sendCommand
(
'
CHANNEL STATUS
'
+
name
);
};
Context
.
prototype
.
answer
=
function
()
{
return
this
.
sendCommand
(
'
ANSWER
'
);
};
Context
.
prototype
.
verbose
=
function
(
message
,
level
)
{
return
this
.
sendCommand
(
'
VERBOSE "
'
+
message
+
'
"
'
+
level
);
};
Context
.
prototype
.
tddMode
=
function
(
value
)
{
return
this
.
sendCommand
(
'
TDD MODE
'
+
value
);
};
Context
.
prototype
.
noop
=
function
(
cb
)
{
return
this
.
sendCommand
(
'
NOOP
'
);
};
Context
.
prototype
.
gosub
=
function
(
context
,
extension
,
priority
,
option
)
{
var
str
=
[
context
,
extension
,
priority
,
option
].
join
(
'
'
);
return
this
.
sendCommand
(
'
GOSUB
'
+
str
);
};
Context
.
prototype
.
recordFile
=
function
(
filename
,
format
,
escape_digits
,
timeout
,
offset
,
beep
,
silence
)
{
var
str
=
[
'
"
'
+
filename
+
'
"
'
,
format
,
escape_digits
,
parseInt
(
timeout
)
*
1000
,
offset
,
beep
,
silence
].
join
(
'
'
);
return
this
.
sendCommand
(
'
RECORD FILE
'
+
str
);
};
Context
.
prototype
.
sayNumber
=
function
(
number
,
escape_digits
)
{
return
this
.
sendCommand
(
'
SAY NUMBER
'
+
number
+
'
"
'
+
escape_digits
+
'
"
'
);
};
Context
.
prototype
.
sayAlpha
=
function
(
number
,
escape_digits
)
{
return
this
.
sendCommand
(
'
SAY ALPHA
'
+
number
+
'
"
'
+
escape_digits
+
'
"
'
);
};
Context
.
prototype
.
sayDate
=
function
(
seconds
,
escape_digits
)
{
//seconds since 1.01.1970
return
this
.
sendCommand
(
'
SAY DATE
'
+
seconds
+
'
"
'
+
escape_digits
+
'
"
'
);
};
Context
.
prototype
.
sayTime
=
function
(
seconds
,
escape_digits
)
{
//seconds since 1.01.1970
return
this
.
sendCommand
(
'
SAY TIME
'
+
seconds
+
'
"
'
+
escape_digits
+
'
"
'
);
};
Context
.
prototype
.
sayDateTime
=
function
(
seconds
,
escape_digits
,
format
,
timezone
)
{
//seconds since 1.01.1970
return
this
.
sendCommand
(
'
SAY DATETIME
'
+
seconds
+
'
"
'
+
escape_digits
+
'
"
'
+
format
+
'
'
+
timezone
);
};
Context
.
prototype
.
sayDigits
=
function
(
digits
,
escape_digits
)
{
return
this
.
sendCommand
(
'
SAY DIGITS
'
+
digits
+
'
"
'
+
escape_digits
+
'
"
'
);
};
Context
.
prototype
.
sayPhonetic
=
function
(
string
,
escape_digits
)
{
return
this
.
sendCommand
(
'
SAY PHONETIC
'
+
string
+
'
"
'
+
escape_digits
+
'
"
'
);
};
Context
.
prototype
.
controlStreamFile
=
function
(
filename
,
escape_digits
,
skipms
,
ffchar
,
rewchr
,
pausechr
,
offsetms
)
{
var
str
=
[
filename
,
escape_digits
,
skipms
,
ffchar
,
rewchr
,
pausechr
,
offsetms
].
join
(
"
"
);
return
this
.
sendCommand
(
'
CONTROL STREAM FILE
'
+
str
);
};
Context
.
prototype
.
streamFile
=
function
(
filename
,
digits
)
{
var
acceptDigits
=
digits
?
digits
:
"
1234567890#*
"
;
return
this
.
sendCommand
(
'
STREAM FILE "
'
+
filename
+
'
" "
'
+
acceptDigits
+
'
"
'
);
};
Context
.
prototype
.
waitForDigit
=
function
(
timeoutIn
)
{
var
timeout
=
timeoutIn
?
timeoutIn
:
5000
;
return
this
.
sendCommand
(
'
WAIT FOR DIGIT
'
+
timeout
);
};
Context
.
prototype
.
hangup
=
function
()
{
return
this
.
sendCommand
(
'
HANGUP
'
);
};
Context
.
prototype
.
asyncAGIBreak
=
function
()
{
return
this
.
sendCommand
(
'
ASYNCAGI BREAK
'
);
};
commands
.
map
(
function
(
command
)
{
var
str
=
''
;
Context
.
prototype
[
command
.
name
]
=
function
()
{
if
(
command
.
params
>
0
)
{
var
args
=
[].
slice
.
call
(
arguments
,
0
,
command
.
params
);
str
=
command
.
command
+
"
"
+
prepareArgs
(
args
,
command
.
paramRules
).
join
(
"
"
);
}
else
{
str
=
command
.
command
;
}
return
this
.
sendCommand
(
str
);
};
});
var
prepareArgs
=
function
(
args
,
argsRules
){
var
q
;
if
(
argsRules
)
{
q
=
args
.
map
(
function
(
arg
,
i
)
{
return
(
argsRules
[
i
])
?
argsRules
[
i
].
prepare
(
arg
)
:
arg
;
});
}
else
{
q
=
args
;
}
return
q
;
}
module
.
exports
=
Context
;
\ No newline at end of file
test/index.js
View file @
19444536
...
...
@@ -417,7 +417,7 @@ describe('Context', function() {
describe
(
'
waitForDigit
'
,
function
()
{
it
(
'
sends with default timeout
'
,
function
()
{
this
.
context
.
waitForDigit
();
this
.
context
.
waitForDigit
(
5000
);
expect
(
this
.
context
.
sent
.
join
(
''
)).
to
.
eql
(
'
WAIT FOR DIGIT 5000
\n
'
);
});
...
...
@@ -450,7 +450,7 @@ describe('Context', function() {
describe
(
'
verbose
'
,
function
()
{
it
(
'
sends correct command
'
,
function
()
{
this
.
context
.
verbose
(
"
good
"
,
2
);
this
.
context
.
verbose
(
'
good
'
,
2
);
expect
(
this
.
context
.
sent
.
join
(
''
)).
to
.
eql
(
'
VERBOSE "good" 2
\n
'
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment