mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
wip: implemented listen, transcribe, play
This commit is contained in:
@@ -32,5 +32,23 @@
|
||||
"Endpoint": "endpoint",
|
||||
"StableCall": "stable-call",
|
||||
"UnansweredCall": "unanswered-call"
|
||||
},
|
||||
"TranscriptionEvents": {
|
||||
"Transcription": "google_transcribe::transcription",
|
||||
"EndOfUtterance": "google_transcribe::end_of_utterance",
|
||||
"NoAudioDetected": "google_transcribe::no_audio_detected",
|
||||
"MaxDurationExceeded": "google_transcribe::max_duration_exceeded"
|
||||
},
|
||||
"ListenEvents": {
|
||||
"Connect": "mod_audio_fork::connect",
|
||||
"ConnectFailure": "mod_audio_fork::connect_failed",
|
||||
"Transcription": "mod_audio_fork::transcription",
|
||||
"Transfer": "mod_audio_fork::transcription",
|
||||
"PlayAudio": "mod_audio_fork::play_audio",
|
||||
"KillAudio": "mod_audio_fork::kill_audio",
|
||||
"Disconnect": "mod_audio_fork::disconnect",
|
||||
"Error": "mod_audio_fork::error",
|
||||
"BufferOverrun": "mod_audio_fork::buffer_overrun",
|
||||
"JsonMessage": "mod_audio_fork::json"
|
||||
}
|
||||
}
|
||||
|
||||
33
lib/utils/normalize-jamones.js
Normal file
33
lib/utils/normalize-jamones.js
Normal file
@@ -0,0 +1,33 @@
|
||||
function normalizeJambones(logger, obj) {
|
||||
logger.debug(`normalizeJambones: ${JSON.stringify(obj)}`);
|
||||
if (!Array.isArray(obj)) throw new Error('invalid JSON: jambones docs must be array');
|
||||
const document = [];
|
||||
for (const tdata of obj) {
|
||||
if (typeof tdata !== 'object') throw new Error('invalid JSON: jambones docs must be array of objects');
|
||||
if (Object.keys(tdata).length === 1) {
|
||||
// {'say': {..}}
|
||||
logger.debug(`pushing ${JSON.stringify(tdata)}`);
|
||||
document.push(tdata);
|
||||
}
|
||||
else if ('verb' in tdata) {
|
||||
// {verb: 'say', text: 'foo..bar'..}
|
||||
const name = tdata.verb;
|
||||
const o = {};
|
||||
Object.keys(tdata)
|
||||
.filter((k) => k !== 'verb')
|
||||
.forEach((k) => o[k] = tdata[k]);
|
||||
const o2 = {};
|
||||
o2[name] = o;
|
||||
document.push(o2);
|
||||
}
|
||||
else {
|
||||
logger.info(tdata, `invalid JSON: invalid verb form, numkeys ${Object.keys(tdata).length}`);
|
||||
throw new Error('invalid JSON: invalid verb form');
|
||||
}
|
||||
}
|
||||
logger.debug(`returning document with ${document.length} tasks`);
|
||||
return document;
|
||||
}
|
||||
|
||||
module.exports = normalizeJambones;
|
||||
|
||||
@@ -11,8 +11,8 @@ function hooks(logger, callAttributes) {
|
||||
url,
|
||||
method,
|
||||
json: true,
|
||||
qs: 'GET' === method ? params : null,
|
||||
body: 'POST' === method ? params : null
|
||||
qs: 'GET' === method ? params : callAttributes,
|
||||
body: 'POST' === method ? opts : null
|
||||
};
|
||||
logger.debug(`${method} ${url} sending ${JSON.stringify(obj)}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
55
lib/utils/place-outdial.js
Normal file
55
lib/utils/place-outdial.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const Emitter = require('events');
|
||||
const {CallStatus} = require('./constants');
|
||||
|
||||
class SingleDialer extends Emitter {
|
||||
constructor(logger, opts) {
|
||||
super();
|
||||
this.logger = logger;
|
||||
this.cs = opts.cs;
|
||||
this.ms = opts.ms;
|
||||
}
|
||||
|
||||
get callState() {
|
||||
return this._callState;
|
||||
}
|
||||
|
||||
/**
|
||||
* launch the outdial
|
||||
*/
|
||||
exec() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* kill the call in progress, or stable dialog, whichever
|
||||
*/
|
||||
async kill() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* execute a jambones application on this call / endpoint
|
||||
* @param {*} jambones document
|
||||
*/
|
||||
async runApp(document) {
|
||||
|
||||
}
|
||||
|
||||
async _createEndpoint() {
|
||||
|
||||
}
|
||||
|
||||
async _outdial() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function placeOutdial(logger, opts) {
|
||||
const singleDialer = new SingleDialer(logger, opts);
|
||||
singleDialer.exec();
|
||||
return singleDialer;
|
||||
}
|
||||
|
||||
module.exports = placeOutdial;
|
||||
|
||||
Reference in New Issue
Block a user