Example #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));
        }
Example #2
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));
        }
Example #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.</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));
        }
Example #4
0
        public void PostContentMarshallTest()
        {
            var operation = service_model.FindOperation("PostContent");

            var request    = InstantiateClassGenerator.Execute <PostContentRequest>();
            var marshaller = new PostContentRequestMarshaller();

            var internalRequest = marshaller.Marshall(request);

            TestTools.RequestValidator.Validate("PostContent", request, internalRequest, service_model);

            var webResponse = new WebResponseData
            {
                Headers =
                {
                    { "Content-Type",                 "Content-Type_Value"                                                                 },
                    { "x-amz-lex-dialog-state",       "x-amz-lex-dialog-state_Value"                                                       },
                    { "x-amz-lex-input-transcript",   "x-amz-lex-input-transcript_Value"                                                   },
                    { "x-amz-lex-intent-name",        "x-amz-lex-intent-name_Value"                                                        },
                    { "x-amz-lex-message",            "x-amz-lex-message_Value"                                                            },
                    { "x-amz-lex-message-format",     "x-amz-lex-message-format_Value"                                                     },
                    { "x-amz-lex-sentiment",          "x-amz-lex-sentiment_Value"                                                          },
                    { "x-amz-lex-session-attributes", Convert.ToBase64String(Encoding.UTF8.GetBytes("x-amz-lex-session-attributes_Value")) },
                    { "x-amz-lex-session-id",         "x-amz-lex-session-id_Value"                                                         },
                    { "x-amz-lex-slots",              Convert.ToBase64String(Encoding.UTF8.GetBytes("x-amz-lex-slots_Value"))              },
                    { "x-amz-lex-slot-to-elicit",     "x-amz-lex-slot-to-elicit_Value"                                                     },
                    { "x-amzn-RequestId",             Guid.NewGuid().ToString()                                                            },
                    { "x-amz-crc32",                  "0"                                                                                  }
                }
            };

            var payloadResponse = new JsonSampleGenerator(service_model, operation.ResponseStructure).Execute();

            webResponse.Headers["Content-Length"] = UTF8Encoding.UTF8.GetBytes(payloadResponse).Length.ToString();
            var context = new JsonUnmarshallerContext(Utils.CreateStreamFromString(payloadResponse), false, webResponse);
            ResponseUnmarshaller unmarshaller = PostContentResponseUnmarshaller.Instance;
            var response = unmarshaller.Unmarshall(context)
                           as PostContentResponse;

            InstantiateClassGenerator.ValidateObjectFullyInstantiated(response);
        }