@onereach/step-voice
Version:
Onereach.ai Voice Steps
89 lines (88 loc) • 3.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const voice_1 = tslib_1.__importDefault(require("./voice"));
class Recording extends voice_1.default {
async runStep() {
const call = await this.fetchData();
const { tts, sensitiveData, textType } = this.data;
const ttsSettings = tts.getSettings(call.tts);
const sections = this.buildSections({ sections: this.data.audio, textType, ttsSettings });
if (!this.data?.disableDefaultBeepSound) {
sections.push({
url: 'https://bot-service-recordings.s3.us-west-2.amazonaws.com/beep_sound.wav',
bargeInVoice: false,
bargeInKeypad: false
});
}
const command = {
name: 'start-record',
params: {
...(this.data.isTerminateOnSilence ? {
silenceHits: this.data.silenceHits
} : {
terminator: this.data.terminationKey
}),
duration: parseInt(this.data.recordDurationSeconds),
sections,
reporterTranscriptEventId: ''
}
};
this.triggers.local(`in/voice/${call.id}`, async (event) => {
const url = event.params.mediaPath;
await this.handleInterruption({
call,
event,
speechSections: sections,
reportingSettingsKey: 'transcriptPrompt'
});
switch (event.params.type) {
case 'hangup':
// TODO do we need zombie?
this.state.zombie = true;
await this.handleHangup(call);
return await this.waitConvEnd();
case 'record':
if (!lodash_1.default.isEmpty(url)) {
await this.transcript(call, {
message: 'Voicemail',
reportingSettingsKey: 'transcriptRecording',
recording: url,
action: 'Call Recording',
actionFromBot: false
});
// TODO do we need zombie?
this.event.params.zombie = this.state.zombie;
// TODO figure out Global Command compatibility
lodash_1.default.unset(this.state.hooks, 'skipVoiceEventTypes');
await this.resumeRecording(call, sensitiveData);
return this.exitStep('success', url);
}
else {
// TODO What happens with reporting here?
this.log.warn('Event params', event.params);
throw new Error(event.params.error?.message ?? 'Cannot finalize recording');
}
case 'error':
return this.throwError(event.params.error);
default:
return this.exitFlow();
}
});
this.triggers.otherwise(async () => {
// TODO figure out Global Command compatibility
lodash_1.default.set(this.state.hooks, 'skipVoiceEventTypes', ['hangup']);
const eventId = await this.transcript(call, {
sections,
reportingSettingsKey: 'transcriptPrompt',
action: 'Call Prompt',
actionFromBot: true
});
command.params.reporterTranscriptEventId = eventId;
await this.pauseRecording(call, command, sensitiveData);
return this.exitFlow();
});
}
}
exports.default = Recording;