This commit is contained in:
Dave Horton
2024-08-20 21:27:51 -04:00
parent af958d0222
commit 8d4d09ddd3

View File

@@ -88,13 +88,9 @@ class Dialogflow extends Task {
await super.exec(cs); await super.exec(cs);
try { try {
this.logger.info('Dialogflow:exec');
await this.init(cs, ep); await this.init(cs, ep);
this.logger.info('Dialogflow:exec - initialized'); await this.startBot();
await this.startBot(ep);
this.logger.info('Dialogflow:exec - started bot');
await this.awaitTaskDone(); await this.awaitTaskDone();
this.logger.info('Dialogflow:exec - done');
} catch (err) { } catch (err) {
this.logger.error({err}, 'Dialogflow:exec error'); this.logger.error({err}, 'Dialogflow:exec error');
} }
@@ -165,28 +161,32 @@ class Dialogflow extends Task {
} }
} }
async startBot(ep) { async startBot() {
const fn = this.isCX ? this.startBotCX : this.startBotES; if (this.isCX) {
await fn(ep); await this.startBotCX();
}
async startBotES(ep) {
this.logger.info('starting dialogflow ES bot');
const baseArgs = `${ep.uuid} ${this.project} ${this.lang} ${this.welcomeEvent}`;
if (this.welcomeEventParams) {
await ep.api(this.cmd, `${baseArgs} '${JSON.stringify(this.welcomeEventParams)}'`);
}
else if (this.welcomeEvent.length) {
await ep.api(this.cmd, baseArgs);
} }
else { else {
await ep.api(this.cmd, `${this.ep.uuid} ${this.project} ${this.lang}`); await this.startBotES();
} }
} }
async startBotCX(ep) { async startBotES() {
this.logger.info('starting dialogflow ES bot');
const baseArgs = `${this.ep.uuid} ${this.project} ${this.lang} ${this.welcomeEvent}`;
if (this.welcomeEventParams) {
await this.ep.api(this.cmd, `${baseArgs} '${JSON.stringify(this.welcomeEventParams)}'`);
}
else if (this.welcomeEvent.length) {
await this.ep.api(this.cmd, baseArgs);
}
else {
await this.ep.api(this.cmd, `${this.ep.uuid} ${this.project} ${this.lang}`);
}
}
async startBotCX() {
const baseArgs = [ const baseArgs = [
ep.uuid, this.ep.uuid,
this.region, this.region,
this.project, this.project,
this.agent, this.agent,
@@ -198,7 +198,7 @@ class Dialogflow extends Task {
} }
this.logger.info({args: baseArgs}, 'starting dialogflow CX bot'); this.logger.info({args: baseArgs}, 'starting dialogflow CX bot');
await ep.api(this.cmd, `${baseArgs.join(' ')}`); await this.ep.api(this.cmd, `${baseArgs.join(' ')}`);
} }
/** /**