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);
try {
this.logger.info('Dialogflow:exec');
await this.init(cs, ep);
this.logger.info('Dialogflow:exec - initialized');
await this.startBot(ep);
this.logger.info('Dialogflow:exec - started bot');
await this.startBot();
await this.awaitTaskDone();
this.logger.info('Dialogflow:exec - done');
} catch (err) {
this.logger.error({err}, 'Dialogflow:exec error');
}
@@ -165,28 +161,32 @@ class Dialogflow extends Task {
}
}
async startBot(ep) {
const fn = this.isCX ? this.startBotCX : this.startBotES;
await fn(ep);
}
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);
async startBot() {
if (this.isCX) {
await this.startBotCX();
}
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 = [
ep.uuid,
this.ep.uuid,
this.region,
this.project,
this.agent,
@@ -198,7 +198,7 @@ class Dialogflow extends Task {
}
this.logger.info({args: baseArgs}, 'starting dialogflow CX bot');
await ep.api(this.cmd, `${baseArgs.join(' ')}`);
await this.ep.api(this.cmd, `${baseArgs.join(' ')}`);
}
/**