mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
wip
This commit is contained in:
@@ -10,6 +10,9 @@ class Dialogflow extends Task {
|
|||||||
super(logger, opts);
|
super(logger, opts);
|
||||||
this.preconditions = TaskPreconditions.Endpoint;
|
this.preconditions = TaskPreconditions.Endpoint;
|
||||||
this.credentials = this.data.credentials;
|
this.credentials = this.data.credentials;
|
||||||
|
this.model = this.data.model || 'es';
|
||||||
|
this.cmd = this.model === 'cx' ? 'dialogflow_cx_start' : 'dialogflow_start';
|
||||||
|
this.cmdStop = this.model === 'cx' ? 'dialogflow_cx_stop' : 'dialogflow_stop';
|
||||||
|
|
||||||
/* set project id with environment and region (optionally) */
|
/* set project id with environment and region (optionally) */
|
||||||
if (this.data.environment && this.data.region) {
|
if (this.data.environment && this.data.region) {
|
||||||
@@ -77,18 +80,18 @@ class Dialogflow extends Task {
|
|||||||
try {
|
try {
|
||||||
await this.init(cs, ep);
|
await this.init(cs, ep);
|
||||||
|
|
||||||
this.logger.debug(`starting dialogflow bot ${this.project}`);
|
this.logger.debug(`starting dialogflow ${this.model} bot ${this.project}`);
|
||||||
|
|
||||||
// kick it off
|
// kick it off
|
||||||
const baseArgs = `${this.ep.uuid} ${this.project} ${this.lang} ${this.welcomeEvent}`;
|
const baseArgs = `${this.ep.uuid} ${this.project} ${this.lang} ${this.welcomeEvent}`;
|
||||||
if (this.welcomeEventParams) {
|
if (this.welcomeEventParams) {
|
||||||
this.ep.api('dialogflow_start', `${baseArgs} '${JSON.stringify(this.welcomeEventParams)}'`);
|
this.ep.api(this.cmd, `${baseArgs} '${JSON.stringify(this.welcomeEventParams)}'`);
|
||||||
}
|
}
|
||||||
else if (this.welcomeEvent.length) {
|
else if (this.welcomeEvent.length) {
|
||||||
this.ep.api('dialogflow_start', baseArgs);
|
this.ep.api(this.cmd, baseArgs);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.ep.api('dialogflow_start', `${this.ep.uuid} ${this.project} ${this.lang}`);
|
this.ep.api(this.cmd, `${this.ep.uuid} ${this.project} ${this.lang}`);
|
||||||
}
|
}
|
||||||
this.logger.debug(`started dialogflow bot ${this.project}`);
|
this.logger.debug(`started dialogflow bot ${this.project}`);
|
||||||
|
|
||||||
@@ -108,6 +111,12 @@ class Dialogflow extends Task {
|
|||||||
this.ep.removeCustomEventListener('dialogflow::end_of_utterance');
|
this.ep.removeCustomEventListener('dialogflow::end_of_utterance');
|
||||||
this.ep.removeCustomEventListener('dialogflow::error');
|
this.ep.removeCustomEventListener('dialogflow::error');
|
||||||
|
|
||||||
|
this.ep.removeCustomEventListener('dialogflow_cx::intent');
|
||||||
|
this.ep.removeCustomEventListener('dialogflow_cx::transcription');
|
||||||
|
this.ep.removeCustomEventListener('dialogflow_cx::audio_provided');
|
||||||
|
this.ep.removeCustomEventListener('dialogflow_cx::end_of_utterance');
|
||||||
|
this.ep.removeCustomEventListener('dialogflow_cx::error');
|
||||||
|
|
||||||
this._clearNoinputTimer();
|
this._clearNoinputTimer();
|
||||||
|
|
||||||
if (!this.reportedFinalAction) this.performAction({dialogflowResult: 'caller hungup'})
|
if (!this.reportedFinalAction) this.performAction({dialogflowResult: 'caller hungup'})
|
||||||
@@ -141,6 +150,12 @@ class Dialogflow extends Task {
|
|||||||
this.ep.addCustomEventListener('dialogflow::end_of_utterance', this._onEndOfUtterance.bind(this, ep, cs));
|
this.ep.addCustomEventListener('dialogflow::end_of_utterance', this._onEndOfUtterance.bind(this, ep, cs));
|
||||||
this.ep.addCustomEventListener('dialogflow::error', this._onError.bind(this, ep, cs));
|
this.ep.addCustomEventListener('dialogflow::error', this._onError.bind(this, ep, cs));
|
||||||
|
|
||||||
|
this.ep.addCustomEventListener('dialogflow_cx::intent', this._onIntent.bind(this, ep, cs));
|
||||||
|
this.ep.addCustomEventListener('dialogflow_cx::transcription', this._onTranscription.bind(this, ep, cs));
|
||||||
|
this.ep.addCustomEventListener('dialogflow_cx::audio_provided', this._onAudioProvided.bind(this, ep, cs));
|
||||||
|
this.ep.addCustomEventListener('dialogflow_cx::end_of_utterance', this._onEndOfUtterance.bind(this, ep, cs));
|
||||||
|
this.ep.addCustomEventListener('dialogflow_cx::error', this._onError.bind(this, ep, cs));
|
||||||
|
|
||||||
const obj = typeof this.credentials === 'string' ? JSON.parse(this.credentials) : this.credentials;
|
const obj = typeof this.credentials === 'string' ? JSON.parse(this.credentials) : this.credentials;
|
||||||
const creds = JSON.stringify(obj);
|
const creds = JSON.stringify(obj);
|
||||||
await this.ep.set('GOOGLE_APPLICATION_CREDENTIALS', creds);
|
await this.ep.set('GOOGLE_APPLICATION_CREDENTIALS', creds);
|
||||||
@@ -171,20 +186,20 @@ class Dialogflow extends Task {
|
|||||||
if (this.noinput && this.greetingPlayed) {
|
if (this.noinput && this.greetingPlayed) {
|
||||||
this.logger.info('no input timer fired, reprompting..');
|
this.logger.info('no input timer fired, reprompting..');
|
||||||
this.noinput = false;
|
this.noinput = false;
|
||||||
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang} ${this.noInputEvent}`);
|
ep.api(this.cmd, `${ep.uuid} ${this.project} ${this.lang} ${this.noInputEvent}`);
|
||||||
}
|
}
|
||||||
else if (this.dtmfEntry && this.greetingPlayed) {
|
else if (this.dtmfEntry && this.greetingPlayed) {
|
||||||
this.logger.info('dtmf detected, reprompting..');
|
this.logger.info('dtmf detected, reprompting..');
|
||||||
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang} none \'${this.dtmfEntry}\'`);
|
ep.api(this.cmd, `${ep.uuid} ${this.project} ${this.lang} none \'${this.dtmfEntry}\'`);
|
||||||
this.dtmfEntry = null;
|
this.dtmfEntry = null;
|
||||||
}
|
}
|
||||||
else if (this.greetingPlayed) {
|
else if (this.greetingPlayed) {
|
||||||
this.logger.info('starting another intent');
|
this.logger.info('starting another intent');
|
||||||
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang}`);
|
ep.api(this.cmd, `${ep.uuid} ${this.project} ${this.lang}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.info('got empty intent');
|
this.logger.info('got empty intent');
|
||||||
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang}`);
|
ep.api(this.cmd, `${ep.uuid} ${this.project} ${this.lang}`);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -231,7 +246,7 @@ class Dialogflow extends Task {
|
|||||||
// start a new intent, (we want to continue to listen during the audio playback)
|
// start a new intent, (we want to continue to listen during the audio playback)
|
||||||
// _unless_ we are transferring or ending the session
|
// _unless_ we are transferring or ending the session
|
||||||
if (!this.hangupAfterPlayDone) {
|
if (!this.hangupAfterPlayDone) {
|
||||||
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang}`);
|
ep.api(this.cmd, `${ep.uuid} ${this.project} ${this.lang}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -389,7 +404,7 @@ class Dialogflow extends Task {
|
|||||||
// start a new intent, (we want to continue to listen during the audio playback)
|
// start a new intent, (we want to continue to listen during the audio playback)
|
||||||
// _unless_ we are transferring or ending the session
|
// _unless_ we are transferring or ending the session
|
||||||
if (/*this.greetingPlayed &&*/ !this.hangupAfterPlayDone) {
|
if (/*this.greetingPlayed &&*/ !this.hangupAfterPlayDone) {
|
||||||
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang}`);
|
ep.api(this.cmd, `${ep.uuid} ${this.project} ${this.lang}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.playInProgress = true;
|
this.playInProgress = true;
|
||||||
@@ -417,7 +432,7 @@ class Dialogflow extends Task {
|
|||||||
/*
|
/*
|
||||||
if (!this.inbound && !this.greetingPlayed) {
|
if (!this.inbound && !this.greetingPlayed) {
|
||||||
this.logger.info('finished greeting on outbound call, starting new intent');
|
this.logger.info('finished greeting on outbound call, starting new intent');
|
||||||
this.ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang}`);
|
this.ep.api(this.cmd, `${ep.uuid} ${this.project} ${this.lang}`);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
this.greetingPlayed = true;
|
this.greetingPlayed = true;
|
||||||
@@ -454,7 +469,7 @@ class Dialogflow extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// kill the current dialogflow, which will result in us getting an immediate intent
|
// kill the current dialogflow, which will result in us getting an immediate intent
|
||||||
ep.api('dialogflow_stop', `${ep.uuid}`)
|
ep.api(this.cmdStop, `${ep.uuid}`)
|
||||||
.catch((err) => this.logger.info(`dialogflow_stop failed: ${err.message}`));
|
.catch((err) => this.logger.info(`dialogflow_stop failed: ${err.message}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,7 +487,7 @@ class Dialogflow extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// kill the current dialogflow, which will result in us getting an immediate intent
|
// kill the current dialogflow, which will result in us getting an immediate intent
|
||||||
ep.api('dialogflow_stop', `${ep.uuid}`)
|
ep.api(this.cmdStop, `${ep.uuid}`)
|
||||||
.catch((err) => this.logger.info(`dialogflow_stop failed: ${err.message}`));
|
.catch((err) => this.logger.info(`dialogflow_stop failed: ${err.message}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
package-lock.json
generated
14
package-lock.json
generated
@@ -18,7 +18,7 @@
|
|||||||
"@jambonz/speech-utils": "^0.1.15",
|
"@jambonz/speech-utils": "^0.1.15",
|
||||||
"@jambonz/stats-collector": "^0.1.10",
|
"@jambonz/stats-collector": "^0.1.10",
|
||||||
"@jambonz/time-series": "^0.2.9",
|
"@jambonz/time-series": "^0.2.9",
|
||||||
"@jambonz/verb-specifications": "^0.0.76",
|
"@jambonz/verb-specifications": "^0.0.77",
|
||||||
"@opentelemetry/api": "^1.8.0",
|
"@opentelemetry/api": "^1.8.0",
|
||||||
"@opentelemetry/exporter-jaeger": "^1.23.0",
|
"@opentelemetry/exporter-jaeger": "^1.23.0",
|
||||||
"@opentelemetry/exporter-trace-otlp-http": "^0.50.0",
|
"@opentelemetry/exporter-trace-otlp-http": "^0.50.0",
|
||||||
@@ -1575,9 +1575,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@jambonz/verb-specifications": {
|
"node_modules/@jambonz/verb-specifications": {
|
||||||
"version": "0.0.76",
|
"version": "0.0.77",
|
||||||
"resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.0.76.tgz",
|
"resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.0.77.tgz",
|
||||||
"integrity": "sha512-7s61qAsG07xLLaEAHW236rSYzEoh9Qg0aRWHPbTfxCsuTKDNeq+5EwGAShDU5R5ZpjgweZJLhArQm8Ym+4xJ2A==",
|
"integrity": "sha512-reGTuBmxiiCo4eCWAtHOBT+Dm6OxZ8d2Yb9J/3scQ92oT+UHFO3U3gutEUH0qjdZAn3ogCkSmWABWn6LEqhqaA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"pino": "^8.8.0"
|
"pino": "^8.8.0"
|
||||||
@@ -10539,9 +10539,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@jambonz/verb-specifications": {
|
"@jambonz/verb-specifications": {
|
||||||
"version": "0.0.76",
|
"version": "0.0.77",
|
||||||
"resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.0.76.tgz",
|
"resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.0.77.tgz",
|
||||||
"integrity": "sha512-7s61qAsG07xLLaEAHW236rSYzEoh9Qg0aRWHPbTfxCsuTKDNeq+5EwGAShDU5R5ZpjgweZJLhArQm8Ym+4xJ2A==",
|
"integrity": "sha512-reGTuBmxiiCo4eCWAtHOBT+Dm6OxZ8d2Yb9J/3scQ92oT+UHFO3U3gutEUH0qjdZAn3ogCkSmWABWn6LEqhqaA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"pino": "^8.8.0"
|
"pino": "^8.8.0"
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
"@jambonz/speech-utils": "^0.1.15",
|
"@jambonz/speech-utils": "^0.1.15",
|
||||||
"@jambonz/stats-collector": "^0.1.10",
|
"@jambonz/stats-collector": "^0.1.10",
|
||||||
"@jambonz/time-series": "^0.2.9",
|
"@jambonz/time-series": "^0.2.9",
|
||||||
"@jambonz/verb-specifications": "^0.0.76",
|
"@jambonz/verb-specifications": "^0.0.77",
|
||||||
"@opentelemetry/api": "^1.8.0",
|
"@opentelemetry/api": "^1.8.0",
|
||||||
"@opentelemetry/exporter-jaeger": "^1.23.0",
|
"@opentelemetry/exporter-jaeger": "^1.23.0",
|
||||||
"@opentelemetry/exporter-trace-otlp-http": "^0.50.0",
|
"@opentelemetry/exporter-trace-otlp-http": "^0.50.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user