microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 5.06 kB
Source Map (JSON)
{"version":3,"sources":["src/common.speech/DialogConnectorFactory.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAqB,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAA6B,MAAM,cAAc,CAAC;AAIrF,qBAAa,uBAAwB,SAAQ,qBAAqB;IAE9D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAiB;IAC/C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAA2B;IAEnD,MAAM,CACT,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW;CAqD1C","file":"DialogConnectorFactory.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\n/* eslint-disable max-classes-per-file */\r\nimport {\r\n ProxyInfo,\r\n WebsocketConnection,\r\n} from \"../common.browser/Exports.js\";\r\nimport { OutputFormatPropertyName } from \"../common.speech/Exports.js\";\r\nimport { IConnection, IStringDictionary } from \"../common/Exports.js\";\r\nimport { DialogServiceConfig, OutputFormat, PropertyId } from \"../sdk/Exports.js\";\r\nimport { ConnectionFactoryBase } from \"./ConnectionFactoryBase.js\";\r\nimport { AuthInfo, RecognizerConfig, WebsocketMessageFormatter } from \"./Exports.js\";\r\nimport { HeaderNames } from \"./HeaderNames.js\";\r\nimport { QueryParameterNames } from \"./QueryParameterNames.js\";\r\n\r\nexport class DialogConnectionFactory extends ConnectionFactoryBase {\r\n\r\n private static readonly ApiKey: string = \"api\";\r\n private static readonly BaseUrl: string = \"convai.speech\";\r\n\r\n public create(\r\n config: RecognizerConfig,\r\n authInfo: AuthInfo,\r\n connectionId?: string): IConnection {\r\n\r\n const applicationId: string = config.parameters.getProperty(PropertyId.Conversation_ApplicationId, \"\");\r\n const dialogType: string = config.parameters.getProperty(PropertyId.Conversation_DialogType);\r\n const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region);\r\n const language: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage, \"en-US\");\r\n const requestTurnStatus: string = config.parameters.getProperty(PropertyId.Conversation_Request_Bot_Status_Messages, \"true\");\r\n\r\n const queryParams: IStringDictionary<string> = {};\r\n queryParams[HeaderNames.ConnectionId] = connectionId;\r\n queryParams[QueryParameterNames.Format] = config.parameters.getProperty(OutputFormatPropertyName, OutputFormat[OutputFormat.Simple]).toLowerCase();\r\n queryParams[QueryParameterNames.Language] = language;\r\n queryParams[QueryParameterNames.RequestBotStatusMessages] = requestTurnStatus;\r\n if (applicationId) {\r\n queryParams[QueryParameterNames.BotId] = applicationId;\r\n if (dialogType === DialogServiceConfig.DialogTypes.CustomCommands) {\r\n queryParams[HeaderNames.CustomCommandsAppId] = applicationId;\r\n }\r\n }\r\n\r\n const resourceInfix: string =\r\n dialogType === DialogServiceConfig.DialogTypes.CustomCommands ? \"commands/\"\r\n : \"\";\r\n const version: string =\r\n dialogType === DialogServiceConfig.DialogTypes.CustomCommands ? \"v1\"\r\n : dialogType === DialogServiceConfig.DialogTypes.BotFramework ? \"v3\"\r\n : \"v0\";\r\n\r\n const headers: IStringDictionary<string> = {};\r\n\r\n if (authInfo.token != null && authInfo.token !== \"\") {\r\n headers[authInfo.headerName] = authInfo.token;\r\n }\r\n\r\n // The URL used for connection is chosen in a priority order of specification:\r\n // 1. If a custom endpoint is provided, that URL is used verbatim.\r\n // 2. If a custom host is provided (e.g. \"wss://my.custom.endpoint.com:1123\"), a URL is constructed from it.\r\n // 3. If no custom connection details are provided, a URL is constructed from default values.\r\n let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, \"\");\r\n if (!endpoint) {\r\n const hostSuffix: string = ConnectionFactoryBase.getHostSuffix(region);\r\n const host: string = config.parameters.getProperty(\r\n PropertyId.SpeechServiceConnection_Host,\r\n `wss://${region}.${DialogConnectionFactory.BaseUrl}${hostSuffix}`);\r\n const standardizedHost: string = host.endsWith(\"/\") ? host : host + \"/\";\r\n endpoint = `${standardizedHost}${resourceInfix}${DialogConnectionFactory.ApiKey}/${version}`;\r\n }\r\n\r\n this.setCommonUrlParams(config, queryParams, endpoint);\r\n\r\n const enableCompression: boolean = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\r\n return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\r\n }\r\n}\r\n"]}