示例#1
0
        /// <summary>
        /// Sends user input (text or speech) to Amazon Lex. Clients use this API to send text
        /// and audio requests to Amazon Lex at runtime. Amazon Lex interprets the user input
        /// using the machine learning model that it built for the bot.
        ///
        ///
        /// <para>
        /// The <code>PostContent</code> operation supports audio input at 8kHz and 16kHz. You
        /// can use 8kHz audio to achieve higher speech recognition accuracy in telephone audio
        /// applications.
        /// </para>
        ///
        /// <para>
        ///  In response, Amazon Lex returns the next message to convey to the user. Consider
        /// the following example messages:
        /// </para>
        ///  <ul> <li>
        /// <para>
        ///  For a user input "I would like a pizza," Amazon Lex might return a response with
        /// a message eliciting slot data (for example, <code>PizzaSize</code>): "What size pizza
        /// would you like?".
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  After the user provides all of the pizza order information, Amazon Lex might return
        /// a response with a message to get user confirmation: "Order the pizza?".
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  After the user replies "Yes" to the confirmation prompt, Amazon Lex might return
        /// a conclusion statement: "Thank you, your cheese pizza has been ordered.".
        /// </para>
        ///  </li> </ul>
        /// <para>
        ///  Not all Amazon Lex messages require a response from the user. For example, conclusion
        /// statements do not require a response. Some messages require only a yes or no response.
        /// In addition to the <code>message</code>, Amazon Lex provides additional context about
        /// the message in the response that you can use to enhance client behavior, such as displaying
        /// the appropriate client user interface. Consider the following examples:
        /// </para>
        ///  <ul> <li>
        /// <para>
        ///  If the message is to elicit slot data, Amazon Lex returns the following context information:
        ///
        /// </para>
        ///  <ul> <li>
        /// <para>
        ///  <code>x-amz-lex-dialog-state</code> header set to <code>ElicitSlot</code>
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  <code>x-amz-lex-intent-name</code> header set to the intent name in the current context
        ///
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  <code>x-amz-lex-slot-to-elicit</code> header set to the slot name for which the <code>message</code>
        /// is eliciting information
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  <code>x-amz-lex-slots</code> header set to a map of slots configured for the intent
        /// with their current values
        /// </para>
        ///  </li> </ul> </li> <li>
        /// <para>
        ///  If the message is a confirmation prompt, the <code>x-amz-lex-dialog-state</code>
        /// header is set to <code>Confirmation</code> and the <code>x-amz-lex-slot-to-elicit</code>
        /// header is omitted.
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  If the message is a clarification prompt configured for the intent, indicating that
        /// the user intent is not understood, the <code>x-amz-dialog-state</code> header is set
        /// to <code>ElicitIntent</code> and the <code>x-amz-slot-to-elicit</code> header is omitted.
        ///
        /// </para>
        ///  </li> </ul>
        /// <para>
        ///  In addition, Amazon Lex also returns your application-specific <code>sessionAttributes</code>.
        /// For more information, see <a href="http://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html">Managing
        /// Conversation Context</a>.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the PostContent service method.</param>
        ///
        /// <returns>The response from the PostContent service method, as returned by Lex.</returns>
        /// <exception cref="Amazon.Lex.Model.BadGatewayException">
        /// Either the Amazon Lex bot is still building, or one of the dependent services (Amazon
        /// Polly, AWS Lambda) failed with an internal service error.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.BadRequestException">
        /// Request validation failed, there is no usable message in the context, or the bot
        /// build failed, is still in progress, or contains unbuilt changes.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.ConflictException">
        /// Two clients are using the same AWS account, Amazon Lex bot, and user ID.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.DependencyFailedException">
        /// One of the dependencies, such as AWS Lambda or Amazon Polly, threw an exception.
        /// For example,
        ///
        ///  <ul> <li>
        /// <para>
        /// If Amazon Lex does not have sufficient permissions to call a Lambda function.
        /// </para>
        ///  </li> <li>
        /// <para>
        /// If a Lambda function takes longer than 30 seconds to execute.
        /// </para>
        ///  </li> <li>
        /// <para>
        /// If a fulfillment Lambda function returns a <code>Delegate</code> dialog action without
        /// removing any slot values.
        /// </para>
        ///  </li> </ul>
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.InternalFailureException">
        /// Internal service error. Retry the call.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.LimitExceededException">
        /// Exceeded a limit.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.LoopDetectedException">
        /// This exception is not used.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.NotAcceptableException">
        /// The accept header in the request does not have a valid value.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.NotFoundException">
        /// The resource (such as the Amazon Lex bot or an alias) that is referred to is not found.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.RequestTimeoutException">
        /// The input speech is too long.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.UnsupportedMediaTypeException">
        /// The Content-Type header (<code>PostContent</code> API) has an invalid value.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostContent">REST API Reference for PostContent Operation</seealso>
        public virtual PostContentResponse PostContent(PostContentRequest request)
        {
            var marshaller   = new PostContentRequestMarshaller();
            var unmarshaller = PostContentResponseUnmarshaller.Instance;

            return(Invoke <PostContentRequest, PostContentResponse>(request, marshaller, unmarshaller));
        }
        /// <inheritdoc />
        protected override async Task <LabeledUtterance> TestSpeechAsync(string speechFile, CancellationToken cancellationToken)
        {
            if (speechFile == null)
            {
                throw new ArgumentNullException(nameof(speechFile));
            }

            using (var stream = File.OpenRead(speechFile))
            {
                var postContentRequest = new PostContentRequest
                {
                    BotAlias    = this.LexBotAlias,
                    BotName     = this.LexBotName,
                    UserId      = Guid.NewGuid().ToString(),
                    Accept      = "text/plain; charset=utf-8",
                    ContentType = "audio/l16; rate=16000; channels=1",
                    InputStream = stream,
                };

                var postContentResponse = await this.LexClient.PostContentAsync(postContentRequest, cancellationToken).ConfigureAwait(false);

                var slots = postContentResponse.Slots != null
                    ? JsonConvert.DeserializeObject <Dictionary <string, string> >(postContentResponse.Slots)
                            .Select(slot => new Entity(slot.Key, slot.Value, null, 0))
                            .ToArray()
                    : null;

                return(new LabeledUtterance(
                           postContentResponse.InputTranscript,
                           postContentResponse.IntentName,
                           slots));
            }
        }
