Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
1.7 kB
42
Indexable
Never
        if (voiceBotType === STT_TYPE.ONLINE) {
            // ============= Connect AudioSocket ==================
            externalChannel = await connectAudioSocket({
                client,
                bridgeIn,
                channelId,
            });
        }

        // ============= Snoop Channel ========================
        const snoopChannel = await channel.snoopChannelWithId({
            snoopId: `${channel.id}-snoop`,
            spy: 'both',
            // whisper: 'out',
            app: process.env.APP_ASTERISK,
        });

        // ====================================================

        const { fileName } = generateAudioFileName(`${ccPhoneNumber}_${userPhoneNumber}`);
        await bridgeRecorder.record({
            name: fileName + '_out',
            format: 'wav',
        }).catch(err => {   
            err.message = `ERROR RECORDING FULL: ${err.message}`;
            logger.error(err);
        });

        await bridgeIn.record({
            name: fileName + '_in',
            format: 'wav',
        }).catch(err => {
            err.message = `ERROR RECORDING FULL: ${err.message}`;
            logger.error(err);
        });

        const cdr = await buildCdrInRedis({
            account,
            userPhoneNumber,
            ccPhoneNumber,
            startedAt,
            bridgeId,
            channelId: channel.id,
            botId: bot._id,
            externalId: externalChannel.id,
            fullAudio: `${fileName}.wav`,
        });

        await bridgeIn.addChannel({
            channel: channel.id,
        });

        await bridgeRecorder.addChannel({
            channel: snoopChannel.id,
        });

        await channel.answer();