UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

131 lines 5.08 kB
import { __awaiter } from "tslib"; /** Custom Modules */ import { createNodeDescriptor } from "../../../createNodeDescriptor"; /** Helper Modules */ import { play } from "../../voice/mappers/play.mapper"; import { nodeColor } from '../utils/design'; import { getParameterFields, getParamSections } from "../utils/paramUtils"; import { buildPayloadAccm } from "./helper/utils"; export const playURLNode = createNodeDescriptor({ type: "playURL", defaultLabel: "Play URL", summary: "UI__NODE_EDITOR__VG__PLAY_URL__SUMMARY", // @ts-ignore fields: [ { key: "playUrlUrl", label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_URL__LABEL", type: "cognigyText", params: { required: true } }, { key: "playUrlMediaFormat", label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_MEDIA_FORMAT__LABEL", type: "select", defaultValue: "wav/lpcm16", description: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_MEDIA_FORMAT__DESCRIPTION", params: { options: [ { label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_MEDIA_FORMAT__OPTIONS__WAV_LPCM16__LABEL", value: "wav/lpcm16" }, { label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_MEDIA_FORMAT__OPTIONS__RAW_LPCM16__LABEL", value: "raw/lpcm16" }, { label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_MEDIA_FORMAT__OPTIONS__WAV_MULAW__LABEL", value: "wav/mulaw" }, { label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_MEDIA_FORMAT__OPTIONS__RAW_MULAW__LABEL", value: "raw/mulaw" } ] } }, { key: "playUrlAltText", label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_ALT_TEXT__LABEL", type: "cognigyText", description: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_ALT_TEXT__DESCRIPTION", defaultValue: "" }, { key: "playUrlCaching", label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__PLAY_URL_CACHING__LABEL", type: "toggle", defaultValue: false }, { key: "setActivityParams", label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__SET_ACTIVITY_PARAMS__LABEL", type: "toggle", defaultValue: false }, { key: "activityParams", label: "UI__NODE_EDITOR__VG__PLAY_URL__FIELDS__ACTIVITY_PARAMS__LABEL", type: "json", defaultValue: "{}" } ].concat(getParameterFields()), sections: [ { key: "advanced", label: "UI__NODE_EDITOR__VG__PLAY_URL__SECTIONS__ADVANCED__LABEL", defaultCollapsed: true, fields: [ "activityParams", ], condition: { key: "setActivityParams", value: true } } ].concat(getParamSections({ key: "setActivityParams", value: true })), form: [ { type: "field", key: "playUrlUrl" }, { type: "field", key: "playUrlMediaFormat" }, { type: "field", key: "playUrlCaching" }, { type: "field", key: "setActivityParams" }, { type: "section", key: "params_stt" }, { type: "section", key: "params_tts" }, { type: "section", key: "params_dtmf" }, { type: "section", key: "params_bargein" }, { type: "section", key: "params_continuousasr" }, { type: "section", key: "params_user_timeouts" }, { type: "section", key: "params_bot_timeouts" }, { type: "section", key: "params_azure" }, { type: "section", key: "params_google" }, { type: "section", key: "advanced" }, ], preview: { type: "text", key: "playUrlUrl" }, appearance: { color: nodeColor }, function: ({ cognigy, config, nodeId }) => __awaiter(void 0, void 0, void 0, function* () { const { api } = cognigy; const { playUrlUrl, playUrlMediaFormat } = config; if (playUrlUrl && playUrlMediaFormat) { try { const { isFeatureAccmEnabled } = api.getEndpointSettings(); const payload = isFeatureAccmEnabled ? buildPayloadAccm("playURL", config, nodeId) : play.handleInput({ endpointType: 'audioCodes', config }); yield api.say(null, { _cognigy: payload }); } catch (error) { throw new Error(`Error on play node. Error message: ${error.message}`); } ; } }) }); //# sourceMappingURL=playURL.js.map