UNPKG

@sirhc77/signalwire-rest-sdk

Version:

An SDK for the SignalWire REST API

1,152 lines 109 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertCreateCallRequestToJSON = convertCreateCallRequestToJSON; exports.convertUpdateCallRequestToJSON = convertUpdateCallRequestToJSON; exports.convertJSONToCallResponse = convertJSONToCallResponse; exports.convertJSONToDocument = convertJSONToDocument; exports.convertJSONToSearchDocumentsResponse = convertJSONToSearchDocumentsResponse; exports.convertCreateDocumentRequestToJSON = convertCreateDocumentRequestToJSON; exports.convertSearchDocumentRequestToJSON = convertSearchDocumentRequestToJSON; exports.convertJSONToDatasphereDocumentChunk = convertJSONToDatasphereDocumentChunk; exports.convertJSONToFabricAddress = convertJSONToFabricAddress; exports.convertJSONToSwmlWebhook = convertJSONToSwmlWebhook; exports.convertJSONToSwmlWebhookResponse = convertJSONToSwmlWebhookResponse; exports.convertCreateSwmlWebhookRequestToJSON = convertCreateSwmlWebhookRequestToJSON; exports.convertJSONToSwmlApplication = convertJSONToSwmlApplication; exports.convertJSONToSwmlApplicationResponse = convertJSONToSwmlApplicationResponse; exports.convertCreateSwmlApplicationRequestToJSON = convertCreateSwmlApplicationRequestToJSON; exports.convertUpdateSwmlApplicationRequestToJSON = convertUpdateSwmlApplicationRequestToJSON; exports.convertJSONToLamlApplication = convertJSONToLamlApplication; exports.convertJSONToLamlApplicationResponse = convertJSONToLamlApplicationResponse; exports.convertUpdateLamlApplicationRequestToJSON = convertUpdateLamlApplicationRequestToJSON; exports.convertJSONToCXMLScript = convertJSONToCXMLScript; exports.convertJSONToCXMLScriptResponse = convertJSONToCXMLScriptResponse; exports.convertJSONToCXMLWebhook = convertJSONToCXMLWebhook; exports.convertJSONToCXMLWebhookResponse = convertJSONToCXMLWebhookResponse; exports.convertCreateCXMLWebhookRequestToJSON = convertCreateCXMLWebhookRequestToJSON; exports.convertUpdateCXMLWebhookRequestToJSON = convertUpdateCXMLWebhookRequestToJSON; exports.convertUpdateSwmlWebhookRequestToJSON = convertUpdateSwmlWebhookRequestToJSON; exports.convertJSONToDomainApplication = convertJSONToDomainApplication; exports.convertUpdateDomainApplicationRequestToJSON = convertUpdateDomainApplicationRequestToJSON; exports.convertJSONToPhoneNumberCallHandler = convertJSONToPhoneNumberCallHandler; exports.convertJSONToMessageHandler = convertJSONToMessageHandler; exports.convertJSONToPhoneNumber = convertJSONToPhoneNumber; exports.convertPhoneNumberCallHandlerToJSON = convertPhoneNumberCallHandlerToJSON; exports.convertPhoneNumberMessageHandlerToJSON = convertPhoneNumberMessageHandlerToJSON; exports.convertUpdatePhoneNumberRequestToJSON = convertUpdatePhoneNumberRequestToJSON; exports.convertJSONToLookupNumberResponse = convertJSONToLookupNumberResponse; exports.convertJSONToSipEndpointCallHandler = convertJSONToSipEndpointCallHandler; exports.convertJSONToSipEndpoint = convertJSONToSipEndpoint; exports.convertSipEndpointCallHandlerToJSON = convertSipEndpointCallHandlerToJSON; exports.convertUpdateSipEndpointRequestToJSON = convertUpdateSipEndpointRequestToJSON; exports.convertCreateSipEndpointRequestToJSON = convertCreateSipEndpointRequestToJSON; exports.convertJSONToRecording = convertJSONToRecording; exports.convertJSONToVideoRoomSession = convertJSONToVideoRoomSession; exports.convertJSONToVideoRoom = convertJSONToVideoRoom; exports.convertJSONToVideoRoomRecording = convertJSONToVideoRoomRecording; exports.convertJSONToVideoRoomSessionMember = convertJSONToVideoRoomSessionMember; exports.convertJSONToVideoRoomStream = convertJSONToVideoRoomStream; exports.convertJSONToVideoConference = convertJSONToVideoConference; exports.convertJSONToVideoConferenceToken = convertJSONToVideoConferenceToken; exports.convertJSONToCharge = convertJSONToCharge; exports.convertJSONToVoiceLog = convertJSONToVoiceLog; exports.convertJSONToVideoLog = convertJSONToVideoLog; exports.convertJSONToMessageLog = convertJSONToMessageLog; exports.convertJSONToFaxLog = convertJSONToFaxLog; exports.convertJSONToFabricResourceAddress = convertJSONToFabricResourceAddress; exports.convertJSONToFabricSubscriber = convertJSONToFabricSubscriber; exports.convertJSONToFabricSubscriberResponse = convertJSONToFabricSubscriberResponse; exports.convertUpdateCallFlowRequestToJSON = convertUpdateCallFlowRequestToJSON; exports.convertCreateCallFlowRequestToJSON = convertCreateCallFlowRequestToJSON; exports.convertJSONToCallFlow = convertJSONToCallFlow; exports.convertJSONToCallFlowResponse = convertJSONToCallFlowResponse; exports.convertJSONToCallFlowVersion = convertJSONToCallFlowVersion; exports.convertJSONToContextStep = convertJSONToContextStep; exports.convertJSONToAiAgentPrompt = convertJSONToAiAgentPrompt; exports.convertJSONToAiAgentPostPrompt = convertJSONToAiAgentPostPrompt; exports.convertJSONToAiAgentParams = convertJSONToAiAgentParams; exports.convertJSONToAiAgentPronounce = convertJSONToAiAgentPronounce; exports.convertJSONToAiAgentLanguages = convertJSONToAiAgentLanguages; exports.convertJSONToAiAgentSWAIGIncludes = convertJSONToAiAgentSWAIGIncludes; exports.convertJSONToSWAIGFunctionProperty = convertJSONToSWAIGFunctionProperty; exports.convertJSONToSWAIGFunctionParameters = convertJSONToSWAIGFunctionParameters; exports.convertJSONToSWAIGAction = convertJSONToSWAIGAction; exports.convertJSONToSWAIGExpression = convertJSONToSWAIGExpression; exports.convertJSONToSWAIGDataMap = convertJSONToSWAIGDataMap; exports.convertJSONToAiAgentSWAIGFunctions = convertJSONToAiAgentSWAIGFunctions; exports.convertJSONToAiAgentSWAIG = convertJSONToAiAgentSWAIG; exports.convertJSONToAiAgent = convertJSONToAiAgent; exports.convertJSONToAiAgentResponse = convertJSONToAiAgentResponse; exports.convertContextStepToJSON = convertContextStepToJSON; exports.convertAiAgentPromptContextsBaseToJSON = convertAiAgentPromptContextsBaseToJSON; exports.convertCreateAiAgentPromptRequestToJSON = convertCreateAiAgentPromptRequestToJSON; exports.convertCreateAiAgentPostPromptRequestToJSON = convertCreateAiAgentPostPromptRequestToJSON; exports.convertAiAgentParamsToJSON = convertAiAgentParamsToJSON; exports.convertPronounceToJSON = convertPronounceToJSON; exports.convertLanguagesToJSON = convertLanguagesToJSON; exports.convertSWAIGIncludesToJSON = convertSWAIGIncludesToJSON; exports.convertSWAIGFunctionPropertyToJSON = convertSWAIGFunctionPropertyToJSON; exports.convertSWAIGToggleFunctionToJSON = convertSWAIGToggleFunctionToJSON; exports.convertSWAIGActionToJSON = convertSWAIGActionToJSON; exports.convertSWAIGExpressionToJSON = convertSWAIGExpressionToJSON; exports.convertSWAIGWebhookToJSON = convertSWAIGWebhookToJSON; exports.convertSWAIGDataMapToJSON = convertSWAIGDataMapToJSON; exports.convertSWAIGFunctionsToJSON = convertSWAIGFunctionsToJSON; exports.convertCreateAiAgentRequestToJSON = convertCreateAiAgentRequestToJSON; exports.convertUpdateAiAgentPromptContextsToJSON = convertUpdateAiAgentPromptContextsToJSON; exports.convertUpdateAiAgentPromptRequestToJSON = convertUpdateAiAgentPromptRequestToJSON; exports.convertUpdateAiAgentPostPromptRequestToJSON = convertUpdateAiAgentPostPromptRequestToJSON; exports.convertUpdateAiAgentRequestToJSON = convertUpdateAiAgentRequestToJSON; exports.convertJSONToSwmlScript = convertJSONToSwmlScript; exports.convertJSONToSwmlScriptResponse = convertJSONToSwmlScriptResponse; exports.convertJSONToRelayApplication = convertJSONToRelayApplication; exports.convertJSONToRelayApplicationResponse = convertJSONToRelayApplicationResponse; exports.convertUpdateRelayApplicationRequestToJSON = convertUpdateRelayApplicationRequestToJSON; exports.convertCreateRelayApplicationRequestToJSON = convertCreateRelayApplicationRequestToJSON; exports.convertJSONToFabricSipEndpoint = convertJSONToFabricSipEndpoint; exports.convertJSONToFabricSipEndpointResponse = convertJSONToFabricSipEndpointResponse; exports.convertUpdateFabricSipEndpointRequestToJSON = convertUpdateFabricSipEndpointRequestToJSON; exports.convertCreateFabricSipEndpointRequestToJSON = convertCreateFabricSipEndpointRequestToJSON; exports.convertJSONToSipGateway = convertJSONToSipGateway; exports.convertJSONToSipGatewayResponse = convertJSONToSipGatewayResponse; exports.convertCreateSipGatewayRequestToJSON = convertCreateSipGatewayRequestToJSON; exports.convertUpdateSipGatewayRequestToJSON = convertUpdateSipGatewayRequestToJSON; exports.convertJSONToSubscriberSipEndpoint = convertJSONToSubscriberSipEndpoint; exports.convertCreateSubscriberSipEndpointRequestToJSON = convertCreateSubscriberSipEndpointRequestToJSON; exports.convertUpdateSubscriberEndpointRequestToJSON = convertUpdateSubscriberEndpointRequestToJSON; exports.convertJSONToFreeswitchConnector = convertJSONToFreeswitchConnector; exports.convertJSONToFreeswitchConnectorResponse = convertJSONToFreeswitchConnectorResponse; exports.convertUpdateFreeswitchConnectorRequestToJson = convertUpdateFreeswitchConnectorRequestToJson; exports.convertCreateFreeswitchConnectorRequestToJson = convertCreateFreeswitchConnectorRequestToJson; exports.convertJSONToDialogflowAgent = convertJSONToDialogflowAgent; exports.convertJSONToDialogflowAgentResponse = convertJSONToDialogflowAgentResponse; exports.convertUpdateDialogflowAgentRequestToJSON = convertUpdateDialogflowAgentRequestToJSON; exports.convertJSONToConferenceRoom = convertJSONToConferenceRoom; exports.convertJSONToConferenceRoomResponse = convertJSONToConferenceRoomResponse; exports.convertCreateConferenceRoomRequestToJSON = convertCreateConferenceRoomRequestToJSON; exports.convertUpdateConferenceRoomRequestToJSON = convertUpdateConferenceRoomRequestToJSON; exports.convertGeneratePubSubTokenRequestToJSON = convertGeneratePubSubTokenRequestToJSON; exports.convertJSONToFabricResourceResponse = convertJSONToFabricResourceResponse; const swmlModelConverters_1 = require("./swmlModelConverters"); function convertCreateCallRequestToJSON(request) { switch (request.type) { case 'url': return { command: request.command, params: { from: request.params.from, to: request.params.to, caller_id: request.params.callerId, fallback_url: request.params.fallbackUrl, url: request.params.url, }, }; case 'swml': return { command: request.command, params: { from: request.params.from, to: request.params.to, caller_id: request.params.callerId, fallback_url: request.params.fallbackUrl, swml: (0, swmlModelConverters_1.convertSWMLToJSON)(request.params.swml), }, }; } } function convertUpdateCallRequestToJSON(request) { switch (request.type) { case 'url': return { command: request.command, params: { id: request.params.id, fallback_url: request.params.fallbackUrl, status: request.params.status, url: request.params.url, } }; case 'swml': return { command: request.command, params: { id: request.params.id, fallback_url: request.params.fallbackUrl, status: request.params.status, swml: request.params.swml === undefined ? undefined : (0, swmlModelConverters_1.convertSWMLToJSON)(request.params.swml), } }; } } function convertJSONToCallResponse(json) { return { id: json.id, from: json.from, to: json.to, direction: json.direction, status: json.status, duration: json.duration, durationMS: json.duration_ms, billableDuration: json.billable_duration, source: json.source, type: json.type, chargeDetails: json.charge_details.map((chargeJSON) => ({ description: chargeJSON.description, amount: chargeJSON.amount })), }; } function convertJSONToDocument(json) { return { id: json.id, filename: json.filename, status: json.status, tags: json.tags, chunkingStrategy: json.chunking_strategy, maxSentencesPerChunk: json.max_sentences_per_chunk, splitNewlines: json.split_newlines, overlapSize: json.overlap_size, chunkSize: json.chunk_size, createdAt: json.created_at, updatedAt: json.updated_at, numberOfChunks: json.number_of_chunks }; } function convertJSONToSearchDocumentsResponse(json) { return { chunks: json.chunks.map((chunkJSON) => ({ text: chunkJSON.text, documentId: chunkJSON.document_id })) }; } function convertCreateDocumentRequestToJSON(request) { const baseJSON = { url: request.url, tags: request.tags }; switch (request.chunkingStrategy) { case 'sentence': return Object.assign(Object.assign({}, baseJSON), { chunking_strategy: 'sentence', max_sentences_per_chunk: request.maxSentencesPerChunk, split_newlines: request.splitNewlines }); case 'sliding': return Object.assign(Object.assign({}, baseJSON), { chunking_strategy: 'sliding', overlap_size: request.overlapSize, chunk_size: request.chunkSize }); case 'page': return Object.assign({ chunking_strategy: 'page' }, baseJSON); case 'paragraph': return Object.assign({ chunking_strategy: 'paragraph' }, baseJSON); default: throw new Error('Unknown chunking strategy'); } } function convertSearchDocumentRequestToJSON(request) { return { tags: request.tags, document_id: request.documentId, query_string: request.queryString, distance: request.distance, count: request.count, language: request.language, pos_to_expand: request.posToExpand, max_synonyms: request.maxSynonyms }; } function convertJSONToDatasphereDocumentChunk(json) { return { id: json.id, datasphereDocumentId: json.datasphere_document_id, projectId: json.project_id, status: json.status, tags: json.tags, content: json.content, createdAt: json.created_at, updatedAt: json.updated_at }; } function convertJSONToFabricAddress(json) { return { id: json.id, name: json.name, displayName: json.display_name, type: json.type, coverUrl: json.cover_url, previewUrl: json.preview_url, locked: json.locked, channels: { video: json.channels.video, audio: json.channels.audio, messaging: json.channels.messaging }, createdAt: json.created_at, }; } function convertJSONToSwmlWebhook(json) { return { id: json.id, name: json.name, usedFor: json.used_for, primaryRequestUrl: json.primary_request_url, primaryRequestMethod: json.primary_request_method, fallbackRequestUrl: json.fallback_request_url, fallbackRequestMethod: json.fallback_request_method, statusCallbackUrl: json.status_callback_url, statusCallbackMethod: json.status_callback_method, }; } function convertJSONToSwmlWebhookResponse(json) { return { id: json.id, projectId: json.project_id, displayName: json.display_name, type: json.type, createdAt: json.created_at, updatedAt: json.updated_at, swmlWebhook: convertJSONToSwmlWebhook(json.swml_webhook) }; } function convertCreateSwmlWebhookRequestToJSON(request) { return { name: request.name, used_for: request.usedFor, primary_request_url: request.primaryRequestUrl, primary_request_method: request.primaryRequestMethod, fallback_request_url: request.fallbackRequestUrl, fallback_request_method: request.fallbackRequestMethod, status_callback_url: request.statusCallbackUrl, status_callback_method: request.statusCallbackMethod, }; } function convertJSONToSwmlApplication(json) { return { id: json.id, name: json.name, handleCallsUsing: json.handle_calls_using, callHandlerUrl: json.call_handler_url, callHandlerMethod: json.call_handler_method, callHandlerFallbackUrl: json.call_handler_fallback_url, callHandlerFallbackMethod: json.call_handler_fallback_method, callStatusCallbackUrl: json.call_status_callback_url, callStatusCallbackMethod: json.call_status_callback_method, callHandlerScript: json.call_handler_script === undefined ? undefined : (0, swmlModelConverters_1.convertJSONToSWML)(json.call_handler_script) }; } function convertJSONToSwmlApplicationResponse(json) { return { id: json.id, projectId: json.project_id, displayName: json.display_name, type: 'swml_application', createdAt: json.created_at, updatedAt: json.updated_at, swmlApplication: convertJSONToSwmlApplication(json.swml_application), }; } function convertCreateSwmlApplicationRequestToJSON(request) { return { name: request.name, handle_calls_using: request.handleCallsUsing, call_handler_url: request.callHandlerUrl, call_handler_method: request.callHandlerMethod, call_handler_fallback_url: request.callHandlerFallbackUrl, call_handler_fallback_method: request.callHandlerFallbackMethod, call_status_callback_url: request.callStatusCallbackUrl, call_status_callback_method: request.callStatusCallbackMethod, call_handler_script: request.callHandlerScript === undefined ? undefined : (0, swmlModelConverters_1.convertSWMLToJSON)(request.callHandlerScript) }; } function convertUpdateSwmlApplicationRequestToJSON(request) { return { name: request.name, handle_calls_using: request.handleCallsUsing, call_handler_url: request.callHandlerUrl, call_handler_method: request.callHandlerMethod, call_handler_fallback_url: request.callHandlerFallbackUrl, call_handler_fallback_method: request.callHandlerFallbackMethod, call_status_callback_url: request.callStatusCallbackUrl, call_status_callback_method: request.callStatusCallbackMethod, call_handler_script: request.callHandlerScript === undefined ? undefined : (0, swmlModelConverters_1.convertSWMLToJSON)(request.callHandlerScript) }; } function convertJSONToLamlApplication(json) { return { id: json.id, accountSid: json.account_sid, voiceUrl: json.voice_url, voiceMethod: json.voice_method, voiceFallbackUrl: json.voice_fallback_url, voiceFallbackMethod: json.voice_fallback_method, statusCallbackUrl: json.status_callback_url, statusCallbackMethod: json.status_callback_method, voiceCallerIdLookup: json.voice_caller_id_lookup, smsUrl: json.sms_url, smsMethod: json.sms_method, smsFallbackUrl: json.sms_fallback_url, smsFallbackMethod: json.sms_fallback_method, smsStatusCallbackUrl: json.sms_status_callback_url, smsStatusCallbackMethod: json.sms_status_callback_method, messageStatusCallback: json.message_status_callback, apiVersion: json.api_version, requestUrl: json.request_url, displayName: json.display_name }; } function convertJSONToLamlApplicationResponse(json) { return { id: json.id, projectId: json.project_id, displayName: json.display_name, type: "cxml_application", createdAt: json.created_at, updatedAt: json.updated_at, lamlApplication: convertJSONToLamlApplication(json.laml_application), }; } function convertUpdateLamlApplicationRequestToJSON(request) { return { name: request.name, call_request_url: request.callRequestUrl, call_request_method: request.callRequestMethod, call_fallback_url: request.callFallbackUrl, call_fallback_method: request.callFallbackMethod, call_status_url: request.callStatusUrl, call_status_method: request.callStatusMethod, message_request_url: request.messageRequestUrl, message_request_method: request.messageRequestMethod, message_fallback_url: request.messageFallbackUrl, message_fallback_method: request.messageFallbackMethod, message_status_url: request.messageStatusUrl, message_status_method: request.messageStatusMethod, }; } function convertJSONToCXMLScript(json) { return { id: json.id, contents: json.contents, requestCount: json.request_count, lastAccessedAt: json.last_accessed_at, requestUrl: json.request_url, displayName: json.display_name }; } function convertJSONToCXMLScriptResponse(json) { return { id: json.id, projectId: json.project_id, displayName: json.display_name, type: json.type, createdAt: json.created_at, updatedAt: json.updated_at, lamlBin: convertJSONToCXMLScript(json.laml_bin) }; } function convertJSONToCXMLWebhook(json) { return { id: json.id, name: json.name, usedFor: json.used_for, primaryRequestUrl: json.primary_request_url, primaryRequestMethod: json.primary_request_method, fallbackRequestUrl: json.fallback_request_url, fallbackRequestMethod: json.fallback_request_method, statusCallbackUrl: json.status_callback_url, statusCallbackMethod: json.status_callback_method, }; } function convertJSONToCXMLWebhookResponse(json) { return { id: json.id, projectId: json.project_id, displayName: json.display_name, type: json.type, createdAt: json.created_at, updatedAt: json.updated_at, cxmlWebhook: convertJSONToCXMLWebhook(json.cxml_webhook) }; } function convertCreateCXMLWebhookRequestToJSON(request) { return { name: request.name, used_for: request.usedFor, primary_request_url: request.primaryRequestUrl, primary_request_method: request.primaryRequestMethod, fallback_request_url: request.fallbackRequestUrl, fallback_request_method: request.fallbackRequestMethod, status_callback_url: request.statusCallbackUrl, status_callback_method: request.statusCallbackMethod }; } function convertUpdateCXMLWebhookRequestToJSON(request) { return { name: request.name, used_for: request.usedFor, primary_request_url: request.primaryRequestUrl, primary_request_method: request.primaryRequestMethod, fallback_request_url: request.fallbackRequestUrl, fallback_request_method: request.fallbackRequestMethod, status_callback_url: request.statusCallbackUrl, status_callback_method: request.statusCallbackMethod }; } function convertUpdateSwmlWebhookRequestToJSON(request) { return { name: request.name, used_for: request.usedFor, primary_request_url: request.primaryRequestUrl, primary_request_method: request.primaryRequestMethod, fallback_request_url: request.fallbackRequestUrl, fallback_request_method: request.fallbackRequestMethod, status_callback_url: request.statusCallbackUrl, status_callback_method: request.statusCallbackMethod }; } function convertJSONToDomainApplicationCallHandler(json) { switch (json.call_handler) { case 'relay_application': return { type: 'relay_application', callRelayApplication: json.call_relay_application }; case 'relay_context': return { type: 'relay_context', callRelayContext: json.call_relay_context, callRelayContextStatusCallbackUrl: json.call_relay_context_status_callback_url }; case 'relay_script': return { type: 'relay_script', callRelayScriptUrl: json.call_relay_script_url }; case 'laml_webhooks': return { type: 'laml_webhooks', callRequestUrl: json.call_request_url, callRequestMethod: json.call_request_method, callFallbackUrl: json.call_fallback_url, callFallbackMethod: json.call_fallback_method, callStatusCallbackUrl: json.call_status_callback_url, callStatusCallbackMethod: json.call_status_callback_method }; case 'laml_application': return { type: 'laml_application', callLamlApplicationId: json.call_laml_application_id }; case 'dialogflow': return { type: 'dialogflow', callDialogflowAgentId: json.call_dialogflow_agent_id }; case 'relay_topic': return { type: 'relay_topic', callRelayTopic: json.call_relay_topic, callRelayTopicStatusCallbackUrl: json.call_relay_topic_status_callback_url }; case 'video_room': return { type: 'video_room', callVideoRoomId: json.call_video_room_id }; case 'ai_agent': return { type: 'ai_agent', callAiAgentId: json.call_ai_agent_id }; case 'call_flow': return { type: 'call_flow', callFlowId: json.call_flow_id, callFlowVersion: json.call_flow_version }; default: throw new Error('Unknown call handler type'); } } function convertJSONToDomainApplication(json) { const callHandler = convertJSONToDomainApplicationCallHandler(json); return { id: json.id, callHandler: callHandler, type: json.type, domain: json.domain, name: json.name, identifier: json.identifier, user: json.user, ipAuthEnabled: json.ip_auth_enabled, ipAuth: json.ip_auth, encryption: json.encryption, codecs: json.codecs, ciphers: json.ciphers, }; } const convertCommonCreateDomainApplicationRequestToJSON = (request) => { const json = {}; if (request.callHandler) { switch (request.callHandler.type) { case 'relay_topic': json.call_handler = 'relay_topic'; if (request.callHandler.callRelayTopic) { json.call_relay_topic = request.callHandler.callRelayTopic; } if (request.callHandler.callRelayTopicStatusCallbackUrl) { json.call_relay_topic_status_callback_url = request.callHandler.callRelayTopicStatusCallbackUrl; } break; case 'relay_application': json.call_handler = 'relay_application'; if (request.callHandler.callRelayApplication) { json.call_relay_application = request.callHandler.callRelayApplication; } break; case "laml_webhooks": json.call_handler = 'laml_webhooks'; if (request.callHandler.callRequestUrl) { json.call_request_url = request.callHandler.callRequestUrl; } if (request.callHandler.callRequestMethod) { json.call_request_method = request.callHandler.callRequestMethod; } if (request.callHandler.callFallbackUrl) { json.call_fallback_url = request.callHandler.callFallbackUrl; } if (request.callHandler.callFallbackMethod) { json.call_fallback_method = request.callHandler.callFallbackMethod; } if (request.callHandler.callStatusCallbackUrl) { json.call_status_callback_url = request.callHandler.callStatusCallbackUrl; } if (request.callHandler.callStatusCallbackMethod) { json.call_status_callback_method = request.callHandler.callStatusCallbackMethod; } break; case 'laml_application': json.call_handler = 'laml_application'; if (request.callHandler.callLamlApplicationId) { json.call_laml_application_id = request.callHandler.callLamlApplicationId; } break; case 'video_room': json.call_handler = 'video_room'; if (request.callHandler.callVideoRoomId) { json.call_video_room_id = request.callHandler.callVideoRoomId; } break; case 'relay_script': json.call_handler = 'relay_script'; if (request.callHandler.callRelayScriptUrl) { json.call_relay_script_url = request.callHandler.callRelayScriptUrl; } break; case 'dialogflow': json.call_handler = 'dialogflow'; if (request.callHandler.callDialogflowAgentId) { json.call_dialogflow_agent_id = request.callHandler.callDialogflowAgentId; } break; case 'ai_agent': json.call_handler = 'ai_agent'; if (request.callHandler.callAiAgentId) { json.call_ai_agent_id = request.callHandler.callAiAgentId; } break; case 'call_flow': json.call_handler = 'call_flow'; if (request.callHandler.callFlowId) { json.call_flow_id = request.callHandler.callFlowId; } if (request.callHandler.callFlowVersion) { json.call_flow_version = request.callHandler.callFlowVersion; } break; case 'relay_context': json.call_handler = 'relay_context'; if (request.callHandler.callRelayContext) { json.call_relay_context = request.callHandler.callRelayContext; } if (request.callHandler.callRelayContextStatusCallbackUrl) { json.call_relay_context_status_callback_url = request.callHandler.callRelayContextStatusCallbackUrl; } break; default: throw new Error('Unknown call handler type'); } } if (request.name) { json.name = request.name; } if (request.identifier) { json.identifier = request.identifier; } if (request.user) { json.user = request.user; } if (request.ipAuthEnabled) { json.ip_auth_enabled = request.ipAuthEnabled; } if (request.ipAuth) { json.ip_auth = request.ipAuth; } if (request.encryption) { json.encryption = request.encryption; } if (request.codecs) { json.codecs = request.codecs; } if (request.ciphers) { json.ciphers = request.ciphers; } return json; }; function convertUpdateDomainApplicationRequestToJSON(request) { const json = convertCommonCreateDomainApplicationRequestToJSON(request); if (request.callHandler) { switch (request.callHandler.type) { case 'relay_topic': json.call_handler = 'relay_topic'; if (request.callHandler.callRelayTopic) { json.call_relay_topic = request.callHandler.callRelayTopic; } if (request.callHandler.callRelayTopicStatusCallbackUrl) { json.call_relay_topic_status_callback_url = request.callHandler.callRelayTopicStatusCallbackUrl; } return json; case 'relay_application': json.call_handler = 'relay_application'; if (request.callHandler.callRelayApplication) { json.call_relay_application = request.callHandler.callRelayApplication; } return json; case "laml_webhooks": json.call_handler = 'laml_webhooks'; if (request.callHandler.callRequestUrl) { json.call_request_url = request.callHandler.callRequestUrl; } if (request.callHandler.callRequestMethod) { json.call_request_method = request.callHandler.callRequestMethod; } if (request.callHandler.callFallbackUrl) { json.call_fallback_url = request.callHandler.callFallbackUrl; } if (request.callHandler.callFallbackMethod) { json.call_fallback_method = request.callHandler.callFallbackMethod; } if (request.callHandler.callStatusCallbackUrl) { json.call_status_callback_url = request.callHandler.callStatusCallbackUrl; } if (request.callHandler.callStatusCallbackMethod) { json.call_status_callback_method = request.callHandler.callStatusCallbackMethod; } return json; case 'laml_application': json.call_handler = 'laml_application'; if (request.callHandler.callLamlApplicationId) { json.call_laml_application_id = request.callHandler.callLamlApplicationId; } return json; case 'video_room': json.call_handler = 'video_room'; if (request.callHandler.callVideoRoomId) { json.call_video_room_id = request.callHandler.callVideoRoomId; } return json; case 'relay_script': json.call_handler = 'relay_script'; if (request.callHandler.callRelayScriptUrl) { json.call_relay_script_url = request.callHandler.callRelayScriptUrl; } return json; case 'dialogflow': json.call_handler = 'dialogflow'; if (request.callHandler.callDialogflowAgentId) { json.call_dialogflow_agent_id = request.callHandler.callDialogflowAgentId; } return json; case 'ai_agent': json.call_handler = 'ai_agent'; if (request.callHandler.callAiAgentId) { json.call_ai_agent_id = request.callHandler.callAiAgentId; } return json; case 'call_flow': json.call_handler = 'call_flow'; if (request.callHandler.callFlowId) { json.call_flow_id = request.callHandler.callFlowId; } if (request.callHandler.callFlowVersion) { json.call_flow_version = request.callHandler.callFlowVersion; } return json; case 'relay_context': json.call_handler = 'relay_context'; if (request.callHandler.callRelayContext) { json.call_relay_context = request.callHandler.callRelayContext; } if (request.callHandler.callRelayContextStatusCallbackUrl) { json.call_relay_context_status_callback_url = request.callHandler.callRelayContextStatusCallbackUrl; } return json; } } } function convertJSONToPhoneNumberCallHandler(json) { switch (json.call_handler) { case 'relay_script': return { type: 'relay_script', callRelayScriptUrl: json.call_relay_script_url }; case 'laml_webhooks': return { type: 'laml_webhooks', callRequestUrl: json.call_request_url, callRequestMethod: json.call_request_method, callFallbackUrl: json.call_fallback_url, callFallbackMethod: json.call_fallback_method, callStatusCallbackUrl: json.call_status_callback_url, callStatusCallbackMethod: json.call_status_callback_method, }; case 'laml_application': return { type: 'laml_application', callLamlApplicationId: json.call_laml_application_id }; case 'dialogflow': return { type: 'dialogflow', callDialogflowAgentId: json.call_dialogflow_agent_id }; case 'relay_topic': return { type: 'relay_topic', callRelayTopic: json.call_relay_topic, callRelayTopicStatusCallbackUrl: json.call_relay_topic_status_callback_url }; case 'relay_context': return { type: 'relay_context', callRelayContext: json.call_relay_context, callRelayContextStatusCallbackUrl: json.call_relay_context_status_callback_url }; case 'relay_application': return { type: 'relay_application', callRelayApplication: json.call_relay_application }; case 'relay_connector': return { type: 'relay_connector', callRelayConnectorId: json.call_relay_connector_id }; case 'relay_sip_endpoint': return { type: 'relay_sip_endpoint', callSipEndpointId: json.call_sip_endpoint_id }; case 'relay_verto_endpoint': return { type: 'relay_verto_endpoint', callVertoResource: json.call_verto_resource }; case 'video_room': return { type: 'video_room', callVideoRoomId: json.call_video_room_id }; default: throw new Error('Unknown call handler type'); } } function convertJSONToMessageHandler(json) { switch (json.message_handler) { case 'laml_webhooks': return { type: 'laml_webhooks', messageRequestUrl: json.message_request_url, messageRequestMethod: json.message_request_method, messageFallbackUrl: json.message_fallback_url, messageFallbackMethod: json.message_fallback_method, messageStatusCallbackUrl: json.message_status_callback_url, messageStatusCallbackMethod: json.message_status_callback_method }; case 'laml_application': return { type: 'laml_application', messageLamlApplicationId: json.message_laml_application_id }; case 'relay_application': return { type: 'relay_application', messageRelayApplicationId: json.message_relay_application_id }; case 'relay_topic': return { type: 'relay_topic', messageRelayTopic: json.message_relay_topic }; case 'relay_context': return { type: 'relay_context', messageRelayContext: json.message_relay_context }; default: throw new Error('Unknown message handler type'); } } function convertJSONToPhoneNumber(json) { return { id: json.id, number: json.number, name: json.name, callHandler: convertJSONToPhoneNumberCallHandler(json), messageHandler: convertJSONToMessageHandler(json), callReceiveMode: json.call_receive_mode, capabilities: json.capabilities, numberType: json.number_type, e911AddressId: json.e911_address_id, createdAt: json.created_at, updatedAt: json.updated_at, nextBilledAt: json.next_billed_at, countryCode: json.country_code }; } function convertPhoneNumberCallHandlerToJSON(callHandler) { if (!callHandler) { return {}; } else { switch (callHandler.type) { case 'relay_script': return { call_handler: 'relay_script', call_relay_script_url: callHandler.callRelayScriptUrl }; case 'laml_webhooks': return { call_handler: 'laml_webhooks', call_request_url: callHandler.callRequestUrl, call_request_method: callHandler.callRequestMethod, call_fallback_url: callHandler.callFallbackUrl, call_fallback_method: callHandler.callFallbackMethod, call_status_callback_url: callHandler.callStatusCallbackUrl, call_status_callback_method: callHandler.callStatusCallbackMethod, }; case 'laml_application': return { call_handler: 'laml_application', call_laml_application_id: callHandler.callLamlApplicationId }; case 'dialogflow': return { call_handler: 'dialogflow', call_dialogflow_agent_id: callHandler.callDialogflowAgentId }; case 'relay_topic': return { call_handler: 'relay_topic', call_relay_topic: callHandler.callRelayTopic, call_relay_topic_status_callback_url: callHandler.callRelayTopicStatusCallbackUrl }; case 'relay_context': return { call_handler: 'relay_context', call_relay_context: callHandler.callRelayContext, call_relay_context_status_callback_url: callHandler.callRelayContextStatusCallbackUrl }; case 'relay_application': return { call_handler: 'relay_application', call_relay_application: callHandler.callRelayApplication }; case 'relay_connector': return { call_handler: 'relay_connector', call_relay_connector_id: callHandler.callRelayConnectorId }; case 'relay_sip_endpoint': return { call_handler: 'relay_sip_endpoint', call_sip_endpoint_id: callHandler.callSipEndpointId }; case 'relay_verto_endpoint': return { call_handler: 'relay_verto_endpoint', call_verto_resource: callHandler.callVertoResource }; case 'video_room': return { call_handler: 'video_room', call_video_room_id: callHandler.callVideoRoomId }; default: throw new Error('Unknown call handler type'); } } } function convertPhoneNumberMessageHandlerToJSON(messageHandler) { if (!messageHandler) { return {}; } else { switch (messageHandler === null || messageHandler === void 0 ? void 0 : messageHandler.type) { case 'laml_webhooks': return { message_handler: 'laml_webhooks', message_request_url: messageHandler.messageRequestUrl, message_request_method: messageHandler.messageRequestMethod, message_fallback_url: messageHandler.messageFallbackUrl, message_fallback_method: messageHandler.messageFallbackMethod, message_status_callback_url: messageHandler.messageStatusCallbackUrl, message_status_callback_method: messageHandler.messageStatusCallbackMethod }; case 'laml_application': return { message_handler: 'laml_application', message_laml_application_id: messageHandler.messageLamlApplicationId }; case 'relay_application': return { message_handler: 'relay_application', message_relay_application_id: messageHandler.messageRelayApplicationId }; case 'relay_topic': return { message_handler: 'relay_topic', message_relay_topic: messageHandler.messageRelayTopic }; case 'relay_context': return { message_handler: 'relay_context', message_relay_context: messageHandler.messageRelayContext }; default: throw new Error('Unknown message handler type'); } } } function convertUpdatePhoneNumberRequestToJSON(request) { return Object.assign(Object.assign({ name: request.name, call_receive_mode: request.callReceiveMode }, convertPhoneNumberCallHandlerToJSON(request.callHandler)), convertPhoneNumberMessageHandlerToJSON(request.messageHandler)); } function convertJSONToLookupNumberResponse(json) { const carrier = json.carrier ? { lrn: json.carrier.lrn, spid: json.carrier.spid, ocn: json.carrier.ocn, lata: json.carrier.lata, city: json.carrier.city, state: json.carrier.state, jurisdiction: json.carrier.jurisdiction, lec: json.carrier.lec, lineType: json.carrier.line_type, } : undefined; const cnam = json.cname ? { callerId: json.cnam.caller_id, } : undefined; return { countryCodeNumber: json.country_code_number, nationalNumber: json.national_number, possibleNumber: json.possible_number, validNumber: json.valid_number, nationalNumberFormatted: json.national_number_fornatted, internationalNumberFormatted: json.international_number_formatted, e164: json.e164, location: json.location, countryCode: json.country_code, timeZones: json.timezones, numberType: json.number_type, carrier, cnam }; } function convertJSONToSipEndpointCallHandler(json) { switch (json.call_handler) { case 'default': return { type: 'default' }; case 'passthrough': return { type: 'passthrough' }; case 'block-pstn': return { type: 'block-pstn' }; case 'ai_agent': return { type: 'ai_agent', callAiAgentId: json.call_ai_agent_id }; case 'relay_context': return { type: 'relay_context', callRelayContext: json.call_relay_context, callRelayContextStatusCallbackUrl: json.call_relay_context_status_callback_url }; case 'relay_script': return { type: 'relay_script', callRelayScriptUrl: json.call_relay_script_url }; case 'laml_webhooks': return { type: 'laml_webhooks', callRequestUrl: json.call_request_url, callRequestMethod: json.call_request_method, callFallbackUrl: json.call_fallback_url, callFallbackMethod: json.call_fallback_method, callStatusCallbackUrl: json.call_status_callback_url, callStatusCallbackMethod: json.call_status_callback_method, }; case 'laml_application': return { type: 'laml_application', callLamlApplicationId: json.call_laml_application_id }; case 'dialogflow': return { type: 'dialogflow', callDialogflowAgentId: json.call_dialogflow_agent_id }; case 'video_room': return { type: 'video_room', callVideoRoomId: json.call_video_room_id }; default: throw new Error('Unknown call handler type'); } } function convertJSONToSipEndpoint(json) { return { id: json.id, username: json.username, callerId: json.caller_id, sendAs: json.send_as, ciphers: json.ciphers, codecs: json.codecs, encryption: json.encryption, callHandler: convertJSONToSipEndpointCallHandler(json), }; } function convertSipEndpointCallHandlerToJSON(callHandler) { if (!callHandler) { return {}; } else { switch (callHandler.type) { case 'default': return { call_handler: 'default' }; case 'passthrough': return { call_handler: 'passthrough' }; case 'block-pstn': return { call_handler: 'block-pstn' }; case 'ai_agent': return { call_handler: 'ai_agent', call_ai_agent_id: callHandler.callAiAge