示例#3
0
        /// <summary>
        /// Initiates the asynchronous execution of the PostContent operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PostContent operation on AmazonLexClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPostContent
        ///         operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostContent">REST API Reference for PostContent Operation</seealso>
        public virtual IAsyncResult BeginPostContent(PostContentRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = new PostContentRequestMarshaller();
            var unmarshaller = PostContentResponseUnmarshaller.Instance;

            return(BeginInvoke <PostContentRequest>(request, marshaller, unmarshaller,
                                                    callback, state));
        }
示例#4
0
        /// <summary>
        /// Initiates the asynchronous execution of the PostContent operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PostContent operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostContent">REST API Reference for PostContent Operation</seealso>
        public Task <PostContentResponse> PostContentAsync(PostContentRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new PostContentRequestMarshaller();
            var unmarshaller = PostContentResponseUnmarshaller.Instance;

            return(InvokeAsync <PostContentRequest, PostContentResponse>(request, marshaller,
                                                                         unmarshaller, cancellationToken));
        }
示例#5
0
        /// <summary>
        /// Sends user input (text or speech) to Amazon Lex. Clients use this API to send text
        /// and audio requests to Amazon Lex at runtime. Amazon Lex interprets the user input
        /// using the machine learning model that it built for the bot.
        ///
        ///
        /// <para>
        /// The <code>PostContent</code> operation supports audio input at 8kHz and 16kHz. You
        /// can use 8kHz audio to achieve higher speech recognition accuracy in telephone audio
        /// applications.
        /// </para>
        ///
        /// <para>
        ///  In response, Amazon Lex returns the next message to convey to the user. Consider
        /// the following example messages:
        /// </para>
        ///  <ul> <li>
        /// <para>
        ///  For a user input "I would like a pizza," Amazon Lex might return a response with
        /// a message eliciting slot data (for example, <code>PizzaSize</code>): "What size pizza
        /// would you like?".
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  After the user provides all of the pizza order information, Amazon Lex might return
        /// a response with a message to get user confirmation: "Order the pizza?".
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  After the user replies "Yes" to the confirmation prompt, Amazon Lex might return
        /// a conclusion statement: "Thank you, your cheese pizza has been ordered.".
        /// </para>
        ///  </li> </ul>
        /// <para>
        ///  Not all Amazon Lex messages require a response from the user. For example, conclusion
        /// statements do not require a response. Some messages require only a yes or no response.
        /// In addition to the <code>message</code>, Amazon Lex provides additional context about
        /// the message in the response that you can use to enhance client behavior, such as displaying
        /// the appropriate client user interface. Consider the following examples:
        /// </para>
        ///  <ul> <li>
        /// <para>
        ///  If the message is to elicit slot data, Amazon Lex returns the following context information:
        ///
        /// </para>
        ///  <ul> <li>
        /// <para>
        ///  <code>x-amz-lex-dialog-state</code> header set to <code>ElicitSlot</code>
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  <code>x-amz-lex-intent-name</code> header set to the intent name in the current context
        ///
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  <code>x-amz-lex-slot-to-elicit</code> header set to the slot name for which the <code>message</code>
        /// is eliciting information
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  <code>x-amz-lex-slots</code> header set to a map of slots configured for the intent
        /// with their current values
        /// </para>
        ///  </li> </ul> </li> <li>
        /// <para>
        ///  If the message is a confirmation prompt, the <code>x-amz-lex-dialog-state</code>
        /// header is set to <code>Confirmation</code> and the <code>x-amz-lex-slot-to-elicit</code>
        /// header is omitted.
        /// </para>
        ///  </li> <li>
        /// <para>
        ///  If the message is a clarification prompt configured for the intent, indicating that
        /// the user intent is not understood, the <code>x-amz-dialog-state</code> header is set
        /// to <code>ElicitIntent</code> and the <code>x-amz-slot-to-elicit</code> header is omitted.
        ///
        /// </para>
        ///  </li> </ul>
        /// <para>
        ///  In addition, Amazon Lex also returns your application-specific <code>sessionAttributes</code>.
        /// For more information, see <a href="https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html">Managing
        /// Conversation Context</a>.
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the PostContent service method.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        ///
        /// <returns>The response from the PostContent service method, as returned by Lex.</returns>
        /// <exception cref="Amazon.Lex.Model.BadGatewayException">
        /// Either the Amazon Lex bot is still building, or one of the dependent services (Amazon
        /// Polly, AWS Lambda) failed with an internal service error.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.BadRequestException">
        /// Request validation failed, there is no usable message in the context, or the bot
        /// build failed, is still in progress, or contains unbuilt changes.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.ConflictException">
        /// Two clients are using the same AWS account, Amazon Lex bot, and user ID.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.DependencyFailedException">
        /// One of the dependencies, such as AWS Lambda or Amazon Polly, threw an exception.
        /// For example,
        ///
        ///  <ul> <li>
        /// <para>
        /// If Amazon Lex does not have sufficient permissions to call a Lambda function.
        /// </para>
        ///  </li> <li>
        /// <para>
        /// If a Lambda function takes longer than 30 seconds to execute.
        /// </para>
        ///  </li> <li>
        /// <para>
        /// If a fulfillment Lambda function returns a <code>Delegate</code> dialog action without
        /// removing any slot values.
        /// </para>
        ///  </li> </ul>
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.InternalFailureException">
        /// Internal service error. Retry the call.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.LimitExceededException">
        /// Exceeded a limit.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.LoopDetectedException">
        /// This exception is not used.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.NotAcceptableException">
        /// The accept header in the request does not have a valid value.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.NotFoundException">
        /// The resource (such as the Amazon Lex bot or an alias) that is referred to is not found.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.RequestTimeoutException">
        /// The input speech is too long.
        /// </exception>
        /// <exception cref="Amazon.Lex.Model.UnsupportedMediaTypeException">
        /// The Content-Type header (<code>PostContent</code> API) has an invalid value.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostContent">REST API Reference for PostContent Operation</seealso>
        public virtual Task <PostContentResponse> PostContentAsync(PostContentRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PostContentRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PostContentResponseUnmarshaller.Instance;

            return(InvokeAsync <PostContentResponse>(request, options, cancellationToken));
        }
