initial checkin

This commit is contained in:
Dave Horton
2021-02-17 20:06:23 -05:00
commit 87b8e5ac92
29 changed files with 3321 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
{
"dial": {
"actionHook": "http://example.com",
"callerId": "+1312888899",
"target": [
{
"type": "foo",
"number": "sip:1617333456@sip.trunk1.com",
"auth": {
"user": "foo",
"password": "bar"
}
}
]
}
}
+4
View File
@@ -0,0 +1,4 @@
{
"key1": "value",
"key2": "value"
}
+1
View File
@@ -0,0 +1 @@
[1, 2]
+5
View File
@@ -0,0 +1,5 @@
{
"sip:decline": {
"status": "hello"
}
}
@@ -0,0 +1,15 @@
{
"dial": {
"actionHook": "http://example.com",
"callerId": "+1312888899",
"target": [
{
"type": "sip",
"number": "sip:1617333456@sip.trunk1.com",
"auth": {
"password": "bar"
}
}
]
}
}
+3
View File
@@ -0,0 +1,3 @@
{
"foo": "bar"
}
+6
View File
@@ -0,0 +1,6 @@
{
"sip:decline": {
"status": 480,
"foo": "bar"
}
}
+31
View File
@@ -0,0 +1,31 @@
[
{
"verb": "gather",
"actionHook": "https://00dd977a.ngrok.io/gather",
"input": ["speech"],
"timeout": 12,
"recognizer": {
"vendor": "google",
"language": "en-US",
"hints": ["sales", "support", "engineering", "human resources", "HR", "operator", "agent"]
},
"say": {
"text": "Please say the name of the department that you would like to speak with. To speak to an operator, just say operator.",
"synthesizer": {
"vendor": "google",
"language": "en-US"
}
}
},
{
"verb": "say",
"text": "I'm sorry, I did not hear a response. Goodbye.",
"synthesizer": {
"vendor": "google",
"language": "en-US"
}
},
{
"verb": "hangup"
}
]
+21
View File
@@ -0,0 +1,21 @@
{
"dial": {
"actionHook": "http://example.com",
"callerId": "+1312888899",
"target": [
{
"type": "phone",
"number": "+15083084809"
}
],
"listen": {
"url": "wss://myrecorder.example.com:4433",
"mixType" : "stereo",
"sampleRate": 8000,
"passDtmf": true,
"metadata": {
"clientId": "12udih"
}
}
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"dial": {
"actionHook": "http://example.com",
"callerId": "+1312888899",
"target": [
{
"type": "phone",
"number": "+15083084809"
}
]
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"dial": {
"actionHook": "http://example.com",
"callerId": "+1312888899",
"target": [
{
"type": "sip",
"number": "sip:1617333456@sip.trunk1.com",
"auth": {
"username": "foo",
"password": "bar"
}
}
]
}
}
+21
View File
@@ -0,0 +1,21 @@
{
"dial": {
"actionHook": "http://example.com",
"callerId": "+1312888899",
"target": [
{
"type": "phone",
"number": "+15083084809"
}
],
"transcribe": {
"transcriptionHook": "/transcribe",
"recognizer": {
"vendor": "google",
"language" : "en-US",
"dualChannel" : true,
"interim": true
}
}
}
}
+12
View File
@@ -0,0 +1,12 @@
{
"dial": {
"actionHook": "http://example.com",
"callerId": "+1312888899",
"target": [
{
"type": "user",
"name": "spike@sip.example.com"
}
]
}
}
+5
View File
@@ -0,0 +1,5 @@
{
"pause": {
"length": 3
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"say": {
"text": ["hi there", "John"],
"synthesizer": {
"vendor": "google",
"language": "en-US"
}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"say": {
"text": "hi there",
"synthesizer": {
"vendor": "google",
"language": "en-US"
}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"sip:decline": {
"status": 480,
"reason": "Gone Fishin",
"headers": {
"Retry-After": 300
}
}
}
+54
View File
@@ -0,0 +1,54 @@
const test = require('blue-tape');
const assert = require('assert');
const fetchData = (json) => {
const keys = Object.keys(json);
return json[keys[0]];
}
test('unit tests', (t) => {
const WebhookResponse = require('..').WebhookResponse;
let app = new WebhookResponse();
app.sip_decline(fetchData(require('./data/good/sip-decline')));
t.pass('sip_decline: passes');
app.say(fetchData(require('./data/good/say')));
t.pass('say: passes');
app.say(fetchData(require('./data/good/say-text-array')));
t.pass('say: passes with array of text');
app.pause(fetchData(require('./data/good/pause')));
t.pass('pause: passes with array of text');
app.dial(fetchData(require('./data/good/dial-sip')));
t.pass('dial: passes with target sip');
app.dial(fetchData(require('./data/good/dial-phone')));
t.pass('dial: passes with target phone');
app.dial(fetchData(require('./data/good/dial-user')));
t.pass('dial: passes with target user');
app.dial(fetchData(require('./data/good/dial-listen')));
t.pass('dial: passes with embedded listen');
//let payload = app.toJSON();
//console.log(payload);
//let task = makeTask(logger, require('./data/good/sip-decline'));
//t.ok(task.name === 'sip:decline', 'parsed sip:decline');
//t.throws(errInvalidInstruction, /malformed jambonz application payload/, 'throws error for invalid instruction');
//t.throws(errUnknownProperty, /unknown property/, 'throws error for invalid instruction');
//t.throws(errMissingProperty, /missing value/, 'throws error for missing required property');
//t.throws(errInvalidType, /invalid data type/, 'throws error for invalid data type');
//t.throws(errBadEnum, /must be one of/, 'throws error for invalid enum');
//t.throws(errBadPayload, /malformed jambonz application payload/, 'throws error for invalid payload with multiple keys');
//t.throws(errBadPayload2, /malformed jambonz application payload/, 'throws error for invalid payload that is not an object');
t.end();
});
const errInvalidInstruction = () => makeTask(logger, require('./data/bad/unknown-instruction'));
const errUnknownProperty = () => makeTask(logger, require('./data/bad/unknown-property'));
const errMissingProperty = () => makeTask(logger, require('./data/bad/missing-required-property'));
const errInvalidType = () => makeTask(logger, require('./data/bad/invalid-type'));
const errBadEnum = () => makeTask(logger, require('./data/bad/bad-enum'));
const errBadPayload = () => makeTask(logger, require('./data/bad/bad-payload'));
const errBadPayload2 = () => makeTask(logger, require('./data/bad/bad-payload2'));