@onereach/step-voice
Version:
Onereach.ai Voice Steps
64 lines (63 loc) • 2.32 kB
JavaScript
;
/* eslint-disable
@typescript-eslint/strict-boolean-expressions,
@typescript-eslint/explicit-function-return-type,
@typescript-eslint/no-misused-promises
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const voice_1 = tslib_1.__importDefault(require("./voice"));
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const defaultSessionTimeout = 5 * 60 * 1000;
class WaitForCall extends voice_1.default {
get conversation() {
if (this.step.dataOut == null)
throw new Error('missing step.dataOut');
return this.step.dataOut;
}
async runStep() {
const selectedNumbers = this.data.selectedNumbers;
lodash_1.default.forEach(selectedNumbers, number => {
this.triggers.on(`in/voice/${number.value}/call`, this.onCall);
});
}
async onCall(event) {
const { asr, tts, endOfInputTimeout } = this.data;
const call = {
headers: event.params.headers,
// @ts-expect-error
botNumber: event.params.channel.to ?? 'unknown',
// @ts-expect-error
endUserNumber: event.params.channel?.from ?? 'unknown',
...event.params.channel,
asr: asr.getSettings(),
tts: tts.getVoice()
};
delete call.from;
delete call.to;
const presetTime = (Number(endOfInputTimeout) || 0) * 60 * 1000;
const { sessionId: previousSessionId = '', beginningSessionId = '', } = event?.reporting ?? {};
await this.session.start({
timeout: presetTime || defaultSessionTimeout,
reporting: {
settingsKey: 'session',
startedBy: 'Visitor',
sessionType: 'Phone',
previousSessionId,
beginningSessionId
},
reportingSessions: [{
previousSessionId,
beginningSessionId
}]
});
await this.startConversation(call);
await this.transcript(call, {
action: 'Call Start',
reportingSettingsKey: 'transcript',
actionFromBot: false
});
return this.exitStep('trigger');
}
}
exports.default = WaitForCall;