示例#6
0
        internal virtual PostContentResponse PostContent(PostContentRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PostContentRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PostContentResponseUnmarshaller.Instance;

            return(Invoke <PostContentResponse>(request, options));
        }
示例#7
0
        /// <summary>
        /// Initiates the asynchronous execution of the PostContent operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PostContent operation on AmazonLexClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndPostContent
        ///         operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostContent">REST API Reference for PostContent Operation</seealso>
        public virtual IAsyncResult BeginPostContent(PostContentRequest request, AsyncCallback callback, object state)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = PostContentRequestMarshaller.Instance;
            options.ResponseUnmarshaller = PostContentResponseUnmarshaller.Instance;

            return(BeginInvoke(request, options, callback, state));
        }
示例#8
0
            public async Task <PostContentResponse> PostContentAsync(PostContentRequest request, CancellationToken cancellationToken)
            {
                var streamCopy = new MemoryStream();

                request.InputStream.CopyTo(streamCopy);
                streamCopy.Position = 0;
                var requestCopy = new PostContentRequest
                {
                    Accept      = request.Accept,
                    BotAlias    = request.BotAlias,
                    BotName     = request.BotName,
                    ContentType = request.ContentType,
                    InputStream = streamCopy,
                    UserId      = request.UserId,
                };

                await this.ProcessRequestAsync(requestCopy).ConfigureAwait(false);

                return(this.Get <PostContentResponse>());
            }
示例#9
0
 public Task <PostContentResponse> PostContentAsync(PostContentRequest request, CancellationToken cancellationToken)
 {
     return(RetryAsync(this.AmazonLexClient.PostContentAsync, request, cancellationToken));
 }