partial void sendMessage(UIButton sender) { Console.WriteLine("Message is " + messageText); //sendMessageApi(messageText.Text); messages.Add("You: " + messageText.Text); tableView.ReloadData(); AmazonLexClient lexClient = new AmazonLexClient(accessKey, accessKeySecret, accessSessionToken, Amazon.RegionEndpoint.USEast1); PostTextRequest request = new PostTextRequest(); request.BotName = "GolfNowReservation"; request.BotAlias = "GolfNowTest"; request.UserId = "250"; request.InputText = messageText.Text; var task = lexClient.PostTextAsync(request); messages.Add("Bot: " + task.Result.Message); messageText.Text = ""; tableView.ReloadData(); //throw new NotImplementedException(); }
public async Task <PostTextResponse> SendTextMessageToLexAsync(string messageToSend, string sessionId, Dictionary <string, string> lexSessionAttributes) { PostTextResponse lextTextResponse; var lexTextRequest = new PostTextRequest { BotAlias = _lexOptions.LexBotAlias, BotName = _lexOptions.LexBotName, UserId = sessionId, InputText = messageToSend, SessionAttributes = lexSessionAttributes }; try { lextTextResponse = await _awsLexClient.PostTextAsync(lexTextRequest); } catch (Exception ex) { _logger.LogError($"AWSLexService.SendTextMessageToLexAsync got an exception for a request: " + $"{Newtonsoft.Json.JsonConvert.SerializeObject(lexTextRequest)} with message: {ex.Message}"); throw; } return(lextTextResponse); }
/// <summary> /// Sends user input (text-only) to Amazon Lex. Client applications can use this API to /// send requests to Amazon Lex at runtime. Amazon Lex then interprets the user input /// using the machine learning model it built for the bot. /// /// /// <para> /// In response, Amazon Lex returns the next <code>message</code> to convey to the user /// an optional <code>responseCard</code> to display. 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, PizzaSize): "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 obtain user confirmation "Proceed with the pizza order?". /// /// </para> /// </li> <li> /// <para> /// After the user replies to a confirmation prompt with a "yes", 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 user response. For example, a conclusion statement /// does not require a response. Some messages require only a "yes" or "no" user response. /// In addition to the <code>message</code>, Amazon Lex provides additional context about /// the message in the response that you might use to enhance client behavior, for example, /// to display the appropriate client user interface. These are the <code>slotToElicit</code>, /// <code>dialogState</code>, <code>intentName</code>, and <code>slots</code> fields in /// the response. 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>dialogState</code> set to ElicitSlot /// </para> /// </li> <li> /// <para> /// <code>intentName</code> set to the intent name in the current context /// </para> /// </li> <li> /// <para> /// <code>slotToElicit</code> set to the slot name for which the <code>message</code> /// is eliciting information /// </para> /// </li> <li> /// <para> /// <code>slots</code> set to a map of slots, configured for the intent, with currently /// known values /// </para> /// </li> </ul> </li> <li> /// <para> /// If the message is a confirmation prompt, the <code>dialogState</code> is set to ConfirmIntent /// and <code>SlotToElicit</code> is set to null. /// </para> /// </li> <li> /// <para> /// If the message is a clarification prompt (configured for the intent) that indicates /// that user intent is not understood, the <code>dialogState</code> is set to ElicitIntent /// and <code>slotToElicit</code> is set to null. /// </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 PostText service method.</param> /// /// <returns>The response from the PostText 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.NotFoundException"> /// The resource (such as the Amazon Lex bot or an alias) that is referred to is not found. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostText">REST API Reference for PostText Operation</seealso> public virtual PostTextResponse PostText(PostTextRequest request) { var marshaller = new PostTextRequestMarshaller(); var unmarshaller = PostTextResponseUnmarshaller.Instance; return(Invoke <PostTextRequest, PostTextResponse>(request, marshaller, unmarshaller)); }
/// <summary> /// Insert Text Signature into the Document /// </summary> /// <param name="request">Request. <see cref="PostTextRequest" /></param> /// <returns><see cref="SignatureDocumentResponse"/></returns> public SignatureDocumentResponse PostText(PostTextRequest request) { // verify the required parameter 'name' is set if (request.Name == null) { throw new ApiException(400, "Missing required parameter 'name' when calling PostText"); } // create path and map variables var resourcePath = this.configuration.GetApiRootUrl() + "/signature/{name}/text"; resourcePath = Regex .Replace(resourcePath, "\\*", string.Empty) .Replace("&", "&") .Replace("/?", "?"); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "name", request.Name); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "password", request.Password); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "folder", request.Folder); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storage", request.Storage); var postBody = SerializationHelper.Serialize(request.SignOptionsData); // http body (model) parameter var response = this.apiInvoker.InvokeApi( resourcePath, "POST", postBody, null, null); if (response != null) { return((SignatureDocumentResponse)SerializationHelper.Deserialize(response, typeof(SignatureDocumentResponse))); } return(null); }
/// <inheritdoc /> protected override async Task <LabeledUtterance> TestAsync(string utterance, CancellationToken cancellationToken) { if (utterance == null) { throw new ArgumentNullException(nameof(utterance)); } var postTextRequest = new PostTextRequest { BotAlias = this.LexBotAlias, BotName = this.LexBotName, UserId = Guid.NewGuid().ToString(), InputText = utterance, }; var postTextResponse = await this.LexClient.PostTextAsync(postTextRequest, cancellationToken).ConfigureAwait(false); var entities = postTextResponse.Slots? .Where(slot => slot.Value != null) .Select(slot => new Entity(slot.Key, slot.Value, null, 0)) .ToArray(); return(new LabeledUtterance( utterance, postTextResponse.IntentName, entities)); }
/// <summary> /// Initiates the asynchronous execution of the PostText operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PostText 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/PostText">REST API Reference for PostText Operation</seealso> public Task <PostTextResponse> PostTextAsync(PostTextRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new PostTextRequestMarshaller(); var unmarshaller = PostTextResponseUnmarshaller.Instance; return(InvokeAsync <PostTextRequest, PostTextResponse>(request, marshaller, unmarshaller, cancellationToken)); }
/// <summary> /// Initiates the asynchronous execution of the PostText operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PostText 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 EndPostText /// operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostText">REST API Reference for PostText Operation</seealso> public virtual IAsyncResult BeginPostText(PostTextRequest request, AsyncCallback callback, object state) { var marshaller = new PostTextRequestMarshaller(); var unmarshaller = PostTextResponseUnmarshaller.Instance; return(BeginInvoke <PostTextRequest>(request, marshaller, unmarshaller, callback, state)); }
internal virtual PostTextResponse PostText(PostTextRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = PostTextRequestMarshaller.Instance; options.ResponseUnmarshaller = PostTextResponseUnmarshaller.Instance; return(Invoke <PostTextResponse>(request, options)); }
/// <summary> /// Initiates the asynchronous execution of the PostText operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the PostText 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 EndPostText /// operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostText">REST API Reference for PostText Operation</seealso> public virtual IAsyncResult BeginPostText(PostTextRequest request, AsyncCallback callback, object state) { var options = new InvokeOptions(); options.RequestMarshaller = PostTextRequestMarshaller.Instance; options.ResponseUnmarshaller = PostTextResponseUnmarshaller.Instance; return(BeginInvoke(request, options, callback, state)); }
/// <summary> /// Sends user input to Amazon Lex. Client applications can use this API to send requests /// to Amazon Lex at runtime. Amazon Lex then interprets the user input using the machine /// learning model it built for the bot. /// /// /// <para> /// In response, Amazon Lex returns the next <code>message</code> to convey to the user /// an optional <code>responseCard</code> to display. 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, PizzaSize): "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 obtain user confirmation "Proceed with the pizza order?". /// /// </para> /// </li> <li> /// <para> /// After the user replies to a confirmation prompt with a "yes", 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 user response. For example, a conclusion statement /// does not require a response. Some messages require only a "yes" or "no" user response. /// In addition to the <code>message</code>, Amazon Lex provides additional context about /// the message in the response that you might use to enhance client behavior, for example, /// to display the appropriate client user interface. These are the <code>slotToElicit</code>, /// <code>dialogState</code>, <code>intentName</code>, and <code>slots</code> fields in /// the response. 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>dialogState</code> set to ElicitSlot /// </para> /// </li> <li> /// <para> /// <code>intentName</code> set to the intent name in the current context /// </para> /// </li> <li> /// <para> /// <code>slotToElicit</code> set to the slot name for which the <code>message</code> /// is eliciting information /// </para> /// </li> <li> /// <para> /// <code>slots</code> set to a map of slots, configured for the intent, with currently /// known values /// </para> /// </li> </ul> </li> <li> /// <para> /// If the message is a confirmation prompt, the <code>dialogState</code> is set to ConfirmIntent /// and <code>SlotToElicit</code> is set to null. /// </para> /// </li> <li> /// <para> /// If the message is a clarification prompt (configured for the intent) that indicates /// that user intent is not understood, the <code>dialogState</code> is set to ElicitIntent /// and <code>slotToElicit</code> is set to null. /// </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 PostText 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 PostText 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.NotFoundException"> /// The resource (such as the Amazon Lex bot or an alias) that is referred to is not found. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/runtime.lex-2016-11-28/PostText">REST API Reference for PostText Operation</seealso> public virtual Task <PostTextResponse> PostTextAsync(PostTextRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = PostTextRequestMarshaller.Instance; options.ResponseUnmarshaller = PostTextResponseUnmarshaller.Instance; return(InvokeAsync <PostTextResponse>(request, options, cancellationToken)); }
public async Task <PostTextResponse> SendTextMsgToLex(string messageToSend, string sessionId) { var textRequest = new PostTextRequest { BotName = _amazonLexConfig.BotName, BotAlias = _amazonLexConfig.BotAlias, UserId = sessionId, InputText = messageToSend }; var response = await _amazonLexClient.PostTextAsync(textRequest); return(response); }
public void PostTextTest() { var file = TestFiles.Pdf02; var signOptionsData = new PdfSignTextOptionsData() { BackgroundColor = new Color() { Web = "#fcfcfc" }, BorderColor = new Color() { Web = "#364E6F" }, DocumentPageNumber = 1, Font = new SignatureFontData() { Bold = true, FontFamily = "Arial", FontSize = 12, Italic = true, Underline = false }, ForeColor = new Color() { Web = "#364E6F" }, Height = 80, HorizontalAlignment = SignTextOptionsData.HorizontalAlignmentEnum.Right, Left = 10, LocationMeasureType = SignTextOptionsData.LocationMeasureTypeEnum.Pixels, Margin = new PaddingData() { Left = 10, Right = 10, Bottom = 10, Top = 10 }, MarginMeasureType = SignTextOptionsData.MarginMeasureTypeEnum.Pixels, Opacity = 0.5, SignAllPages = false, Text = "1234567890", Top = 100, VerticalAlignment = SignTextOptionsData.VerticalAlignmentEnum.Center, Width = 100 }; var request = new PostTextRequest { Name = TestFiles.Pdf02.FileName, SignOptionsData = signOptionsData, Password = null, Folder = TestFiles.Pdf02.Folder }; var response = SignatureApi.PostText(request); Assert.IsTrue(!string.IsNullOrEmpty(response.FileName)); }
/// <summary> /// 机器人会话接口,接收文本信息,传递给后台机器人 /// </summary> /// <param name="req">参考<see cref="PostTextRequest"/></param> /// <returns>参考<see cref="PostTextResponse"/>实例</returns> public async Task <PostTextResponse> PostText(PostTextRequest req) { JsonResponseModel <PostTextResponse> rsp = null; try { var strResp = await this.InternalRequest(req, "PostText"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <PostTextResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
private async Task <string> GetIntentFromLexAsync(String customerContact) { try { AmazonLexClient lexClient = new AmazonLexClient(primaryRegion); PostTextRequest textRequest = new PostTextRequest(); textRequest.UserId = "MailBot"; textRequest.BotAlias = "DEV"; textRequest.BotName = "NBC_Mailbot_Intents"; textRequest.InputText = customerContact; PostTextResponse textRespone = await lexClient.PostTextAsync(textRequest); return(textRespone.IntentName); } catch (Exception error) { await SendFailureAsync("Getting Intent", error.Message); Console.WriteLine("ERROR : GetIntentFromLexAsync : " + error.StackTrace); return("GeneralEnquiries"); } }
async void SendMessage(object sender, EventArgs e) { try { listView.BeginRefresh(); PostTextRequest request = new PostTextRequest(); request.BotName = "GolfNowReservation"; request.BotAlias = "GolfNowTest"; request.UserId = "250"; request.InputText = messageText.Text; var task = lexClient.PostTextAsync(request); var output = task.Result.Message; Messages.Add("Me: " + messageText.Text); if (output.Contains("CustomPayload")) { Messages.Add("GolfNow: Hello, how can I help you?"); } else { Messages.Add("GolfNow: " + output); } listView.ItemsSource = Messages.ToArray(); listView.EndRefresh(); messageText.Text = ""; } catch (Exception ee) { Messages.Add("GolfNow: Sorry I could not understand, bye!"); listView.ItemsSource = Messages.ToArray(); listView.EndRefresh(); } }
public async Task <PostTextResponse> SendTextMsgToLex(string messageToSend, string sessionId) { PostTextResponse lexTextResponse; PostTextRequest lexTextRequest = new PostTextRequest() { BotAlias = _awsOptions.LexBotAlias, BotName = _awsOptions.LexBotName, UserId = sessionId, InputText = messageToSend, SessionAttributes = _lexSessionAttribs }; try { lexTextResponse = await awsLexClient.PostTextAsync(lexTextRequest); } catch (Exception ex) { throw new BadRequestException(ex); } return(lexTextResponse); }
public virtual HttpResponseMessage PostText(PostTextRequest request) { PostTextResponse response = new PostTextResponse(); try { if (request == null) { throw new ArgumentException("Request content is invalid"); } SaveTextRequest saveTextRequest = new SaveTextRequest(); saveTextRequest.City = request.City; saveTextRequest.Text = new TextDto(); saveTextRequest.Text.Name = request.Name; saveTextRequest.Text.Value = request.Text; saveTextRequest.Text.ParentId = Convert.ToInt32(request.ParentId); SaveTextResponse saveTextResponse = _textService.SaveText(saveTextRequest); response.Data = new TextResponse(); response.Data.Text = saveTextResponse.Text.Value; response.Data.Id = saveTextResponse.Text.Id.ToString(); response.Data.ParentId = saveTextResponse.Text.ParentId.ToString(); response.Data.City = saveTextResponse.City.Name; response.Data.Lat = saveTextResponse.City.Latitude.ToString(); response.Data.Lon = saveTextResponse.City.Longitude.ToString(); response.Data.Temp = saveTextResponse.City.Temperature.ToString(); } catch (Exception ex) { response.Error = string.Format("Internal server error: {0}", ex.Message); } return(Request.CreateResponse(HttpStatusCode.OK, response)); }
public async Task <PostTextResponse> PostTextAsync(PostTextRequest request, CancellationToken cancellationToken) { await this.ProcessRequestAsync(request).ConfigureAwait(false); return(this.Get <PostTextResponse>()); }
public Task <PostTextResponse> PostTextAsync(PostTextRequest request, CancellationToken cancellationToken) { return(RetryAsync(this.AmazonLexClient.PostTextAsync, request, cancellationToken)); }