Exemple #1
0
        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);
        }
Exemple #2
0
        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> 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);
        }
Exemple #4
0
        public string PostText(string text, string mentionName)
        {
            var result = _lex.PostTextAsync(new PostTextRequest
            {
                BotName           = "QuoteBotDispute",
                BotAlias          = "Initial",
                InputText         = text,
                UserId            = mentionName + mentionName,
                SessionAttributes = { ["mentionName"] = mentionName }
            }).Result;

            if (result.DialogState == DialogState.ReadyForFulfillment)
            {
                return(_dataService.DeleteQuote(result.SessionAttributes["quotee"], result.SessionAttributes["quote"])
                    ? "Quote deleted." : "Problem deleting from database.");
            }
            else
            {
                return(result.Message);
            }
        }
        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");
            }
        }
Exemple #6
0
        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);
        }