ivr-tester
Version:
An automated testing framework for IVR call flows
43 lines (42 loc) • 1.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CallTranscriber = void 0;
const TwilioCall_1 = require("../TwilioCall");
const twilio_1 = require("../twilio");
const Debugger_1 = require("../../Debugger");
const Emitter_1 = require("../../Emitter");
class CallTranscriber extends Emitter_1.TypedEmitter {
constructor(call, transcriber) {
super();
this.call = call;
this.transcriber = transcriber;
this.processMessageRef = this.processMessage.bind(this);
this.closeRef = this.close.bind(this);
call
.getStream()
.on(TwilioCall_1.WebSocketEvents.Message, this.processMessageRef)
.on(TwilioCall_1.WebSocketEvents.Close, this.closeRef);
transcriber.on("transcription", this.collects.bind(this));
}
processMessage(message) {
const data = JSON.parse(message);
switch (data.event) {
case twilio_1.TwilioConnectionEvents.Media:
this.transcriber.transcribe(Buffer.from(data.media.payload, "base64"));
break;
}
}
close() {
this.call
.getStream()
.off(TwilioCall_1.WebSocketEvents.Message, this.processMessageRef)
.off(TwilioCall_1.WebSocketEvents.Close, this.closeRef);
this.transcriber.close();
}
collects(event) {
CallTranscriber.debug("Transcript: %s", event.transcription);
this.emit("transcription", event);
}
}
exports.CallTranscriber = CallTranscriber;
CallTranscriber.debug = Debugger_1.Debugger.getPackageDebugger();