Ejemplo n.º 1
0
        /// <summary>
        /// Creates a message request that will process a query string with NLU
        /// </summary>
        /// <param name="config"></param>
        /// <param name="query">Text string to process with the NLU</param>
        /// <returns></returns>
        public static WitRequest MessageRequest(this WitConfiguration config, string query, WitRequestOptions requestOptions, IDynamicEntitiesProvider[] additionalDynamicEntities = null)
        {
            List <WitRequest.QueryParam> queryParams = new List <WitRequest.QueryParam>
            {
                QueryParam("q", query)
            };

            if (null != requestOptions && -1 != requestOptions.nBestIntents)
            {
                queryParams.Add(QueryParam("n", requestOptions.nBestIntents.ToString()));
            }

            HandleWitRequestOptions(requestOptions, additionalDynamicEntities, queryParams);

            if (null != requestOptions && !string.IsNullOrEmpty(requestOptions.tag))
            {
                queryParams.Add(QueryParam("tag", requestOptions.tag));
            }

            var        path    = WitEndpointConfig.GetEndpointConfig(config).Message;
            WitRequest request = new WitRequest(config, path, queryParams.ToArray());

            if (null != requestOptions)
            {
                request.onResponse += requestOptions.onResponse;
                request.requestId   = requestOptions.requestID;
            }

            return(request);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Requests a client token for an application
        /// </summary>
        /// <param name="config"></param>
        /// <param name="appId">The id of the app as it is defined in wit.ai</param>
        /// <param name="refresh">Should the token be refreshed</param>
        /// <returns></returns>
        public static WitRequest GetClientToken(this WitConfiguration config, string appId, bool refresh = false)
        {
            var postString = "{\"refresh\":" + refresh.ToString().ToLower() + "}";
            var postData   = Encoding.UTF8.GetBytes(postString);
            var request    = new WitRequest(config, $"{WitRequest.WIT_ENDPOINT_APPS}/{appId}/client_tokens", true)
            {
                postContentType = "application/json",
                postData        = postData
            };

            return(request);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a request for getting the transcription from the mic data
        /// </summary>
        ///<param name="config"></param>
        /// <param name="requestOptions"></param>
        /// <returns>WitRequest</returns>
        public static WitRequest DictationRequest(this WitConfiguration config, WitRequestOptions requestOptions)
        {
            List <WitRequest.QueryParam> queryParams = new List <WitRequest.QueryParam>();
            var        path    = WitEndpointConfig.GetEndpointConfig(config).Dictation;
            WitRequest request = new WitRequest(config, path, queryParams.ToArray());

            if (null != requestOptions)
            {
                request.onResponse += requestOptions.onResponse;
                request.requestId   = requestOptions.requestID;
            }

            return(request);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a request for nlu processing that includes a data stream for mic data
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static WitRequest SpeechRequest(this WitConfiguration config, WitRequestOptions requestOptions, IDynamicEntitiesProvider[] additionalEntityProviders = null)
        {
            List <WitRequest.QueryParam> queryParams = new List <WitRequest.QueryParam>();

            if (null != requestOptions && -1 != requestOptions.nBestIntents)
            {
                queryParams.Add(QueryParam("n", requestOptions.nBestIntents.ToString()));
            }

            HandleWitRequestOptions(requestOptions, additionalEntityProviders, queryParams);

            var        path    = WitEndpointConfig.GetEndpointConfig(config).Speech;
            WitRequest request = new WitRequest(config, path, queryParams.ToArray());

            if (null != requestOptions)
            {
                request.onResponse += requestOptions.onResponse;
                request.requestId   = requestOptions.requestID;
            }

            return(request);
        }