UNPKG

@sirhc77/signalwire-rest-sdk

Version:

An SDK for the SignalWire REST API

1,411 lines (1,283 loc) 100 kB
import { SWML, SWMLAIHint, SWMLAILanguage, SWMLAIMethod, SWMLAIParameters, SWMLAIParams, SWMLAIPrompt, SWMLAIPronounce, SWMLAnswerMethod, SWMLAnswerParameters, SWMLCondElseParameters, SWMLCondMethod, SWMLCondParameters, SWMLCondWhenThenParameters, SWMLConnectDestination, SWMLConnectDialingParameter, SWMLConnectHeader, SWMLConnectMethod, SWMLConnectParallelDialingParameter, SWMLConnectParameters, SWMLConnectSerialDialingParameter, SWMLConnectSerialParallelDialingParameter, SWMLConnectToDialingParameter, SWMLDenoiseMethod, SWMLDetectMachineMethod, SWMLDetectMachineParameters, SWMLExecuteMethod, SWMLExecuteParameters, SWMLGotoMethod, SWMLGotoParameters, SWMLHangupMethod, SWMLHangupParameters, SWMLJoinRoomMethod, SWMLJoinRoomParameters, SWMLLabelMethod, SWMLLiveTranscribeAction, SWMLLiveTranscribeMethod, SWMLLiveTranscribeParameters, SWMLLiveTranscribeStartAction, SWMLLiveTranscribeStopAction, SWMLLiveTranscribeSummarizeAction, SWMLLiveTranslateAction, SWMLLiveTranslateInjectAction, SWMLLiveTranslateMethod, SWMLLiveTranslateParameters, SWMLLiveTranslateStartAction, SWMLLiveTranslateStopAction, SWMLLiveTranslateSummarizeAction, SWMLMethod, SWMLPayMethod, SWMLPayParameter, SWMLPayParameters, SWMLPayPrompt, SWMLPayPromptAction, SWMLPlayableSound, SWMLPlayMethod, SWMLPlayParameters, SWMLPlayUrl, SWMLPlayUrls, SWMLPromptMethod, SWMLPromptParameters, SWMLReceiveFaxMethod, SWMLReceiveFaxParameters, SWMLRecordCallMethod, SWMLRecordCallParameters, SWMLRecordMethod, SWMLRecordParameters, SWMLRequestMethod, SWMLRequestParameters, SWMLReturnMethod, SWMLSendDigitsMethod, SWMLSendDigitsParameters, SWMLSendFaxMethod, SWMLSendFaxParameters, SWMLSendMMSMessageParameters, SWMLSendSMSMessageParameters, SWMLSendSMSMethod, SWMLSendSMSParameters, SWMLSetMethod, SWMLSIPReferMethod, SWMLSIPReferParameters, SWMLSleepMethod, SWMLSleepParameters, SWMLStopDenoiseMethod, SWMLStopRecordCallMethod, SWMLStopRecordCallParameters, SWMLStopTapMethod, SWMLStopTapParameters, SWMLSWAIG, SWMLSWAIGDataMap, SWMLSWAIGDataMapExpression, SWMLSWAIGDataMapOutput, SWMLSWAIGDataMapOutputAction, SWMLSWAIGDataMapOutputContextSwitchAction, SWMLSWAIGDataMapOutputPlaybackBGAction, SWMLSWAIGDataMapOutputSayAction, SWMLSWAIGDataMapOutputSetGlobalDataAction, SWMLSWAIGDataMapOutputSetMetaDataAction, SWMLSWAIGDataMapOutputStopAction, SWMLSWAIGDataMapOutputStopPlaybackBGAction, SWMLSWAIGDataMapOutputSWMLAction, SWMLSWAIGDataMapOutputToggleFunction, SWMLSWAIGDataMapOutputToggleFunctionsAction, SWMLSWAIGDataMapOutputUnsetGlobalDataAction, SWMLSWAIGDataMapOutputUnsetMetaDataAction, SWMLSWAIGDataMapOutputUserInputAction, SWMLSWAIGDataMapWebhook, SWMLSWAIGDataMapWebhookForeach, SWMLSWAIGDefaults, SWMLSWAIGFunction, SWMLSWAIGFunctionFillers, SWMLSWAIGFunctionParameterAllOfProperty, SWMLSWAIGFunctionParameterAnyOfProperty, SWMLSWAIGFunctionParameterArrayProperty, SWMLSWAIGFunctionParameterBooleanProperty, SWMLSWAIGFunctionParameterConstProperty, SWMLSWAIGFunctionParameterIntegerProperty, SWMLSWAIGFunctionParameterNumberProperty, SWMLSWAIGFunctionParameterObjectProperty, SWMLSWAIGFunctionParameterOneOfProperty, SWMLSWAIGFunctionParameterProperties, SWMLSWAIGFunctionParameterProperty, SWMLSWAIGFunctionParameters, SWMLSWAIGFunctionParameterStringProperty, SWMLSWAIGInclude, SWMLSWAIGInternalFiller, SWMLSWAIGVisualInputFiller, SWMLSwitchCaseParameters, SWMLSwitchMethod, SWMLSwitchParameters, SWMLTapMethod, SWMLTapParameters, SWMLTransferMethod, SWMLTransferParameters, SWMLUnsetMethod, SWMLUnsetParameters, SWMLUserEventMethod, SWMLUserEventParameters } from "./SWMLTypes"; export function convertSWMLAIHintToJSON(hint: SWMLAIHint): any { return { hint: hint.hint, pattern: hint.pattern, replace: hint.replace, ignore_case: hint.ignoreCase } } export function convertJSONToSWMLAIHint(json: any): SWMLAIHint { return { hint: json.hint, pattern: json.pattern, replace: json.replace, ignoreCase: json.ignore_case } } export function convertSWMLAILanguageToJSON(language: SWMLAILanguage): any { return { name: language.name, code: language.code, voice: language.voice, emotion: language.emotion, function_fillers: language.functionFillers, model: language.model, speech_fillers: language.speechFillers, speed: language.speed } } export function convertJSONToSWMLAILanguage(json: any): SWMLAILanguage { return { name: json.name, code: json.code, voice: json.voice, emotion: json.emotion, functionFillers: json.function_fillers, model: json.model, speechFillers: json.speech_fillers, speed: json.speed } } export function convertSWMLAIParamsToJSON(params?: SWMLAIParams): any { if (params === undefined) { return undefined; } return { ai_model: params.aiModel, conscience: params.conscience, thinking_model: params.thinkingModel, vision_model: params.visionModel, enable_thinking: params.enableThinking, enable_vision: params.enableVision, wait_for_user: params.waitForUser, direction: params.direction, conversation_id: params.conversationId, local_tz: params.localTZ, save_conversation: params.saveConversation, transfer_summary: params.transferSummary, languages_enabled: params.languagesEnabled, conversation_sliding_window: params.conversationSlidingWindow, summary_mode: params.summaryMode, asr_diarize: params.asrDiarize, asr_speaker_affinity: params.asrSpeakerAffinity, asr_smart_format: params.asrSmartFormat, openai_asr_engine: params.openAiAsrEngine, energy_level: params.energyLevel, llm_diarize_aware: params.llmDiarizeAware, end_of_speech_timeout: params.endOfSpeechTimeout, first_word_timeout: params.firstWordTimeout, ai_volume: params.aiVolume, tts_number_format: params.ttsNumberFormat, eleven_labs_similarity: params.elevenLabsSimilarity, video_talking_file: params.videoTalkingFile, video_idle_file: params.videoIdleFile, video_listening_file: params.videoListeningFile, max_emotion: params.maxEmotion, speech_gen_quick_stops: params.speechGenQuickStops, acknowledge_interruptions: params.acknowledgeInterruptions, enable_barge: params.enableBarge, transparent_barge: params.transparentBarge, barge_match_string: params.bargeMatchString, barge_min_words: params.bargeMinWords, interrupt_on_noise: params.interruptOnNoise, interrupt_prompt: params.interruptPrompt, barge_functions: params.bargeFunctions, transparent_barge_max_time: params.transparentBargeMaxTime, attention_timeout: params.attentionTimeout, attention_timeout_prompt: params.attentionTimeoutPrompt, inactivity_timeout: params.inactivityTimeout, outbound_attention_timeout: params.outboundAttentionTimeout, initial_sleep_ms: params.initialSleepMS, speech_event_timeout: params.speechEventTimeout, digit_timeout: params.digitTimeout, hard_stop_time: params.hardStopTime, hard_stop_prompt: params.hardStopPrompt, speech_timeout: params.speechTimeout, background_file: params.backgroundFile, background_file_loops: params.backgroundFileLoops, background_file_volume: params.backgroundFileVolume, hold_music: params.holdMusic, hold_on_process: params.holdOnProcess, static_greeting: params.staticGreeting, static_greeting_no_barge: params.staticGreetingNoBarge, swaig_allow_swml: params.swaigAllowSWML, swaig_allow_settings: params.swaigAllowSettings, swaig_post_conversation: params.swaigPostConversation, function_wait_for_talking: params.functionWaitForTalking, swaig_set_global_data: params.swaigSetGlobalData, functions_on_no_response: params.functionsOnNoResponse, digit_terminators: params.digitTerminators?.join(''), input_poll_freq: params.inputPollFreq, debug_webhook_url: params.debugWebhookUrl, debug_webhook_level: params.debugWebhookLevel, audible_debug: params.audibleDebug, verbose_logs: params.verboseLogs, cache_mode: params.cacheMode, enable_accounting: params.enableAccounting, audible_latency: params.audibleLatency, } } export function convertJSONToSWMLAIParams(json: any): SWMLAIParams { return { aiModel: json.ai_model, conscience: json.conscience, thinkingModel: json.thinking_model, visionModel: json.vision_model, enableThinking: json.enable_thinking, enableVision: json.enable_vision, waitForUser: json.wait_for_user, direction: json.direction, conversationId: json.conversation_id, localTZ: json.local_tz, saveConversation: json.save_conversation, transferSummary: json.transfer_summary, languagesEnabled: json.languages_enabled, conversationSlidingWindow: json.conversation_sliding_window, summaryMode: json.summary_mode, asrDiarize: json.asr_diarize, asrSpeakerAffinity: json.asr_speaker_affinity, asrSmartFormat: json.asr_smart_format, openAiAsrEngine: json.openai_asr_engine, energyLevel: json.energy_level, llmDiarizeAware: json.llm_diarize_aware, endOfSpeechTimeout: json.end_of_speech_timeout, firstWordTimeout: json.first_word_timeout, aiVolume: json.ai_volume, ttsNumberFormat: json.tts_number_format, elevenLabsStability: json.eleven_labs_stability, elevenLabsSimilarity: json.eleven_labs_similarity, videoTalkingFile: json.video_talking_file, videoIdleFile: json.video_idle_file, videoListeningFile: json.video_listening_file, maxEmotion: json.max_emotion, speechGenQuickStops: json.speech_gen_quick_stops, acknowledgeInterruptions: json.acknowledge_interruptions, enableBarge: json.enable_barge, transparentBarge: json.transparent_barge, bargeMatchString: json.barge_match_string, bargeMinWords: json.barge_min_words, interruptOnNoise: json.interrupt_on_noise, interruptPrompt: json.interrupt_prompt, bargeFunctions: json.barge_functions, transparentBargeMaxTime: json.transparent_barge_max_time, attentionTimeout: json.attention_timeout, attentionTimeoutPrompt: json.attention_timeout_prompt, inactivityTimeout: json.inactivity_timeout, outboundAttentionTimeout: json.outbound_attention_timeout, initialSleepMS: json.initial_sleep_ms, speechEventTimeout: json.speech_event_timeout, digitTimeout: json.digit_timeout, hardStopTime: json.hard_stop_time, hardStopPrompt: json.hard_stop_prompt, speechTimeout: json.speech_timeout, backgroundFile: json.background_file, backgroundFileLoops: json.background_file_loops, backgroundFileVolume: json.background_file_volume, holdMusic: json.hold_music, holdOnProcess: json.hold_on_process, staticGreeting: json.static_greeting, staticGreetingNoBarge: json.static_greeting_no_barge, swaigAllowSWML: json.swaig_allow_swml, swaigAllowSettings: json.swaig_allow_settings, swaigPostConversation: json.swaig_post_conversation, functionWaitForTalking: json.function_wait_for_talking, swaigSetGlobalData: json.swaig_set_global_data, functionsOnNoResponse: json.functions_on_no_response, digitTerminators: json.digit_terminators?.split(''), inputPollFreq: json.input_poll_freq, debugWebhookUrl: json.debug_webhook_url, debugWebhookLevel: json.debug_webhook_level, audibleDebug: json.audible_debug, verboseLogs: json.verbose_logs, cacheMode: json.cache_mode, enableAccounting: json.enable_accounting, audibleLatency: json.audible_latency, } } export function convertSWMLAIPromptToJSON(prompt?: SWMLAIPrompt): any { if (prompt === undefined) { return undefined; } return { text: prompt.text, temperature: prompt.temperature, top_p: prompt.topP, confidence: prompt.confidence, presence_penalty: prompt.presencePenalty, frequency_penalty: prompt.frequencyPenalty } } export function convertJSONToSWMLAIPrompt(json?: any): SWMLAIPrompt | undefined { if (json === undefined) { return undefined; } return { text: json.text, temperature: json.temperature, topP: json.top_p, confidence: json.confidence, presencePenalty: json.presence_penalty, frequencyPenalty: json.frequency_penalty } } export function convertSWMLAIPronounceToJSON(pronounce: SWMLAIPronounce): any { return { replace: pronounce.replace, with: pronounce.with, ignore_case: pronounce.ignoreCase } } export function convertJSONToSWMLAIPronounce(json: any): SWMLAIPronounce { return { replace: json.replace, with: json.with, ignoreCase: json.ignore_case } } export function convertSWMLSWAIGDefaultsToJSON(defaults?: SWMLSWAIGDefaults): any { if (defaults === undefined) { return undefined; } return { webHookUrl: defaults.webHookUrl } } export function convertJSONToSWMLSWAIGDefaults(json?: any): SWMLSWAIGDefaults | undefined { if (json === undefined) { return undefined; } return { webHookUrl: json.web_hook_url } } export function convertSWMLSWAIGDataMapOutputSWMLActionToJSON(action: SWMLSWAIGDataMapOutputSWMLAction): any { return { SWML: convertSWMLToJSON(action.SWML), } } export function convertJSONToSWMLSWAIGDataMapOutputSWMLAction(json: any): SWMLSWAIGDataMapOutputSWMLAction { return { type: 'swml', SWML: convertJSONToSWML(json.SWML) } } export function convertSWMLSWAIGDataMapOutputSayActionToJSON(action: SWMLSWAIGDataMapOutputSayAction): any { return { say: action.say, } } export function convertJSONToSWMLSWAIGDataMapOutputSayAction(json: any): SWMLSWAIGDataMapOutputSayAction { return { type: 'say', say: json.say } } export function convertSWMLSWAIGDataMapOutputStopActionToJSON(action: SWMLSWAIGDataMapOutputStopAction): any { return { stop: action.stop, } } export function convertJSONToSWMLSWAIGDataMapOutputStopAction(json: any): SWMLSWAIGDataMapOutputStopAction { return { type: 'stop', stop: json.stop } } export function convertSWMLSWAIGDataMapOutputToggleFunctionToJSON(toggleFunction: SWMLSWAIGDataMapOutputToggleFunction): any { return { active: toggleFunction.active, function: toggleFunction.function, } } export function convertJSONToSWMLSWAIGDataMapOutputToggleFunction(json: any): SWMLSWAIGDataMapOutputToggleFunction { return { active: json.active, function: json.function, } } export function convertSWMLSWAIGDataMapOutputToggleFunctionsActionToJSON(toggleFunctionsAction: SWMLSWAIGDataMapOutputToggleFunctionsAction): any { return { toggle_functions: toggleFunctionsAction.toggleFunctions.map(convertSWMLSWAIGDataMapOutputToggleFunctionToJSON), } } export function convertJSONToSWMLSWAIGDataMapOutputToggleFunctionsAction(json: any): SWMLSWAIGDataMapOutputToggleFunctionsAction { return { type: 'toggleFunctions', toggleFunctions: json.toggle_functions.map(convertJSONToSWMLSWAIGDataMapOutputToggleFunction) } } export function convertSWMLSWAIGDataMapOutputSetGlobalDataActionToJSON(action: SWMLSWAIGDataMapOutputSetGlobalDataAction): any { return { set_global_data: action.setGlobalData, } } export function convertJSONToSWMLSWAIGDataMapOutputSetGlobalDataAction(json: any): SWMLSWAIGDataMapOutputSetGlobalDataAction { return { type: 'setGlobalData', setGlobalData: json.set_global_data } } export function convertSWMLSWAIGDataMapOutputSetMetaDataActionToJSON(action: SWMLSWAIGDataMapOutputSetMetaDataAction): any { return { set_meta_data: action.setMetaData, } } export function convertJSONToSWMLSWAIGDataMapOutputSetMetaDataAction(json: any): SWMLSWAIGDataMapOutputSetMetaDataAction { return { type: 'setMetaData', setMetaData: json.set_meta_data } } export function convertSWMLSWAIGDataMapOutputUnsetGlobalDataActionToJSON(action: SWMLSWAIGDataMapOutputUnsetGlobalDataAction): any { return { unset_global_data: action.unsetGlobalData } } export function convertJSONToSWMLSWAIGDataMapOutputUnsetGlobalDataAction(json: any): SWMLSWAIGDataMapOutputUnsetGlobalDataAction { return { type: 'unsetGlobalData', unsetGlobalData: json.unset_global_data } } export function convertSWMLSWAIGDataMapOutputUnsetMetaDataActionToJSON(action: SWMLSWAIGDataMapOutputUnsetMetaDataAction): any { return { unset_meta_data: action.unsetMetaData } } export function convertJSONToSWMLSWAIGDataMapOutputUnsetMetaDataAction(json: any): SWMLSWAIGDataMapOutputUnsetMetaDataAction { return { type: 'unsetMetaData', unsetMetaData: json.unset_meta_data } } export function convertSWMLSWAIGDataMapOutputPlaybackBGActionToJSON(action: SWMLSWAIGDataMapOutputPlaybackBGAction): any { return { playback_bg: { file: action.playbackBG.file, wait: action.playbackBG.wait } } } export function convertJSONToSWMLSWAIGDataMapOutputPlaybackBGAction(json: any): SWMLSWAIGDataMapOutputPlaybackBGAction { return { type: 'playbackBG', playbackBG: { file: json.playback_bg.file, wait: json.playback_bg.wait } } } export function convertSWMLSWAIGDataMapOutputStopPlaybackBGActionToJSON(action: SWMLSWAIGDataMapOutputStopPlaybackBGAction): any { return { stop_playback_bg: action.stopPlaybackBG } } export function convertJSONToSWMLSWAIGDataMapOutputStopPlaybackBGAction(json: any): SWMLSWAIGDataMapOutputStopPlaybackBGAction { return { type: 'stopPlaybackBG', stopPlaybackBG: json.stop_playback_bg } } export function convertSWMLSWAIGDataMapOutputUserInputActionToJSON(action: SWMLSWAIGDataMapOutputUserInputAction): any { return { user_input: action.userInput } } export function convertJSONToSWMLSWAIGDataMapOutputUserInputAction(json: any): SWMLSWAIGDataMapOutputUserInputAction { return { type: 'userInput', userInput: json.user_input } } export function convertSWMLSWAIGDataMapOutputContextSwitchActionToJSON(action: SWMLSWAIGDataMapOutputContextSwitchAction): any { return { context_switch: { system_prompt: action.contextSwitch.systemPrompt, consolidate: action.contextSwitch.consolidate, user_prompt: action.contextSwitch.userPrompt } } } export function convertJSONToSWMLSWAIGDataMapOutputContextSwitchAction(json: any): SWMLSWAIGDataMapOutputContextSwitchAction { return { type: 'contextSwitch', contextSwitch: { systemPrompt: json.context_switch.system_prompt, consolidate: json.context_switch.consolidate, userPrompt: json.context_switch.user_prompt } } } export function convertSWMLSWAIGDataMapOutputActionToJSON(action: SWMLSWAIGDataMapOutputAction): any { switch (action.type) { case 'swml': return convertSWMLSWAIGDataMapOutputSWMLActionToJSON(action); case 'say': return convertSWMLSWAIGDataMapOutputSayActionToJSON(action); case 'stop': return convertSWMLSWAIGDataMapOutputStopActionToJSON(action); case 'toggleFunctions': return convertSWMLSWAIGDataMapOutputToggleFunctionsActionToJSON(action); case 'setGlobalData': return convertSWMLSWAIGDataMapOutputSetGlobalDataActionToJSON(action); case 'setMetaData': return convertSWMLSWAIGDataMapOutputSetMetaDataActionToJSON(action); case 'unsetGlobalData': return convertSWMLSWAIGDataMapOutputUnsetGlobalDataActionToJSON(action); case 'unsetMetaData': return convertSWMLSWAIGDataMapOutputUnsetMetaDataActionToJSON(action); case 'playbackBG': return convertSWMLSWAIGDataMapOutputPlaybackBGActionToJSON(action); case 'stopPlaybackBG': return convertSWMLSWAIGDataMapOutputStopPlaybackBGActionToJSON(action); case 'userInput': return convertSWMLSWAIGDataMapOutputUserInputActionToJSON(action); case 'contextSwitch': return convertSWMLSWAIGDataMapOutputContextSwitchActionToJSON(action); default: throw Error("Unknown DataMap Output Action Type"); } } export function convertJSONToSWMLSWAIGDataMapOutputAction(json: any): SWMLSWAIGDataMapOutputAction { const objectKeys = Object.keys(json); if (objectKeys.includes('SWML')) { return convertJSONToSWMLSWAIGDataMapOutputSWMLAction(json); } else if (objectKeys.includes('say')) { return convertJSONToSWMLSWAIGDataMapOutputSayAction(json); } else if (objectKeys.includes('stop')) { return convertJSONToSWMLSWAIGDataMapOutputStopAction(json); } else if (objectKeys.includes('toggle_functions')) { return convertJSONToSWMLSWAIGDataMapOutputToggleFunctionsAction(json); } else if (objectKeys.includes('set_global_data')) { return convertJSONToSWMLSWAIGDataMapOutputSetGlobalDataAction(json); } else if (objectKeys.includes('set_meta_data')) { return convertJSONToSWMLSWAIGDataMapOutputSetMetaDataAction(json); } else if (objectKeys.includes('unset_global_data')) { return convertJSONToSWMLSWAIGDataMapOutputUnsetGlobalDataAction(json); } else if (objectKeys.includes('unset_meta_data')) { return convertJSONToSWMLSWAIGDataMapOutputUnsetMetaDataAction(json); } else if (objectKeys.includes('playback_bg')) { return convertJSONToSWMLSWAIGDataMapOutputPlaybackBGAction(json); } else if (objectKeys.includes('stop_playback_bg')) { return convertJSONToSWMLSWAIGDataMapOutputStopPlaybackBGAction(json); } else if (objectKeys.includes('user_input')) { return convertJSONToSWMLSWAIGDataMapOutputUserInputAction(json); } else if (objectKeys.includes('context_switch')) { return convertJSONToSWMLSWAIGDataMapOutputContextSwitchAction(json); } else { throw Error("Unknown DataMap Output Action Type"); } } export function convertSWMLSWAIGDataMapOutputToJSON(output: SWMLSWAIGDataMapOutput): any { if (output === undefined) { return undefined; } return { response: output.response, action: output.action.map(convertSWMLSWAIGDataMapOutputActionToJSON) } } export function convertJSONToSWMLSWAIGDataMapOutput(json: any): SWMLSWAIGDataMapOutput { return { response: json.response, action: json.action.map(convertJSONToSWMLSWAIGDataMapOutputAction) } } export function convertSWMLSWAIGDataMapExpressionToJSON(expression: SWMLSWAIGDataMapExpression): any { return { string: expression.string, pattern: expression.pattern, output: convertSWMLSWAIGDataMapOutputToJSON(expression.output) } } export function convertJSONToSWMLSWAIGDataMapExpression(json: any): SWMLSWAIGDataMapExpression { return { string: json.string, pattern: json.pattern, output: convertJSONToSWMLSWAIGDataMapOutput(json.output) } } export function convertSWMLSWAIGDataMapWebhookForeachToJSON(foreach?: SWMLSWAIGDataMapWebhookForeach): any { if (foreach === undefined) { return undefined; } return { append: foreach.append, input_key: foreach.inputKey, max: foreach.max, output_key: foreach.outputKey } } export function convertJSONToSWMLSWAIGDataMapWebhookForeach(json?: any): SWMLSWAIGDataMapWebhookForeach | undefined { if (json === undefined) { return undefined; } return { append: json.append, inputKey: json.input_key, max: json.max, outputKey: json.output_key } } export function convertSWMLSWAIGDataMapWebhookToJSON(webhook: SWMLSWAIGDataMapWebhook): any { return { expressions: webhook.expressions?.map(convertSWMLSWAIGDataMapExpressionToJSON), error_keys: webhook.errorKeys, url: webhook.url, foreach: convertSWMLSWAIGDataMapWebhookForeachToJSON(webhook.foreach), headers: webhook.headers, method: webhook.method, input_args_as_params: webhook.inputArgsAsParams, params: webhook.params, required_args: webhook.requiredArgs, output: convertSWMLSWAIGDataMapOutputToJSON(webhook.output) } } export function convertJSONToSWMLSWAIGDataMapWebhook(json: any): SWMLSWAIGDataMapWebhook { return { expressions: json.expressions?.map(convertJSONToSWMLSWAIGDataMapExpression), errorKeys: json.error_keys, url: json.url, foreach: convertJSONToSWMLSWAIGDataMapWebhookForeach(json.foreach), headers: json.headers, method: json.method, inputArgsAsParams: json.input_args_as_params, params: json.params, requiredArgs: json.required_args, output: convertJSONToSWMLSWAIGDataMapOutput(json.output) } } export function convertSWMLSWAIGDataMapToJSON(dataMap?: SWMLSWAIGDataMap): any { if (dataMap === undefined) { return undefined; } return { expressions: dataMap.expressions.map(convertSWMLSWAIGDataMapExpressionToJSON), webhooks: dataMap.webhooks.map(convertSWMLSWAIGDataMapWebhookToJSON), output: convertSWMLSWAIGDataMapOutputToJSON(dataMap.output) } } export function convertJSONToSWMLSWAIGDataMap(json?: any): SWMLSWAIGDataMap | undefined { if (json === undefined) { return undefined; } return { expressions: json.expressions.map(convertJSONToSWMLSWAIGDataMapExpression), webhooks: json.webhooks.map(convertJSONToSWMLSWAIGDataMapWebhook), output: convertJSONToSWMLSWAIGDataMapOutput(json.output) } } export function convertSWMLSWAIGFunctionParameterStringPropertyToJSON(property: SWMLSWAIGFunctionParameterStringProperty): any { return { type: 'string', description: property.description, enum: property.enum, default: property.default, pattern: property.pattern, nullable: property.nullable, } } export function convertJSONToSWMLSWAIGFunctionParameterStringProperty(json: any): SWMLSWAIGFunctionParameterStringProperty { return { type: 'string', description: json.description, enum: json.enum, default: json.default, pattern: json.pattern, nullable: json.nullable, } } export function convertSWMLSWAIGFunctionParameterIntegerPropertyToJSON(property: SWMLSWAIGFunctionParameterIntegerProperty): any { return { type: 'integer', description: property.description, enum: property.enum, default: property.default, nullable: property.nullable, } } export function convertJSONToSWMLSWAIGFunctionParameterIntegerProperty(json: any): SWMLSWAIGFunctionParameterIntegerProperty { return { type: 'integer', description: json.description, enum: json.enum, default: json.default, nullable: json.nullable, } } export function convertSWMLSWAIGFunctionParameterNumberPropertyToJSON(property: SWMLSWAIGFunctionParameterNumberProperty): any { return { type: 'number', description: property.description, enum: property.enum, default: property.default, nullable: property.nullable, } } export function convertJSONToSWMLSWAIGFunctionParameterNumberProperty(json: any): SWMLSWAIGFunctionParameterNumberProperty { return { type: 'number', description: json.description, enum: json.enum, default: json.default, nullable: json.nullable, } } export function convertSWMLSWAIGFunctionParameterBooleanPropertyToJSON(property: SWMLSWAIGFunctionParameterBooleanProperty): any { return { type: 'boolean', description: property.description, default: property.default, nullable: property.nullable, } } export function convertJSONToSWMLSWAIGFunctionParameterBooleanProperty(json: any): SWMLSWAIGFunctionParameterBooleanProperty { return { type: 'boolean', description: json.description, default: json.default, nullable: json.nullable, } } export function convertSWMLSWAIGFunctionParameterArrayPropertyToJSON(property: SWMLSWAIGFunctionParameterArrayProperty): any { return { type: 'array', description: property.description, items: property.items.map(convertSWMLSWAIGFunctionParameterPropertyToJSON), default: property.default, nullable: property.nullable, } } export function convertJSONToSWMLSWAIGFunctionParameterArrayProperty(json: any): SWMLSWAIGFunctionParameterArrayProperty { return { type: 'array', description: json.description, items: json.items.map(convertJSONToSWMLSWAIGFunctionParameterProperty), default: json.default, nullable: json.nullable, } } export function convertSWMLSWAIGFunctionParameterPropertiesToJSON(properties: SWMLSWAIGFunctionParameterProperties): any { const propertiesEntries = Object.entries(properties).map(([key, value]) => { const tuple: [string, any] = [key, convertSWMLSWAIGFunctionParameterPropertyToJSON(value)]; return tuple; }); return Object.fromEntries(propertiesEntries); } export function convertJSONToSWMLSWAIGFunctionParameterProperties(json: any): SWMLSWAIGFunctionParameterProperties { const propertiesEntries = Object.entries(json).map(([key, value]) => { const tuple: [string, SWMLSWAIGFunctionParameterProperty] = [key, convertJSONToSWMLSWAIGFunctionParameterProperty(value)]; return tuple; }); return Object.fromEntries(propertiesEntries); } export function convertSWMLSWAIGFunctionParameterObjectPropertyToJSON(property: SWMLSWAIGFunctionParameterObjectProperty): any { return { type: 'object', description: property.description, properties: convertSWMLSWAIGFunctionParameterPropertiesToJSON(property.properties), required: property.required, default: property.default, nullable: property.nullable, } } export function convertJSONToSWMLSWAIGFunctionParameterObjectProperty(json: any): SWMLSWAIGFunctionParameterObjectProperty { return { type: 'object', description: json.description, properties: convertJSONToSWMLSWAIGFunctionParameterProperties(json.properties), required: json.required, default: json.default, nullable: json.nullable, } } export function convertSWMLSWAIGFunctionParameterOneOfPropertyToJSON(property: SWMLSWAIGFunctionParameterOneOfProperty): any { return { oneOf: property.oneOf.map(convertSWMLSWAIGFunctionParameterPropertyToJSON) } } export function convertJSONToSWMLSWAIGFunctionParameterOneOfProperty(json: any): SWMLSWAIGFunctionParameterOneOfProperty { return { type: 'oneOf', oneOf: json.oneOf.map(convertJSONToSWMLSWAIGFunctionParameterProperty) } } export function convertSWMLSWAIGFunctionParameterAllOfPropertyToJSON(property: SWMLSWAIGFunctionParameterAllOfProperty): any { return { allOf: property.allOf.map(convertSWMLSWAIGFunctionParameterPropertyToJSON) } } export function convertJSONToSWMLSWAIGFunctionParameterAllOfProperty(json: any): SWMLSWAIGFunctionParameterAllOfProperty { return { type: 'allOf', allOf: json.allOf.map(convertJSONToSWMLSWAIGFunctionParameterProperty) } } export function convertSWMLSWAIGFunctionParameterAnyOfPropertyToJSON(property: SWMLSWAIGFunctionParameterAnyOfProperty): any { return { anyOf: property.anyOf.map(convertSWMLSWAIGFunctionParameterPropertyToJSON) } } export function convertJSONToSWMLSWAIGFunctionParameterAnyOfProperty(json: any): SWMLSWAIGFunctionParameterAnyOfProperty { return { type: 'anyOf', anyOf: json.anyOf.map(convertJSONToSWMLSWAIGFunctionParameterProperty) } } export function convertSWMLSWAIGFunctionParameterConstPropertyToJSON(property: SWMLSWAIGFunctionParameterConstProperty): any { return { const: property.const } } export function convertJSONToSWMLSWAIGFunctionParameterConstProperty(json: any): SWMLSWAIGFunctionParameterConstProperty { return { type: 'const', const: json.const } } export function convertSWMLSWAIGFunctionParameterPropertyToJSON(property: SWMLSWAIGFunctionParameterProperty): any { switch (property.type) { case 'string': return convertSWMLSWAIGFunctionParameterStringPropertyToJSON(property); case 'integer': return convertSWMLSWAIGFunctionParameterIntegerPropertyToJSON(property); case 'number': return convertSWMLSWAIGFunctionParameterNumberPropertyToJSON(property); case 'boolean': return convertSWMLSWAIGFunctionParameterBooleanPropertyToJSON(property); case 'array': return convertSWMLSWAIGFunctionParameterArrayPropertyToJSON(property); case 'object': return convertSWMLSWAIGFunctionParameterObjectPropertyToJSON(property); case 'oneOf': return convertSWMLSWAIGFunctionParameterOneOfPropertyToJSON(property); case 'allOf': return convertSWMLSWAIGFunctionParameterAllOfPropertyToJSON(property); case 'anyOf': return convertSWMLSWAIGFunctionParameterAnyOfPropertyToJSON(property); case 'const': return convertSWMLSWAIGFunctionParameterConstPropertyToJSON(property); default: throw Error("Unknown Function Parameter Type"); } } export function convertJSONToSWMLSWAIGFunctionParameterProperty(json: any): SWMLSWAIGFunctionParameterProperty { switch (json.type) { case 'string': return convertJSONToSWMLSWAIGFunctionParameterStringProperty(json); case 'integer': return convertJSONToSWMLSWAIGFunctionParameterIntegerProperty(json); case 'number': return convertJSONToSWMLSWAIGFunctionParameterNumberProperty(json); case 'boolean': return convertJSONToSWMLSWAIGFunctionParameterBooleanProperty(json); case 'array': return convertJSONToSWMLSWAIGFunctionParameterArrayProperty(json); case 'object': return convertJSONToSWMLSWAIGFunctionParameterObjectProperty(json); default: const objectKeys = Object.keys(json); if (objectKeys.includes('oneOf')) { return convertJSONToSWMLSWAIGFunctionParameterOneOfProperty(json); } else if (objectKeys.includes('allOf')) { return convertJSONToSWMLSWAIGFunctionParameterAllOfProperty(json); } else if (objectKeys.includes('anyOf')) { return convertJSONToSWMLSWAIGFunctionParameterAnyOfProperty(json); } else if (objectKeys.includes('const')) { return convertJSONToSWMLSWAIGFunctionParameterConstProperty(json); } else { throw Error("Unknown Function Parameter Type"); } } } export function convertSWMLSWAIGFunctionParametersToJSON(parameters?: SWMLSWAIGFunctionParameters): any { if (parameters === undefined) { return undefined; } return { type: parameters.type, properties: convertSWMLSWAIGFunctionParameterPropertiesToJSON(parameters.properties), required: parameters.required } } export function convertJSONToSWMLSWAIGFunctionParameters(json?: any): SWMLSWAIGFunctionParameters | undefined { if (json === undefined) { return undefined; } return { type: json.type, properties: convertJSONToSWMLSWAIGFunctionParameterProperties(json.properties), required: json.required } } export function convertSWMLSWAIGFunctionFillersToJSON(fillers?: SWMLSWAIGFunctionFillers): any { if (fillers === undefined) { return undefined; } const fillersEntries = Object.entries(fillers).map(([languageCode, value]) => { const tuple: [string, any] = [languageCode, value]; return tuple; }); return Object.fromEntries(fillersEntries); } export function convertJSONToSWMLSWAIGFunctionFillers(json: any): SWMLSWAIGFunctionFillers { const entries = Object.entries(json).map(([languageCode, value]) => { const tuple: [string, string[]] = [languageCode, value as string[]]; return tuple; }); return Object.fromEntries(entries); } export function convertSWMLSWAIGFunctionToJSON(func: SWMLSWAIGFunction): any { return { description: func.description, function: func.function, active: func.active, data_map: convertSWMLSWAIGDataMapToJSON(func.dataMap), parameters: convertSWMLSWAIGFunctionParametersToJSON(func.parameters), fillers: convertSWMLSWAIGFunctionFillersToJSON(func.fillers), meta_data: func.metaData, meta_data_token: func.metaDataToken, wait_file: func.waitFile, wait_file_loops: func.waitFileLoops, wait_for_fillers: func.waitForFillers, web_hook_url: func.webHookUrl, } } export function convertJSONToSWMLSWAIGFunction(json: any): SWMLSWAIGFunction { return { description: json.description, function: json.function, active: json.active, dataMap: convertJSONToSWMLSWAIGDataMap(json.data_map), parameters: convertJSONToSWMLSWAIGFunctionParameters(json.parameters), fillers: convertJSONToSWMLSWAIGFunctionFillers(json.fillers), metaData: json.meta_data, metaDataToken: json.meta_data_token, waitFile: json.wait_file, waitFileLoops: json.wait_file_loops, waitForFillers: json.wait_for_fillers, webHookUrl: json.web_hook_url, } } export function convertSWMLSWAIGIncludeToJSON(include: SWMLSWAIGInclude): any { return { url: include.url, function: include.function, meta_data: include.metaData, } } export function convertJSONToSWMLSWAIGInclude(json: any): SWMLSWAIGInclude { return { url: json.url, function: json.function, metaData: json.meta_data, } } export function convertSWMLSWAIGVisualInputFillerToJSON(filler: SWMLSWAIGVisualInputFiller): any { const objectEntries = Object.entries(filler).map(([languageCode, value]) => { const tuple: [string, any] = [languageCode, value]; return tuple; }) return Object.fromEntries(objectEntries); } export function convertJSONToSWMLSWAIGVisualInputFiller(json: any): SWMLSWAIGVisualInputFiller { const entries = Object.entries(json).map(([languageCode, value]) => { const tuple: [string, string[]] = [languageCode, value as string[]]; return tuple; }); return Object.fromEntries(entries); } export function convertSWMLSWAIGInternalFillerToJSON(filler?: SWMLSWAIGInternalFiller): any { if (filler === undefined) { return undefined; } return { get_visual_input: convertSWMLSWAIGVisualInputFillerToJSON(filler.getVisualInput) } } export function convertJSONToSWMLSWAIGInternalFiller(json?: any): SWMLSWAIGInternalFiller | undefined { if (json === undefined) { return undefined; } return { getVisualInput: convertJSONToSWMLSWAIGVisualInputFiller(json.get_visual_input) } } export function convertSWMLSWAIGToJSON(swaig?: SWMLSWAIG): any { if (swaig === undefined) { return undefined; } return { defaults: convertSWMLSWAIGDefaultsToJSON(swaig.defaults), functions: swaig.functions?.map(convertSWMLSWAIGFunctionToJSON), includes: swaig.includes?.map(convertSWMLSWAIGIncludeToJSON), internal_fillers: convertSWMLSWAIGInternalFillerToJSON(swaig.internalFillers), native_functions: swaig.nativeFunctions, } } export function convertJSONToSWMLSWAIG(json?: any): SWMLSWAIG | undefined { if (json === undefined) { return undefined; } return { defaults: convertJSONToSWMLSWAIGDefaults(json.defaults), functions: json.functions?.map(convertJSONToSWMLSWAIGFunction), includes: json.includes?.map(convertJSONToSWMLSWAIGInclude), internalFillers: convertJSONToSWMLSWAIGInternalFiller(json.internal_fillers), nativeFunctions: json.native_functions, } } export function convertSWMLAIHintsToJSON(hints?: string[] | SWMLAIHint[]): any { const isArrayOfStrings = Array.isArray(hints) && hints.every(element => typeof element === 'string'); if (isArrayOfStrings) { return hints as string[]; } else { return hints?.map(convertSWMLAIHintToJSON); } } export function convertJSONToSWMLAIHints(json?: any): string[] | SWMLAIHint[] | undefined { const isArrayOfStrings = Array.isArray(json) && json.every(element => typeof element === 'string'); if (isArrayOfStrings) { return json as string[]; } else { return json?.map(convertJSONToSWMLAIHint); } } export function convertSWMLAIParametersToJSON(parameters: SWMLAIParameters): any { return { global_data: parameters.globalData, hints: convertSWMLAIHintsToJSON(parameters.hints), languages: parameters.languages?.map(convertSWMLAILanguageToJSON), params: convertSWMLAIParamsToJSON(parameters.params), post_prompt: convertSWMLAIPromptToJSON(parameters.postPrompt), post_prompt_url: parameters.postPromptUrl, pronounce: parameters.pronounce?.map(convertSWMLAIPronounceToJSON), prompt: convertSWMLAIPromptToJSON(parameters.prompt), SWAIG: convertSWMLSWAIGToJSON(parameters.SWAIG) } } export function convertJSONToSWMLAIParameters(json: any): SWMLAIParameters { return { globalData: json.global_data, hints: convertJSONToSWMLAIHints(json.hints), languages: json.languages?.map(convertJSONToSWMLAILanguage), params: convertJSONToSWMLAIParams(json.params), postPrompt: convertJSONToSWMLAIPrompt(json.post_prompt), postPromptUrl: json.post_prompt_url, pronounce: json.pronounce?.map(convertJSONToSWMLAIPronounce), prompt: convertJSONToSWMLAIPrompt(json.prompt)!, SWAIG: convertJSONToSWMLSWAIG(json.SWAIG) } } export function convertSWMLAIMethodToJSON(method: SWMLAIMethod): any { return { ai: convertSWMLAIParametersToJSON(method.ai) } } export function convertJSONToSWMLAIMethod(json: any): SWMLAIMethod { return { type: 'ai', ai: convertJSONToSWMLAIParameters(json.ai) } } export function convertSWMLAnswerParametersToJSON(parameters: SWMLAnswerParameters): any { return { max_duration: parameters.maxDuration, sip_auth_username: parameters.sipAuthUsername, sip_auth_password: parameters.sipAuthPassword, } } export function convertJSONToSWMLAnswerParameters(json: any): SWMLAnswerParameters { return { maxDuration: json.max_duration, sipAuthUsername: json.sip_auth_username, sipAuthPassword: json.sip_auth_password, } } export function convertSWMLAnswerMethodToJSON(method: SWMLAnswerMethod): any { return { answer: convertSWMLAnswerParametersToJSON(method.answer) } } export function convertJSONToSWMLAnswerMethod(json: any): SWMLAnswerMethod { return { type: 'answer', answer: convertJSONToSWMLAnswerParameters(json.answer) } } export function convertSWMLCondWhenThenParametersToJSON(parameters: SWMLCondWhenThenParameters): any { return { when: parameters.when, then: parameters.then.map(convertSWMLMethodToJSON), } } export function convertJSONToSWMLCondWhenThenParameters(json: any): SWMLCondWhenThenParameters { return { type: 'whenThen', when: json.when, then: json.then.map(convertJSONToSWMLMethod), } } export function convertSWMLCondElseParametersToJSON(parameters: SWMLCondElseParameters): any { return { else: parameters.else?.map(convertSWMLMethodToJSON) } } export function convertJSONToSWMLCondElseParameters(json: any): SWMLCondElseParameters { return { type: 'else', else: json.else?.map(convertJSONToSWMLMethod), } } export function convertSWMLCondParametersToJSON(parameters: SWMLCondParameters): any { switch (parameters.type) { case 'whenThen': return convertSWMLCondWhenThenParametersToJSON(parameters); case 'else': return convertSWMLCondElseParametersToJSON(parameters); default: throw Error("Unknown Cond Type"); } } export function convertJSONToSWMLCondParameters(json: any): SWMLCondParameters { const objectKeys = Object.keys(json); if (objectKeys.includes('when')) { return convertJSONToSWMLCondWhenThenParameters(json); } else if (objectKeys.includes('else') || json.else === undefined) { return convertJSONToSWMLCondElseParameters(json); } else { throw Error("Unknown Cond Type"); } } export function convertSWMLCondMethodToJSON(method: SWMLCondMethod): any { return { cond: method.cond.map(convertSWMLCondParametersToJSON) } } export function convertJSONToSWMLCondMethod(json: any): SWMLCondMethod { return { type: 'cond', cond: json.cond.map(convertJSONToSWMLCondParameters), } } export function convertSWMLConnectHeaderToJSON(header: SWMLConnectHeader): any { return { name: header.name, value: header.value, } } export function convertJSONToSWMLConnectHeader(json: any): SWMLConnectHeader { return { name: json.name, value: json.value, } } export function convertSWMLConnectToDialingParameterToJSONObject(parameter: SWMLConnectToDialingParameter): any { return { to: parameter.to } } export function convertToParameterToSWMLConnectToDialingParameter(to: string): SWMLConnectToDialingParameter { return { type: 'to', to: to } } export function convertSWMLConnectDestinationToJSON(destination: SWMLConnectDestination): any { return { to: destination.to, from: destination.from, timeout: destination.timeout, call_state_url: destination.callStateUrl, call_state_events: destination.callStateEvents, } } export function convertJSONToSWMLConnectDestination(json: any): SWMLConnectDestination { return { to: json.to, from: json.from, timeout: json.timeout, callStateUrl: json.call_state_url, callStateEvents: json.call_state_events, } } export function convertSWMLConnectSerialDialingParameterToJSONObject(parameter: SWMLConnectSerialDialingParameter): any { return { serial: parameter.serial.map(convertSWMLConnectDestinationToJSON), } } export function convertJSONObjectToSWMLConnectSerialDialingParameter(json: any): SWMLConnectSerialDialingParameter { return { type: 'serial', serial: json.serial.map(convertJSONToSWMLConnectDestination), } } export function convertSWMLConnectParallelDialingParameterToJSONObject(parameter: SWMLConnectParallelDialingParameter): any { return { parallel: parameter.parallel.map(convertSWMLConnectDestinationToJSON), } } export function convertJSONObjectToSWMLConnectParallelDialingParameter(json: any): SWMLConnectParallelDialingParameter { return { type: 'parallel', parallel: json.parallel.map(convertJSONToSWMLConnectDestination), } } export function convertSWMLConnectSerialParallelDialingParameterToJSONObject(parameter: SWMLConnectSerialParallelDialingParameter): any { return { serial_parallel: parameter.serialParallel.map(parallel => parallel.map(convertSWMLConnectDestinationToJSON)), } } export function convertJSONObjectToSWMLConnectSerialParallelDialingParameter(json: any): SWMLConnectSerialParallelDialingParameter { return { type: 'serialParallel', serialParallel: json.serial_parallel.map((parallel: any[]) => parallel.map(convertJSONToSWMLConnectDestination)), } } export function convertSWMLConnectDialingParameterToJSONObject(parameter: SWMLConnectDialingParameter): any { switch (parameter.type) { case 'to': return convertSWMLConnectToDialingParameterToJSONObject(parameter); case 'serial': return convertSWMLConnectSerialDialingParameterToJSONObject(parameter); case 'parallel'