@fonoster/apiserver 0.27.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/applications/buildService.d.ts +5 -1
- package/dist/applications/buildService.js +10 -7
- package/dist/applications/createCreateApplication.d.ts +6 -2
- package/dist/applications/createCreateApplication.js +24 -16
- package/dist/applications/createCreateTestToken.d.ts +3 -1
- package/dist/applications/createCreateTestToken.js +18 -13
- package/dist/applications/createGetApplication.js +2 -2
- package/dist/applications/createGetFnUtil.d.ts +22 -18
- package/dist/applications/createGetFnUtil.js +3 -5
- package/dist/applications/createListApplications.js +3 -4
- package/dist/applications/createRotateSigningSecret.d.ts +9 -0
- package/dist/{calls/createFetchSingleCall.js → applications/createRotateSigningSecret.js} +23 -20
- package/dist/applications/createUpdateApplication.d.ts +6 -2
- package/dist/applications/createUpdateApplication.js +35 -36
- package/dist/applications/evalKeys.d.ts +9 -0
- package/dist/{voice/handlers/dial/recordChannel.js → applications/evalKeys.js} +17 -12
- package/dist/applications/session/appModel.d.ts +225 -0
- package/dist/applications/session/appModel.js +331 -0
- package/dist/applications/types.d.ts +1 -27
- package/dist/billing/buildService.d.ts +24 -0
- package/dist/billing/buildService.js +116 -0
- package/dist/bin/entrypoint.d.ts +1 -0
- package/dist/bin/entrypoint.js +180 -0
- package/dist/bin/healthcheck.d.ts +2 -0
- package/dist/{voice/utils/VoiceServiceClientConstructor.js → bin/healthcheck.js} +24 -9
- package/dist/bin/regionHubSetup.d.ts +2 -0
- package/dist/bin/regionHubSetup.js +67 -0
- package/dist/bin/usage.d.ts +2 -0
- package/dist/bin/usage.js +119 -0
- package/dist/calls/buildService.d.ts +1 -20
- package/dist/calls/buildService.js +59 -6
- package/dist/calls/createCall.d.ts +17 -2
- package/dist/calls/createCall.js +64 -11
- package/dist/calls/createCallPublisher.d.ts +40 -2
- package/dist/calls/createCallPublisher.js +43 -9
- package/dist/calls/createIsWorkspaceNumber.d.ts +41 -0
- package/dist/calls/createIsWorkspaceNumber.js +39 -0
- package/dist/calls/createTrackCall.d.ts +55 -2
- package/dist/calls/createTrackCall.js +230 -16
- package/dist/calls/getCall.d.ts +4 -2
- package/dist/calls/getCall.js +2 -3
- package/dist/calls/listCalls.d.ts +4 -2
- package/dist/calls/listCalls.js +2 -3
- package/dist/calls/types.d.ts +11 -2
- package/dist/calls/types.js +10 -0
- package/dist/{core/buildWelcomeDemoService.d.ts → capabilities/buildService.d.ts} +8 -8
- package/dist/capabilities/buildService.js +17 -0
- package/dist/capabilities/createGetCapabilities.d.ts +78 -0
- package/dist/capabilities/createGetCapabilities.js +98 -0
- package/dist/{voice/handlers/utils → capabilities}/index.d.ts +2 -3
- package/dist/{voice/handlers/utils → capabilities}/index.js +4 -3
- package/dist/config/index.d.ts +23 -0
- package/dist/config/index.js +102 -0
- package/dist/config/schema.d.ts +1919 -0
- package/dist/config/schema.js +357 -0
- package/dist/core/allowList.js +2 -1
- package/dist/core/applyCatalog.d.ts +10 -0
- package/dist/{voice/client/GrpcClientHandler.js → core/applyCatalog.js} +45 -51
- package/dist/core/db.d.ts +3 -1
- package/dist/core/db.js +2 -1
- package/dist/core/durableConsumer.d.ts +41 -0
- package/dist/core/durableConsumer.js +104 -0
- package/dist/core/httpBridge.d.ts +24 -6
- package/dist/core/httpBridge.js +3 -25
- package/dist/core/identityConfig.d.ts +2 -35
- package/dist/core/identityConfig.js +3 -36
- package/dist/core/regionHooks.d.ts +15 -0
- package/dist/{calls/influxdb.js → core/regionHooks.js} +4 -8
- package/dist/core/runServices.js +98 -15
- package/dist/core/services.d.ts +96 -6
- package/dist/core/services.js +49 -10
- package/dist/{voice/errors/index.d.ts → core/telemetry.d.ts} +2 -2
- package/dist/core/telemetry.js +42 -0
- package/dist/{applications/utils/convertToApplicationData.d.ts → core/telemetryInterceptor.d.ts} +10 -4
- package/dist/core/telemetryInterceptor.js +57 -0
- package/dist/core/testTokenConfig.js +4 -1
- package/dist/core/upsertRoomrPeer.d.ts +6 -0
- package/dist/core/{upsertDefaultPeer.js → upsertRoomrPeer.js} +31 -30
- package/dist/envs.d.ts +136 -23
- package/dist/envs.js +108 -143
- package/dist/index.js +39 -21
- package/dist/outbound/createNodeDirectory.d.ts +86 -0
- package/dist/outbound/createNodeDirectory.js +140 -0
- package/dist/{voice/integrations → outbound}/index.d.ts +4 -1
- package/dist/{voice/errors → outbound}/index.js +4 -2
- package/dist/outbound/placeOutboundCall.d.ts +96 -0
- package/dist/outbound/placeOutboundCall.js +172 -0
- package/dist/outbound/placementSweep.d.ts +56 -0
- package/dist/outbound/placementSweep.js +127 -0
- package/dist/outbound/runOutboundCalls.d.ts +52 -0
- package/dist/outbound/runOutboundCalls.js +171 -0
- package/dist/providers/createProvidersHandlers.d.ts +39 -0
- package/dist/providers/createProvidersHandlers.js +229 -0
- package/dist/providers/index.d.ts +47 -0
- package/dist/{voice/client → providers}/index.js +15 -6
- package/dist/providers/registryUsage.d.ts +48 -0
- package/dist/providers/registryUsage.js +236 -0
- package/dist/records/createIndexRecord.d.ts +42 -0
- package/dist/records/createIndexRecord.js +185 -0
- package/dist/records/createRecordsRouter.d.ts +61 -0
- package/dist/records/createRecordsRouter.js +330 -0
- package/dist/records/createSearchRecords.d.ts +51 -0
- package/dist/records/createSearchRecords.js +134 -0
- package/dist/{voice/filters → records}/index.d.ts +6 -6
- package/dist/{voice/filters → records}/index.js +6 -6
- package/dist/records/maintenance.d.ts +33 -0
- package/dist/records/maintenance.js +166 -0
- package/dist/records/runCallRecords.d.ts +48 -0
- package/dist/records/runCallRecords.js +49 -0
- package/dist/{events/createPerCallCache.d.ts → records/stores.d.ts} +4 -7
- package/dist/{voice/handlers/utils/isDtmf.js → records/stores.js} +9 -3
- package/dist/records/types.d.ts +104 -0
- package/dist/regions/configSync.d.ts +130 -0
- package/dist/regions/configSync.js +316 -0
- package/dist/regions/createRegionsRouter.d.ts +151 -0
- package/dist/regions/createRegionsRouter.js +391 -0
- package/dist/regions/endpoints.d.ts +41 -0
- package/dist/regions/endpoints.js +90 -0
- package/dist/regions/enrollmentToken.d.ts +41 -0
- package/dist/regions/enrollmentToken.js +94 -0
- package/dist/regions/httpAuth.d.ts +39 -0
- package/dist/regions/httpAuth.js +78 -0
- package/dist/regions/ids.d.ts +15 -0
- package/dist/regions/ids.js +81 -0
- package/dist/{voice/client → regions}/index.d.ts +17 -6
- package/dist/regions/index.js +51 -0
- package/dist/regions/link.d.ts +17 -0
- package/dist/regions/link.js +170 -0
- package/dist/regions/natsAuth.d.ts +41 -0
- package/dist/regions/natsAuth.js +64 -0
- package/dist/regions/natsJwt.d.ts +23 -0
- package/dist/regions/natsJwt.js +26 -0
- package/dist/regions/relay.d.ts +45 -0
- package/dist/regions/relay.js +203 -0
- package/dist/regions/relayHttp.d.ts +7 -0
- package/dist/regions/relayHttp.js +107 -0
- package/dist/regions/relaySlots.d.ts +18 -0
- package/dist/regions/relaySlots.js +118 -0
- package/dist/regions/runRegions.d.ts +111 -0
- package/dist/regions/runRegions.js +235 -0
- package/dist/regions/service.d.ts +129 -0
- package/dist/regions/service.js +558 -0
- package/dist/regions/sources.d.ts +20 -0
- package/dist/regions/sources.js +191 -0
- package/dist/regions/status.d.ts +35 -0
- package/dist/regions/status.js +63 -0
- package/dist/regions/types.d.ts +123 -0
- package/dist/regions/types.js +41 -0
- package/dist/{voice/integrations/getSttConfig.d.ts → regions/withConfigChangeHook.d.ts} +13 -7
- package/dist/regions/withConfigChangeHook.js +44 -0
- package/dist/secrets/createGetFnUtil.d.ts +2 -2
- package/dist/session/createSessionRouter.d.ts +49 -0
- package/dist/session/createSessionRouter.js +206 -0
- package/dist/{voice/handlers/dial → session}/index.d.ts +1 -1
- package/dist/{voice/handlers/dial → session}/index.js +1 -1
- package/dist/usage/buildService.d.ts +16 -0
- package/dist/{voice/integrations/getTtsConfig.js → usage/buildService.js} +13 -7
- package/dist/{voice/tts/utils/convertUlawToPCM16.d.ts → usage/createGetUsage.d.ts} +7 -6
- package/dist/usage/createGetUsage.js +118 -0
- package/dist/usage/ingestUsage.d.ts +7 -0
- package/dist/usage/ingestUsage.js +87 -0
- package/dist/usage/publishRecordedUsage.d.ts +52 -0
- package/dist/usage/publishRecordedUsage.js +103 -0
- package/dist/{utils/createHandleDialEventsWithNats.d.ts → usage/publishUsage.d.ts} +10 -4
- package/dist/usage/publishUsage.js +50 -0
- package/dist/usage/rebuildUsage.d.ts +48 -0
- package/dist/usage/rebuildUsage.js +104 -0
- package/dist/usage/runUsageConsumer.d.ts +22 -0
- package/dist/usage/runUsageConsumer.js +78 -0
- package/dist/usage/snapshotStorage.d.ts +14 -0
- package/dist/usage/snapshotStorage.js +95 -0
- package/dist/{voice/integrations/getTtsConfig.d.ts → usage/types.d.ts} +17 -6
- package/dist/utils/createCheckNumberPreconditions.js +4 -0
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/voice/stt/Deepgram.d.ts +4 -57
- package/dist/voice/stt/Deepgram.js +15 -286
- package/dist/voice/stt/Google.d.ts +4 -15
- package/dist/voice/stt/Google.js +7 -103
- package/dist/voice/stt/types.d.ts +2 -38
- package/dist/voice/stt/types.js +25 -3
- package/dist/voice/tts/Azure.d.ts +4 -34
- package/dist/voice/tts/Azure.js +25 -105
- package/dist/voice/tts/Deepgram.d.ts +4 -38
- package/dist/voice/tts/Deepgram.js +25 -82
- package/dist/voice/tts/ElevenLabs.d.ts +4 -18
- package/dist/voice/tts/ElevenLabs.js +6 -97
- package/dist/voice/tts/Google.d.ts +4 -38
- package/dist/voice/tts/Google.js +25 -91
- package/dist/webhooks/createWebhooksHandlers.d.ts +37 -0
- package/dist/webhooks/createWebhooksHandlers.js +217 -0
- package/dist/webhooks/index.d.ts +37 -0
- package/dist/webhooks/index.js +51 -0
- package/dist/webhooks/lostCalls.d.ts +49 -0
- package/dist/webhooks/lostCalls.js +147 -0
- package/dist/webhooks/nodeCallEvents.d.ts +73 -0
- package/dist/webhooks/nodeCallEvents.js +177 -0
- package/dist/webhooks/runWebhookFanout.d.ts +44 -0
- package/dist/webhooks/runWebhookFanout.js +202 -0
- package/package.json +21 -31
- package/dist/applications/utils/applicationWithEncodedStruct.d.ts +0 -3
- package/dist/applications/utils/applicationWithEncodedStruct.js +0 -50
- package/dist/applications/utils/convertToApplicationData.js +0 -37
- package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +0 -786
- package/dist/applications/validation/assistantWithoutApiKeySchema.js +0 -35
- package/dist/applications/validation/createValidationSchema.d.ts +0 -1474
- package/dist/applications/validation/createValidationSchema.js +0 -67
- package/dist/applications/validation/prepareForValidation.d.ts +0 -21
- package/dist/applications/validation/prepareForValidation.js +0 -35
- package/dist/applications/validation/speechValidators.d.ts +0 -47
- package/dist/applications/validation/speechValidators.js +0 -50
- package/dist/applications/validation/validOrThrow.d.ts +0 -21
- package/dist/applications/validation/validOrThrow.js +0 -15
- package/dist/calls/createFetchCalls.d.ts +0 -22
- package/dist/calls/createFetchCalls.js +0 -88
- package/dist/calls/createFetchSingleCall.d.ts +0 -22
- package/dist/calls/influxdb.d.ts +0 -2
- package/dist/calls/runCallManager.d.ts +0 -8
- package/dist/calls/runCallManager.js +0 -75
- package/dist/core/buildWelcomeDemoService.js +0 -97
- package/dist/core/upsertDefaultPeer.d.ts +0 -2
- package/dist/events/amdResultCache.d.ts +0 -23
- package/dist/events/amdResultCache.js +0 -35
- package/dist/events/createInfluxDbPub.d.ts +0 -13
- package/dist/events/createInfluxDbPub.js +0 -89
- package/dist/events/createPerCallCache.js +0 -46
- package/dist/events/mapCallDirectionToEnum.d.ts +0 -21
- package/dist/events/mapCallDirectionToEnum.js +0 -37
- package/dist/events/nats.d.ts +0 -10
- package/dist/events/nats.js +0 -82
- package/dist/events/transformEvent.d.ts +0 -2
- package/dist/events/transformEvent.js +0 -87
- package/dist/events/types.d.ts +0 -26
- package/dist/utils/createHandleDialEventsWithNats.js +0 -24
- package/dist/utils/createHandleDialEventsWithVoiceClient.d.ts +0 -23
- package/dist/utils/createHandleDialEventsWithVoiceClient.js +0 -27
- package/dist/utils/getIntegrationsFromFile.d.ts +0 -2
- package/dist/utils/getIntegrationsFromFile.js +0 -49
- package/dist/utils/mapDialStatus.d.ts +0 -21
- package/dist/utils/mapDialStatus.js +0 -38
- package/dist/voice/VoiceDispatcher.d.ts +0 -21
- package/dist/voice/VoiceDispatcher.js +0 -122
- package/dist/voice/amd/mapAsteriskAmd.d.ts +0 -38
- package/dist/voice/amd/mapAsteriskAmd.js +0 -68
- package/dist/voice/client/AudioSocketHandler.d.ts +0 -38
- package/dist/voice/client/AudioSocketHandler.js +0 -70
- package/dist/voice/client/AuthorizationHandler.d.ts +0 -13
- package/dist/voice/client/AuthorizationHandler.js +0 -78
- package/dist/voice/client/ExternalMediaHandler.d.ts +0 -32
- package/dist/voice/client/ExternalMediaHandler.js +0 -59
- package/dist/voice/client/GrpcClientHandler.d.ts +0 -36
- package/dist/voice/client/SpeechHandler.d.ts +0 -60
- package/dist/voice/client/SpeechHandler.js +0 -120
- package/dist/voice/client/VoiceClientImpl.d.ts +0 -79
- package/dist/voice/client/VoiceClientImpl.js +0 -198
- package/dist/voice/connectToAri.d.ts +0 -2
- package/dist/voice/connectToAri.js +0 -81
- package/dist/voice/createCreateVoiceClient.d.ts +0 -9
- package/dist/voice/createCreateVoiceClient.js +0 -97
- package/dist/voice/errors/ChannelVarNotFoundError.d.ts +0 -23
- package/dist/voice/errors/ChannelVarNotFoundError.js +0 -10
- package/dist/voice/errors/MethodNotImplementedError.d.ts +0 -22
- package/dist/voice/errors/MethodNotImplementedError.js +0 -27
- package/dist/voice/filters/AudioFilterFactory.d.ts +0 -35
- package/dist/voice/filters/AudioFilterFactory.js +0 -94
- package/dist/voice/filters/aiCoustics/createAiCousticsFilter.d.ts +0 -64
- package/dist/voice/filters/aiCoustics/createAiCousticsFilter.js +0 -252
- package/dist/voice/filters/aiCoustics/types.d.ts +0 -45
- package/dist/voice/filters/aiCoustics/types.js +0 -29
- package/dist/voice/filters/createAudioFilterChain.d.ts +0 -9
- package/dist/voice/filters/createAudioFilterChain.js +0 -171
- package/dist/voice/filters/createAudioFilterSession.d.ts +0 -15
- package/dist/voice/filters/createAudioFilterSession.js +0 -114
- package/dist/voice/filters/pcm.d.ts +0 -21
- package/dist/voice/filters/pcm.js +0 -37
- package/dist/voice/filters/types.d.ts +0 -61
- package/dist/voice/filters/types.js +0 -26
- package/dist/voice/handlers/createAnswerHandler.d.ts +0 -23
- package/dist/voice/handlers/createAnswerHandler.js +0 -24
- package/dist/voice/handlers/createHangupHandler.d.ts +0 -23
- package/dist/voice/handlers/createHangupHandler.js +0 -28
- package/dist/voice/handlers/createMuteHandler.d.ts +0 -4
- package/dist/voice/handlers/createMuteHandler.js +0 -27
- package/dist/voice/handlers/createPlayDtmfHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlayDtmfHandler.js +0 -27
- package/dist/voice/handlers/createPlayHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlayHandler.js +0 -33
- package/dist/voice/handlers/createPlaybackControlHandler.d.ts +0 -4
- package/dist/voice/handlers/createPlaybackControlHandler.js +0 -62
- package/dist/voice/handlers/createRecordHandler.d.ts +0 -4
- package/dist/voice/handlers/createRecordHandler.js +0 -58
- package/dist/voice/handlers/createSayHandler.d.ts +0 -4
- package/dist/voice/handlers/createSayHandler.js +0 -31
- package/dist/voice/handlers/createSetAudioFiltersHandler.d.ts +0 -11
- package/dist/voice/handlers/createSetAudioFiltersHandler.js +0 -74
- package/dist/voice/handlers/createStopSayHandler.d.ts +0 -3
- package/dist/voice/handlers/createStopSayHandler.js +0 -34
- package/dist/voice/handlers/createStreamGatherHandler.d.ts +0 -3
- package/dist/voice/handlers/createStreamGatherHandler.js +0 -74
- package/dist/voice/handlers/createStreamHandler.d.ts +0 -3
- package/dist/voice/handlers/createStreamHandler.js +0 -70
- package/dist/voice/handlers/createUnmuteHandler.d.ts +0 -4
- package/dist/voice/handlers/createUnmuteHandler.js +0 -27
- package/dist/voice/handlers/dial/createDialHandler.d.ts +0 -23
- package/dist/voice/handlers/dial/createDialHandler.js +0 -78
- package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +0 -24
- package/dist/voice/handlers/dial/handleChannelLeftBridge.js +0 -29
- package/dist/voice/handlers/dial/handleStasisEnd.d.ts +0 -21
- package/dist/voice/handlers/dial/handleStasisEnd.js +0 -19
- package/dist/voice/handlers/dial/handleStasisStart.d.ts +0 -27
- package/dist/voice/handlers/dial/handleStasisStart.js +0 -52
- package/dist/voice/handlers/dial/recordChannel.d.ts +0 -22
- package/dist/voice/handlers/gather/createGatherHandler.d.ts +0 -3
- package/dist/voice/handlers/gather/createGatherHandler.js +0 -86
- package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +0 -26
- package/dist/voice/handlers/gather/getTimeoutPromise.js +0 -18
- package/dist/voice/handlers/index.d.ts +0 -33
- package/dist/voice/handlers/index.js +0 -49
- package/dist/voice/handlers/utils/awaitForPlaybackFinished.d.ts +0 -21
- package/dist/voice/handlers/utils/awaitForPlaybackFinished.js +0 -25
- package/dist/voice/handlers/utils/awaitForRecordingFinished.d.ts +0 -5
- package/dist/voice/handlers/utils/awaitForRecordingFinished.js +0 -53
- package/dist/voice/handlers/utils/isDtmf.d.ts +0 -20
- package/dist/voice/handlers/utils/textChunksByClause.d.ts +0 -2
- package/dist/voice/handlers/utils/textChunksByClause.js +0 -41
- package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.d.ts +0 -2
- package/dist/voice/handlers/utils/textChunksByFirstNaturalPause.js +0 -34
- package/dist/voice/handlers/utils/withErrorHandling.d.ts +0 -22
- package/dist/voice/handlers/utils/withErrorHandling.js +0 -38
- package/dist/voice/integrations/ApplicationNotFoundError.d.ts +0 -22
- package/dist/voice/integrations/ApplicationNotFoundError.js +0 -28
- package/dist/voice/integrations/createCreateContainer.d.ts +0 -4
- package/dist/voice/integrations/createCreateContainer.js +0 -76
- package/dist/voice/integrations/getSttConfig.js +0 -30
- package/dist/voice/integrations/index.js +0 -35
- package/dist/voice/integrations/types.d.ts +0 -29
- package/dist/voice/stt/AbstractSpeechToText.d.ts +0 -33
- package/dist/voice/stt/AbstractSpeechToText.js +0 -19
- package/dist/voice/stt/SpeechToTextFactory.d.ts +0 -9
- package/dist/voice/stt/SpeechToTextFactory.js +0 -43
- package/dist/voice/transcribeOnConnection.d.ts +0 -35
- package/dist/voice/transcribeOnConnection.js +0 -91
- package/dist/voice/tts/AbstractTextToSpeech.d.ts +0 -40
- package/dist/voice/tts/AbstractTextToSpeech.js +0 -50
- package/dist/voice/tts/TextToSpeechFactory.d.ts +0 -8
- package/dist/voice/tts/TextToSpeechFactory.js +0 -47
- package/dist/voice/tts/types.d.ts +0 -48
- package/dist/voice/tts/types.js +0 -2
- package/dist/voice/tts/utils/convertUlawToPCM16.js +0 -40
- package/dist/voice/tts/utils/createChunkedSynthesisStream.d.ts +0 -28
- package/dist/voice/tts/utils/createChunkedSynthesisStream.js +0 -78
- package/dist/voice/tts/utils/createErrorStream.d.ts +0 -21
- package/dist/voice/tts/utils/createErrorStream.js +0 -28
- package/dist/voice/tts/utils/index.d.ts +0 -23
- package/dist/voice/tts/utils/index.js +0 -39
- package/dist/voice/tts/utils/isSsml.d.ts +0 -20
- package/dist/voice/tts/utils/isSsml.js +0 -25
- package/dist/voice/tts/utils/streamToBuffer.d.ts +0 -20
- package/dist/voice/tts/utils/streamToBuffer.js +0 -60
- package/dist/voice/types/ari.d.ts +0 -43
- package/dist/voice/types/ari.js +0 -48
- package/dist/voice/types/index.d.ts +0 -20
- package/dist/voice/types/index.js +0 -36
- package/dist/voice/types/voice.d.ts +0 -67
- package/dist/voice/types/voice.js +0 -2
- package/dist/voice/utils/VoiceServiceClientConstructor.d.ts +0 -3
- package/dist/voice/utils/createExternalMediaConfig.d.ts +0 -12
- package/dist/voice/utils/createExternalMediaConfig.js +0 -37
- package/dist/voice/utils/createGetChannelVar.d.ts +0 -22
- package/dist/voice/utils/createGetChannelVar.js +0 -27
- package/dist/voice/utils/createGetChannelVarWithoutThrow.d.ts +0 -22
- package/dist/voice/utils/createGetChannelVarWithoutThrow.js +0 -26
- package/dist/voice/utils/index.d.ts +0 -22
- package/dist/voice/utils/index.js +0 -38
- /package/dist/{events → records}/types.js +0 -0
- /package/dist/{voice/integrations → usage}/types.js +0 -0
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SpeechHandler = void 0;
|
|
13
|
-
const logger_1 = require("@fonoster/logger");
|
|
14
|
-
const types_1 = require("../types");
|
|
15
|
-
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
16
|
-
class SpeechHandler {
|
|
17
|
-
constructor(params) {
|
|
18
|
-
this.tts = params.tts;
|
|
19
|
-
this.stt = params.stt;
|
|
20
|
-
this.ari = params.ari;
|
|
21
|
-
this.transcriptionsStream = params.transcriptionsStream;
|
|
22
|
-
this.audioStream = params.audioStream;
|
|
23
|
-
this.mediaSessionRef = params.mediaSessionRef;
|
|
24
|
-
}
|
|
25
|
-
synthesize(text, options) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const { ref, stream } = this.tts.synthesize(text, options);
|
|
28
|
-
logger.verbose("starting audio synthesis", { ref });
|
|
29
|
-
try {
|
|
30
|
-
// Stop any active stream
|
|
31
|
-
this.audioStream.stop();
|
|
32
|
-
yield this.audioStream.playStream(stream);
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
logger.error(`stream error for ref ${ref}: ${error.message}`, {
|
|
36
|
-
errorDetails: error.stack || "No stack trace"
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return ref;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
stopSynthesis() {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
this.audioStream.stop();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
transcribe() {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
try {
|
|
50
|
-
return yield this.stt.transcribe(this.transcriptionsStream);
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
logger.warn("transcription error", e);
|
|
54
|
-
return {};
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
startSpeechGather(callback) {
|
|
59
|
-
const out = this.stt.streamTranscribe(this.transcriptionsStream);
|
|
60
|
-
out.on("data", callback);
|
|
61
|
-
out.on("error", (error) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
logger.error("speech recognition error", { error });
|
|
63
|
-
yield this.ari.channels.hangup({ channelId: this.mediaSessionRef });
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
startDtmfGather(callback) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const channel = yield this.ari.channels.get({
|
|
69
|
-
channelId: this.mediaSessionRef
|
|
70
|
-
});
|
|
71
|
-
channel.on(types_1.AriEvent.CHANNEL_DTMF_RECEIVED, (event) => {
|
|
72
|
-
const { digit } = event;
|
|
73
|
-
callback({ digit });
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
// Returns a promise that resolves when DTMF collection is complete
|
|
78
|
-
waitForDtmf(params) {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const { onDigitReceived, finishOnKey, maxDigits, timeout } = params;
|
|
81
|
-
let result = "";
|
|
82
|
-
let timeoutId = null;
|
|
83
|
-
const channel = yield this.ari.channels.get({
|
|
84
|
-
channelId: this.mediaSessionRef
|
|
85
|
-
});
|
|
86
|
-
return new Promise((resolve) => {
|
|
87
|
-
const resetTimer = () => {
|
|
88
|
-
if (timeoutId) {
|
|
89
|
-
clearTimeout(timeoutId);
|
|
90
|
-
}
|
|
91
|
-
timeoutId = setTimeout(() => {
|
|
92
|
-
channel.removeListener(types_1.AriEvent.CHANNEL_DTMF_RECEIVED, dtmfListener);
|
|
93
|
-
resolve({ digits: result });
|
|
94
|
-
}, timeout);
|
|
95
|
-
};
|
|
96
|
-
const dtmfListener = (event) => {
|
|
97
|
-
const { digit } = event;
|
|
98
|
-
// Stops the global timeout
|
|
99
|
-
onDigitReceived();
|
|
100
|
-
resetTimer();
|
|
101
|
-
if (digit !== finishOnKey) {
|
|
102
|
-
result += digit;
|
|
103
|
-
}
|
|
104
|
-
if (result.length >= maxDigits || digit === finishOnKey) {
|
|
105
|
-
clearTimeout(timeoutId);
|
|
106
|
-
channel.removeListener(types_1.AriEvent.CHANNEL_DTMF_RECEIVED, dtmfListener);
|
|
107
|
-
resolve({ digits: result });
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
channel.on(types_1.AriEvent.CHANNEL_DTMF_RECEIVED, dtmfListener);
|
|
111
|
-
resetTimer(); // Start the initial timeout
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
// Placeholder for future implementation
|
|
116
|
-
stopStreamGather() {
|
|
117
|
-
throw new Error("Method 'stopStreamGather' not implemented.");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.SpeechHandler = SpeechHandler;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
3
|
-
* http://github.com/fonoster/fonoster
|
|
4
|
-
*
|
|
5
|
-
* This file is part of Fonoster
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the MIT License (the "License");
|
|
8
|
-
* you may not use this file except in compliance with
|
|
9
|
-
* the License. You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* https://opensource.org/licenses/MIT
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
import { Stream } from "stream";
|
|
20
|
-
import { SayOptions, VoiceClientConfig, VoiceIn } from "@fonoster/common";
|
|
21
|
-
import { Bridge, Client } from "ari-client";
|
|
22
|
-
import { AudioFilterConfig } from "../filters";
|
|
23
|
-
import { SpeechResult } from "../stt/types";
|
|
24
|
-
import { SpeechToText, TextToSpeech, VoiceClient } from "../types";
|
|
25
|
-
declare class VoiceClientImpl implements VoiceClient {
|
|
26
|
-
config: VoiceClientConfig;
|
|
27
|
-
verbsStream: Stream;
|
|
28
|
-
transcriptionsStream: Stream;
|
|
29
|
-
ari: Client;
|
|
30
|
-
bridge: Bridge;
|
|
31
|
-
private authHandler;
|
|
32
|
-
private audioSocketHandler;
|
|
33
|
-
private externalMediaHandler;
|
|
34
|
-
private grpcHandler;
|
|
35
|
-
private speechHandler;
|
|
36
|
-
private readonly audioFilters;
|
|
37
|
-
private _tts;
|
|
38
|
-
private _stt;
|
|
39
|
-
constructor(params: {
|
|
40
|
-
ari: Client;
|
|
41
|
-
config: VoiceClientConfig;
|
|
42
|
-
tts: TextToSpeech;
|
|
43
|
-
stt: SpeechToText;
|
|
44
|
-
});
|
|
45
|
-
connect(): Promise<void>;
|
|
46
|
-
sendResponse(response: VoiceIn): void;
|
|
47
|
-
on(type: string, callback: (data: VoiceIn) => void): void;
|
|
48
|
-
synthesize(text: string, options: SayOptions): Promise<string>;
|
|
49
|
-
stopSynthesis(): Promise<void>;
|
|
50
|
-
transcribe(): Promise<SpeechResult>;
|
|
51
|
-
startSpeechGather(callback: (stream: {
|
|
52
|
-
speech: string;
|
|
53
|
-
responseTime: number;
|
|
54
|
-
}) => void): void;
|
|
55
|
-
startDtmfGather(mediaSessionRef: string, callback: (event: {
|
|
56
|
-
digit: string;
|
|
57
|
-
}) => void): Promise<void>;
|
|
58
|
-
waitForDtmf(params: {
|
|
59
|
-
mediaSessionRef: string;
|
|
60
|
-
finishOnKey: string;
|
|
61
|
-
maxDigits: number;
|
|
62
|
-
timeout: number;
|
|
63
|
-
onDigitReceived: () => void;
|
|
64
|
-
}): Promise<{
|
|
65
|
-
digits: string;
|
|
66
|
-
}>;
|
|
67
|
-
stopStreamGather(): void;
|
|
68
|
-
getTranscriptionsStream(): Stream;
|
|
69
|
-
/**
|
|
70
|
-
* Replaces the session's audio filters. Rejects when they cannot be
|
|
71
|
-
* applied, leaving the call on whatever it had before.
|
|
72
|
-
*/
|
|
73
|
-
setAudioFilters(filters: AudioFilterConfig[]): Promise<void>;
|
|
74
|
-
close(): void;
|
|
75
|
-
private logFilterStats;
|
|
76
|
-
get tts(): TextToSpeech;
|
|
77
|
-
get stt(): SpeechToText;
|
|
78
|
-
}
|
|
79
|
-
export { VoiceClientImpl };
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.VoiceClientImpl = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
15
|
-
* http://github.com/fonoster/fonoster
|
|
16
|
-
*
|
|
17
|
-
* This file is part of Fonoster
|
|
18
|
-
*
|
|
19
|
-
* Licensed under the MIT License (the "License");
|
|
20
|
-
* you may not use this file except in compliance with
|
|
21
|
-
* the License. You may obtain a copy of the License at
|
|
22
|
-
*
|
|
23
|
-
* https://opensource.org/licenses/MIT
|
|
24
|
-
*
|
|
25
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
26
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
27
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
|
-
* See the License for the specific language governing permissions and
|
|
29
|
-
* limitations under the License.
|
|
30
|
-
*/
|
|
31
|
-
const stream_1 = require("stream");
|
|
32
|
-
const logger_1 = require("@fonoster/logger");
|
|
33
|
-
const pick_port_1 = require("pick-port");
|
|
34
|
-
const filters_1 = require("../filters");
|
|
35
|
-
const AudioSocketHandler_1 = require("./AudioSocketHandler");
|
|
36
|
-
const AuthorizationHandler_1 = require("./AuthorizationHandler");
|
|
37
|
-
const ExternalMediaHandler_1 = require("./ExternalMediaHandler");
|
|
38
|
-
const GrpcClientHandler_1 = require("./GrpcClientHandler");
|
|
39
|
-
const SpeechHandler_1 = require("./SpeechHandler");
|
|
40
|
-
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
41
|
-
class VoiceClientImpl {
|
|
42
|
-
constructor(params) {
|
|
43
|
-
// Owns the call's filter chain: building, replacing and retiring it
|
|
44
|
-
this.audioFilters = (0, filters_1.createAudioFilterSession)();
|
|
45
|
-
const { config, tts, stt, ari } = params;
|
|
46
|
-
this.config = config;
|
|
47
|
-
this.ari = ari;
|
|
48
|
-
this._tts = tts;
|
|
49
|
-
this._stt = stt;
|
|
50
|
-
this.verbsStream = new stream_1.Stream();
|
|
51
|
-
this.transcriptionsStream = new stream_1.Stream();
|
|
52
|
-
// Initialize component handlers
|
|
53
|
-
this.authHandler = new AuthorizationHandler_1.AuthorizationHandler({
|
|
54
|
-
config: this.config,
|
|
55
|
-
ari: this.ari
|
|
56
|
-
});
|
|
57
|
-
this.audioSocketHandler = new AudioSocketHandler_1.AudioSocketHandler({
|
|
58
|
-
transcriptionsStream: this.transcriptionsStream,
|
|
59
|
-
config: this.config,
|
|
60
|
-
getFilterChain: () => this.audioFilters.current()
|
|
61
|
-
});
|
|
62
|
-
this.externalMediaHandler = new ExternalMediaHandler_1.ExternalMediaHandler({
|
|
63
|
-
ari: this.ari,
|
|
64
|
-
config: this.config
|
|
65
|
-
});
|
|
66
|
-
this.grpcHandler = new GrpcClientHandler_1.GrpcClientHandler({
|
|
67
|
-
config: this.config,
|
|
68
|
-
verbsStream: this.verbsStream
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
connect() {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
// Check authorization
|
|
74
|
-
const isAuthorized = yield this.authHandler.checkAuthorization();
|
|
75
|
-
if (!isAuthorized) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// Set up audio socket and external media
|
|
79
|
-
const externalMediaPort = yield (0, pick_port_1.pickPort)({ type: "tcp" });
|
|
80
|
-
logger.verbose("picked external media port", { port: externalMediaPort });
|
|
81
|
-
// Wait for both audio socket and external media setup to complete
|
|
82
|
-
yield Promise.all([
|
|
83
|
-
this.audioSocketHandler.setupAudioSocket(externalMediaPort),
|
|
84
|
-
this.externalMediaHandler.setupExternalMedia(externalMediaPort)
|
|
85
|
-
]);
|
|
86
|
-
// Get the bridge from the external media handler
|
|
87
|
-
this.bridge = this.externalMediaHandler.getBridge();
|
|
88
|
-
// Initialize speech handler now that we have the audio stream
|
|
89
|
-
this.speechHandler = new SpeechHandler_1.SpeechHandler({
|
|
90
|
-
tts: this._tts,
|
|
91
|
-
stt: this._stt,
|
|
92
|
-
ari: this.ari,
|
|
93
|
-
transcriptionsStream: this.transcriptionsStream,
|
|
94
|
-
audioStream: this.audioSocketHandler.getAudioStream(),
|
|
95
|
-
mediaSessionRef: this.config.mediaSessionRef
|
|
96
|
-
});
|
|
97
|
-
// Set up the GRPC client LAST. Opening the session immediately writes the request
|
|
98
|
-
// that starts the voice application, so nothing it may depend on can still be
|
|
99
|
-
// pending when that happens — the Say handler needs the speech handler built just
|
|
100
|
-
// above, and the caller attaches the verb listeners before calling connect (see
|
|
101
|
-
// VoiceDispatcher.handleStasisStart). Doing this first let a fast application's
|
|
102
|
-
// opening verbs arrive before the client could serve them.
|
|
103
|
-
yield this.grpcHandler.setupGrpcClient();
|
|
104
|
-
logger.verbose("voice client setup completed");
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
// Public API methods required by VoiceClient interface
|
|
108
|
-
sendResponse(response) {
|
|
109
|
-
this.grpcHandler.sendResponse(response);
|
|
110
|
-
}
|
|
111
|
-
on(type, callback) {
|
|
112
|
-
this.verbsStream.on(type.toString(), (data) => {
|
|
113
|
-
callback(data[type]);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
synthesize(text, options) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
return this.speechHandler.synthesize(text, options);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
stopSynthesis() {
|
|
122
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
return this.speechHandler.stopSynthesis();
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
transcribe() {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
return this.speechHandler.transcribe();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
startSpeechGather(callback) {
|
|
132
|
-
this.speechHandler.startSpeechGather(callback);
|
|
133
|
-
}
|
|
134
|
-
startDtmfGather(mediaSessionRef, callback) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
return this.speechHandler.startDtmfGather(callback);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
waitForDtmf(params) {
|
|
140
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
-
const { finishOnKey, maxDigits, timeout, onDigitReceived } = params;
|
|
142
|
-
return this.speechHandler.waitForDtmf({
|
|
143
|
-
finishOnKey,
|
|
144
|
-
maxDigits,
|
|
145
|
-
timeout,
|
|
146
|
-
onDigitReceived
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
stopStreamGather() {
|
|
151
|
-
this.speechHandler.stopStreamGather();
|
|
152
|
-
}
|
|
153
|
-
getTranscriptionsStream() {
|
|
154
|
-
return this.transcriptionsStream;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Replaces the session's audio filters. Rejects when they cannot be
|
|
158
|
-
* applied, leaving the call on whatever it had before.
|
|
159
|
-
*/
|
|
160
|
-
setAudioFilters(filters) {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
yield this.audioFilters.set(filters);
|
|
163
|
-
logger.verbose("audio filters set", {
|
|
164
|
-
mediaSessionRef: this.config.mediaSessionRef,
|
|
165
|
-
filters: filters.map((filter) => filter.name)
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
close() {
|
|
170
|
-
this.logFilterStats(this.audioFilters.close());
|
|
171
|
-
this.grpcHandler.close();
|
|
172
|
-
this.audioSocketHandler.close();
|
|
173
|
-
}
|
|
174
|
-
// One line per filtered call, so filter cost and any filter that gave up are
|
|
175
|
-
// visible in production without turning on verbose logging
|
|
176
|
-
logFilterStats(stats) {
|
|
177
|
-
if (!stats) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
logger.info("audio filter stats for session", {
|
|
181
|
-
mediaSessionRef: this.config.mediaSessionRef,
|
|
182
|
-
frames: stats.total.frames,
|
|
183
|
-
p50Ms: stats.total.p50Ms,
|
|
184
|
-
p95Ms: stats.total.p95Ms,
|
|
185
|
-
delayMs: stats.total.delayMs,
|
|
186
|
-
disabled: stats.filters
|
|
187
|
-
.filter((filter) => filter.disabled)
|
|
188
|
-
.map((filter) => `${filter.name}: ${filter.error}`)
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
get tts() {
|
|
192
|
-
return this._tts;
|
|
193
|
-
}
|
|
194
|
-
get stt() {
|
|
195
|
-
return this._stt;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
exports.VoiceClientImpl = VoiceClientImpl;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.connectToAri = connectToAri;
|
|
16
|
-
/**
|
|
17
|
-
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
18
|
-
* http://github.com/fonoster/fonoster
|
|
19
|
-
*
|
|
20
|
-
* This file is part of Fonoster
|
|
21
|
-
*
|
|
22
|
-
* Licensed under the MIT License (the "License");
|
|
23
|
-
* you may not use this file except in compliance with
|
|
24
|
-
* the License. You may obtain a copy of the License at
|
|
25
|
-
*
|
|
26
|
-
* https://opensource.org/licenses/MIT
|
|
27
|
-
*
|
|
28
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
29
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
30
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
31
|
-
* See the License for the specific language governing permissions and
|
|
32
|
-
* limitations under the License.
|
|
33
|
-
*/
|
|
34
|
-
const logger_1 = require("@fonoster/logger");
|
|
35
|
-
const ari_client_1 = __importDefault(require("ari-client"));
|
|
36
|
-
const nats_1 = require("nats");
|
|
37
|
-
const wait_port_1 = __importDefault(require("wait-port"));
|
|
38
|
-
const db_1 = require("../core/db");
|
|
39
|
-
const envs_1 = require("../envs");
|
|
40
|
-
const createCreateVoiceClient_1 = require("./createCreateVoiceClient");
|
|
41
|
-
const integrations_1 = require("./integrations");
|
|
42
|
-
const types_1 = require("./types");
|
|
43
|
-
const VoiceDispatcher_1 = require("./VoiceDispatcher");
|
|
44
|
-
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
45
|
-
const connection = {
|
|
46
|
-
host: envs_1.ASTERISK_ARI_PROXY_URL.split("//")[1].split(":")[0],
|
|
47
|
-
port: parseInt(envs_1.ASTERISK_ARI_PROXY_URL.split("//")[1].split(":")[1]),
|
|
48
|
-
timeout: 5000,
|
|
49
|
-
output: "silent"
|
|
50
|
-
};
|
|
51
|
-
function connectToAri(filesServer) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
logger.info("waiting for asterisk server");
|
|
54
|
-
const open = yield (0, wait_port_1.default)(connection);
|
|
55
|
-
if (open) {
|
|
56
|
-
const ari = yield ari_client_1.default.connect(envs_1.ASTERISK_ARI_PROXY_URL, envs_1.ASTERISK_ARI_USERNAME, envs_1.ASTERISK_ARI_SECRET);
|
|
57
|
-
ari.on(types_1.AriEvent.WEB_SOCKET_RECONNECTING, () => {
|
|
58
|
-
logger.info("reconnecting to asterisk");
|
|
59
|
-
});
|
|
60
|
-
ari.on(types_1.AriEvent.WEB_SOCKET_MAX_RETRIES, () => {
|
|
61
|
-
logger.error("max retries reconnecting to asterisk");
|
|
62
|
-
attemptReconnection(filesServer);
|
|
63
|
-
});
|
|
64
|
-
logger.info("asterisk is ready");
|
|
65
|
-
const createContainer = (0, integrations_1.createCreateContainer)(db_1.prisma, envs_1.INTEGRATIONS_FILE);
|
|
66
|
-
const nats = yield (0, nats_1.connect)({ servers: envs_1.NATS_URL, maxReconnectAttempts: -1 });
|
|
67
|
-
const dispatcher = new VoiceDispatcher_1.VoiceDispatcher(ari, nats, (0, createCreateVoiceClient_1.createCreateVoiceClient)(createContainer));
|
|
68
|
-
dispatcher.start();
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
logger.error("asterisk is not ready");
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function attemptReconnection(filesServer) {
|
|
77
|
-
logger.info("attempting to reconnect in 5 seconds...");
|
|
78
|
-
setTimeout(() => {
|
|
79
|
-
connectToAri(filesServer);
|
|
80
|
-
}, 5000); // Reconnect after 5 seconds
|
|
81
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Channel, Client, StasisStart } from "ari-client";
|
|
2
|
-
import { CreateContainer } from "./integrations/types";
|
|
3
|
-
import { VoiceClient } from "./types";
|
|
4
|
-
declare function createCreateVoiceClient(createContainer: CreateContainer): (params: {
|
|
5
|
-
ari: Client;
|
|
6
|
-
event: StasisStart;
|
|
7
|
-
channel: Channel;
|
|
8
|
-
}) => Promise<VoiceClient>;
|
|
9
|
-
export { createCreateVoiceClient };
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createCreateVoiceClient = createCreateVoiceClient;
|
|
13
|
-
/**
|
|
14
|
-
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
15
|
-
* http://github.com/fonoster/fonoster
|
|
16
|
-
*
|
|
17
|
-
* This file is part of Fonoster
|
|
18
|
-
*
|
|
19
|
-
* Licensed under the MIT License (the "License");
|
|
20
|
-
* you may not use this file except in compliance with
|
|
21
|
-
* the License. You may obtain a copy of the License at
|
|
22
|
-
*
|
|
23
|
-
* https://opensource.org/licenses/MIT
|
|
24
|
-
*
|
|
25
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
26
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
27
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
|
-
* See the License for the specific language governing permissions and
|
|
29
|
-
* limitations under the License.
|
|
30
|
-
*/
|
|
31
|
-
const identity_1 = require("@fonoster/identity");
|
|
32
|
-
const logger_1 = require("@fonoster/logger");
|
|
33
|
-
const types_1 = require("@fonoster/types");
|
|
34
|
-
const uuid_1 = require("uuid");
|
|
35
|
-
const identityConfig_1 = require("../core/identityConfig");
|
|
36
|
-
const amdResultCache_1 = require("../events/amdResultCache");
|
|
37
|
-
const mapCallDirectionToEnum_1 = require("../events/mapCallDirectionToEnum");
|
|
38
|
-
const mapAsteriskAmd_1 = require("./amd/mapAsteriskAmd");
|
|
39
|
-
const client_1 = require("./client");
|
|
40
|
-
const types_2 = require("./types");
|
|
41
|
-
const createGetChannelVarWithoutThrow_1 = require("./utils/createGetChannelVarWithoutThrow");
|
|
42
|
-
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
43
|
-
const generateCallAccessToken = (0, identity_1.createGenerateCallAccessToken)(identityConfig_1.identityConfig);
|
|
44
|
-
// Note: By the time the call arrives here the owner of the app MUST be authenticated
|
|
45
|
-
function createCreateVoiceClient(createContainer) {
|
|
46
|
-
return function createVoiceClient(params) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
49
|
-
const { ari, event, channel } = params;
|
|
50
|
-
const { id: mediaSessionRef, caller } = event.channel;
|
|
51
|
-
const { name: callerName, number: callerNumber } = caller;
|
|
52
|
-
const getChannelVar = (0, createGetChannelVarWithoutThrow_1.createGetChannelVarWithoutThrow)(channel);
|
|
53
|
-
// Variables set by Asterisk's dialplan
|
|
54
|
-
const callDirection = (_a = (yield getChannelVar(types_2.ChannelVar.CALL_DIRECTION))) === null || _a === void 0 ? void 0 : _a.value;
|
|
55
|
-
const appRef = (_b = (yield getChannelVar(types_2.ChannelVar.APP_REF))) === null || _b === void 0 ? void 0 : _b.value;
|
|
56
|
-
const ingressNumber = ((_c = (yield getChannelVar(types_2.ChannelVar.INGRESS_NUMBER))) === null || _c === void 0 ? void 0 : _c.value) || "";
|
|
57
|
-
// Try to get callRef from channel variable (set by dialplan from X-Call-Ref header for API-originated calls)
|
|
58
|
-
// If not found, generate a new UUID (for PSTN-terminated calls)
|
|
59
|
-
const callRefFromChannel = (_d = (yield getChannelVar(types_2.ChannelVar.CALL_REF))) === null || _d === void 0 ? void 0 : _d.value;
|
|
60
|
-
const callRef = callRefFromChannel || (0, uuid_1.v4)();
|
|
61
|
-
const { accessKeyId, endpoint, tts, stt } = yield createContainer(appRef);
|
|
62
|
-
const sessionToken = yield generateCallAccessToken({ accessKeyId, appRef });
|
|
63
|
-
const metadataStr = (_f = (_e = (yield getChannelVar(types_2.ChannelVar.METADATA))) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : "{}";
|
|
64
|
-
const callDirectionEnum = (0, mapCallDirectionToEnum_1.mapCallDirectionToEnum)(callDirection);
|
|
65
|
-
// Answering Machine Detection. AMD() runs in the dialplan before Stasis, so
|
|
66
|
-
// by the time we get here the verdict is already on the channel — undefined
|
|
67
|
-
// when AMD is off or the media server predates the AMD dialplan. Only
|
|
68
|
-
// outbound calls are ever classified (an inbound channel has not been
|
|
69
|
-
// answered when the dialplan runs), so don't pay the lookup on any other
|
|
70
|
-
// direction: an unset channel variable costs a round-trip that 404s.
|
|
71
|
-
const amd = callDirectionEnum === types_1.CallDirection.TO_PSTN
|
|
72
|
-
? (0, mapAsteriskAmd_1.mapAsteriskAmd)((_g = (yield getChannelVar(types_2.ChannelVar.AMD_STATUS))) === null || _g === void 0 ? void 0 : _g.value)
|
|
73
|
-
: undefined;
|
|
74
|
-
const config = Object.assign({ appRef,
|
|
75
|
-
mediaSessionRef,
|
|
76
|
-
callRef,
|
|
77
|
-
accessKeyId,
|
|
78
|
-
endpoint,
|
|
79
|
-
callerName,
|
|
80
|
-
callerNumber,
|
|
81
|
-
ingressNumber,
|
|
82
|
-
sessionToken, callDirection: callDirectionEnum, metadata: JSON.parse(metadataStr) }, (amd ? { amd } : {}));
|
|
83
|
-
if (amd) {
|
|
84
|
-
// AMDCAUSE says which threshold fired. It is not part of the session
|
|
85
|
-
// contract, so it rides to the CDR on its own for offline tuning.
|
|
86
|
-
amdResultCache_1.amdResultCache.set(callRef, Object.assign(Object.assign({}, amd), { cause: (_j = (_h = (yield getChannelVar(types_2.ChannelVar.AMD_CAUSE))) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : "" }));
|
|
87
|
-
}
|
|
88
|
-
logger.verbose("creating voice client with config: ", {
|
|
89
|
-
appRef,
|
|
90
|
-
callerNumber,
|
|
91
|
-
ingressNumber,
|
|
92
|
-
amdStatus: amd === null || amd === void 0 ? void 0 : amd.status
|
|
93
|
-
});
|
|
94
|
-
return new client_1.VoiceClientImpl({ ari, config, tts, stt });
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
3
|
-
* http://github.com/fonoster/fonoster
|
|
4
|
-
*
|
|
5
|
-
* This file is part of Fonoster
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the MIT License (the "License");
|
|
8
|
-
* you may not use this file except in compliance with
|
|
9
|
-
* the License. You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* https://opensource.org/licenses/MIT
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
import { ChannelVar } from "../types";
|
|
20
|
-
declare class ChannelVarNotFoundError extends Error {
|
|
21
|
-
constructor(variable: ChannelVar);
|
|
22
|
-
}
|
|
23
|
-
export { ChannelVarNotFoundError };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChannelVarNotFoundError = void 0;
|
|
4
|
-
class ChannelVarNotFoundError extends Error {
|
|
5
|
-
constructor(variable) {
|
|
6
|
-
super(`Channel variable not found: ${variable}`);
|
|
7
|
-
this.name = this.constructor.name;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.ChannelVarNotFoundError = ChannelVarNotFoundError;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
3
|
-
* http://github.com/fonoster/fonoster
|
|
4
|
-
*
|
|
5
|
-
* This file is part of Fonoster
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the MIT License (the "License");
|
|
8
|
-
* you may not use this file except in compliance with
|
|
9
|
-
* the License. You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* https://opensource.org/licenses/MIT
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
declare class MethodNotImplementedError extends Error {
|
|
20
|
-
constructor();
|
|
21
|
-
}
|
|
22
|
-
export { MethodNotImplementedError };
|