/// <summary> /// This event is fired after the user pauses, typically at the end of a sentence. The full recognized string is returned here. /// </summary> /// <param name="text">The text that was heard by the recognizer.</param> /// <param name="confidence">A representation of how confident (rejected, low, medium, high) the recognizer is of this recognition.</param> private async void DictationRecognizer_DictationResult(string text, ConfidenceLevel confidence) { StopRecording(); // Append textSoFar with latest text textSoFar.Append(text + ". "); string msg = text; string result = "I'm sorry, I'm not sure how to answer that"; if (await tmsBot.SendMessage(msg)) { ConversationMessages messages = await tmsBot.GetMessages(); for (int i = 1; i < messages.messages.Length; i++) { result = messages.messages[i].text; } } //animator.Play("Happy"); MyTTS.SpeakText(result); // Set DictationDisplay text to be textSoFar //DictationDisplay.text = textSoFar.ToString(); }
private void ForwardToCorrectConversation(ConversationMessages.IncomingChatMessage msg) { if (_conversations.ContainsKey(msg.ConversationId)) { _conversations[msg.ConversationId].Tell(msg); } }
public async Task <PhraseServiceModel> GetPhrase(string messageToSent) { PhraseServiceModel phraseResponse = new PhraseServiceModel { Content = string.Empty }; try { StartConversationResponse conversationStart = await directLineClientService.StartConversationAsync(); await directLineClientService.SendMessageAsync(conversationStart.ConversationId, messageToSent); ConversationMessages conversationMessages = await directLineClientService.GetMessagesAsync(conversationStart.ConversationId, ""); var content = new StringBuilder(); foreach (Message messageFromBot in conversationMessages.Messages) { if (messageFromBot.Text != null && messageFromBot.Text != messageToSent) { content.AppendLine(messageFromBot.Text); } } phraseResponse.Content = content.ToString(); } catch (Exception e) { phraseResponse.Content = "¿No le he entendido, por favor podría repetir la pregunta?"; } return(phraseResponse); }
public ConversationViewModelActor(ConversationMessages.ConversationStarted conversationMetadata) { _conversationMetadata = conversationMetadata; Receive<AssociateWithViewModel>(msg => AssociateAndSetParticipants(msg)); Receive<ConversationMessages.OutgoingChatMessage>(msg => HandleOutgoingMessage(msg)); Receive<ConversationMessages.IncomingChatMessage>(msg => HandleIncomingMessage(msg)); Receive<ClientsActor.ClientStatusQueryResponse>(msg => UpdateClientList(msg)); Context.ActorSelection(ClientActorPaths.ClientsActor.Path).Tell(new ClientsActor.ClientStatusQuery(conversationMetadata.Clients)); Receive<ClientTracking.ClientChanged>( change => { var participant = _viewModel.Participants.FirstOrDefault(p => p.Id == change.Client.ClientId); if (participant != null) participant.Status = change.Client.Status; }); Receive<ClientTracking.ClientConnected>( connect => { var participant = _viewModel.Participants.FirstOrDefault(p => p.Id == connect.Client.ClientId); if (participant != null) participant.Status = connect.Client.Status; }); Receive<ClientTracking.ClientDisconnected>( disconect => { var participant = _viewModel.Participants.FirstOrDefault(p => p.Id == disconect.Client.ClientId); if (participant != null) participant.Status = ClientStatus.Offline; }); }
private void ForwardToConversations(ConversationMessages.IncomingChatMessage msg) { if (_conversationsVMActor == null) { _conversationsVMActor = Context.ActorSelection(ClientActorPaths.ConversationsViewModelActor.Path) .ResolveOne(TimeSpan.FromSeconds(1)).Result; } _conversationsVMActor.Tell(msg); }
private void OpenConversation(ConversationMessages.ConversationStarted msg) { if (_conversationsVMActor == null) { _conversationsVMActor = Context.ActorSelection(ClientActorPaths.ConversationsViewModelActor.Path) .ResolveOne(TimeSpan.FromSeconds(1)).Result; } _conversationsVMActor.Tell(msg); }
private void BroadcastChatMessage(ConversationMessages.OutgoingChatMessage msg) { _messageHistory.Add(new ConversationMessage(msg.SenderId, msg.Message)); var incomingChatMessage = new ConversationMessages.IncomingChatMessage(this._conversationId, msg.Message, msg.SenderId); foreach (var participant in _participants) { participant.MessagingHandler.Tell(incomingChatMessage); } }
private void HandleIncomingMessage(ConversationMessages.IncomingChatMessage msg) { _viewModel.ReceiveMessage(new ConversationViewModel.ReceivedMessage() { Message = msg.Message, UserName = _participants.FirstOrDefault(p => p.ClientId == msg.SenderId)?.Username ?? "Unknown" }); if (!_viewModel.IsActive) { Context.ActorSelection(ClientActorPaths.NotifierActor.Path).Tell(new NotificationActor.NotifyUser()); } }
public IHttpActionResult AddMessage([FromBody] ConversationMessages m) { try { m.Date = DateTime.Now; db.ConversationMessages.Add(m); db.SaveChanges(); db.ConversationMessagesView.Where(x => x.Id == m.Id).FirstOrDefault(); return(Json(m)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task <ActionResult <CustomerIpInformation> > InsertCustomerIpInformation(int widget_id, int customerId, CustomerIpInformation customerIpInformation) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } string curURL = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}"; // string ip = Response.HttpContext.Connection.RemoteIpAddress.ToString(); // string externalIP; // externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/"); // externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) // .Matches(externalIP)[0].ToString(); // if (ip == "::1") // { // ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList[1].ToString(); // ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToString(); // } var widget = await _context.Widgets.FindAsync(widget_id); var customerIpInformations = new CustomerIpInformation(); var conversationMessage = new ConversationMessages(); if (widget != null) { customerIpInformations.HttpURL = customerIpInformation.HttpURL; customerIpInformations.ClientIp = customerIpInformation.ClientIp; // externalIP; customerIpInformations.CustomerId = customerId; customerIpInformations.CreatedTimeUTC = DateTime.UtcNow; customerIpInformations.HttpReferrer = customerIpInformation.HttpURL; _context.CustomerIpInformation.Add(customerIpInformations); await _context.SaveChangesAsync(); return(Ok(customerIpInformations)); } else { return(BadRequest("No such widget")); } }
private void OpenOrFocusWindow(ConversationMessages.ConversationStarted msg) { if (!_conversations.ContainsKey(msg.ConversationId)) { IActorRef conversationActor = Context.ActorOf(Props.Create(() => new ConversationViewModelActor(msg)), msg.ConversationId.ToString()); var newConversation = new ConversationViewModel(conversationActor, msg.ConversationId) { DisplayName = $"#{_conversations.Count+1}" }; _viewModel.AddConversation(newConversation); _conversations.Add(msg.ConversationId, conversationActor); } _viewModel.FocusConversation(msg.ConversationId); Context.ActorSelection(ClientActorPaths.NotifierActor.Path).Tell(new NotificationActor.NotifyUser()); }
// This event handler's code only works in UWP (i.e. HoloLens) #if WINDOWS_UWP /// <summary> /// This event is fired after the user pauses, typically at the end of a sentence. The full recognized string is returned here. /// </summary> /// <param name="text">The text that was heard by the recognizer.</param> /// <param name="confidence">A representation of how confident (rejected, low, medium, high) the recognizer is of this recognition.</param> private async void DictationRecognizer_DictationResult(string text, ConfidenceLevel confidence) { StopRecording(); // Append textSoFar with latest text textSoFar.Append(text); // Set DictationDisplay text to be textSoFar //DictationDisplay.text = textSoFar.ToString(); UnityEngine.WSA.Application.InvokeOnAppThread(() => { // Display captions for the question captionsManager.SetCaptionsText(text); }, false); string msg = text; string result = "I'm sorry, I'm not sure how to answer that"; if (await tmsBot.SendMessage(msg)) { ConversationMessages messages = await tmsBot.GetMessages(); for (int i = 1; i < messages.messages.Length; i++) { result = messages.messages[i].text; } } //animator.Play("Happy"); MyTTS.SpeakText(result); UnityEngine.WSA.Application.InvokeOnAppThread(() => { // Display captions for the question captionsManager.SetCaptionsText(result); }, false); }
private void HandleOutgoingMessage(ConversationMessages.OutgoingChatMessage msg) { if(_messagingActor == null) { _messagingActor = Context.ActorSelection(ClientActorPaths.ChatMessageRouter.Path) .ResolveOne(TimeSpan.FromSeconds(1)) .Result; } _messagingActor.Tell(msg, Self); }
private void RouteChatMessage(ConversationMessages.OutgoingChatMessage msg) { if (_conversations.ContainsKey(msg.ConversationId)) { _conversations[msg.ConversationId].Tell(msg); } else { //todo: log and sender tell error message } }
private void HandleConversationRequest(ConversationMessages.ConversationRequest msg) { _serverMessagingActor.Tell(msg); }
private void ForwardToServerMessager(ConversationMessages.OutgoingChatMessage msg) { _serverMessagingActor.Tell(msg); }
private void CreateConversation(ConversationMessages.ConversationRequest msg) { IEnumerable<ConversationParticipant> participants = msg.Clients.Select(id => new ConversationParticipant(id, _handlers[id].Handler)).ToList(); var request = new ConversationCoordinatorActor.StartConversation(participants); _conversationCoordinator.Tell(request); }
private void HandleConversationRequest(ConversationMessages.ConversationRequest msg) { ForwardToMessenger(msg); }
public async Task PostAsync([FromBody] JObject MessageJobj) { bool outgoing; string ChannelUUId = ""; string SocketPublishUrl = _configuration.GetValue <string>("RequestUrls:WebSocketPublish"); string MdeiaType = "0"; LogProperties.info("Whats api called"); try { outgoing = (bool)MessageJobj["outgoing"]; // "sender": "919966226645", //"recipient": "2df4b63c-135a-4206-91d3-8132dfe64f22", if (!outgoing) { ChannelUUId = Convert.ToString(MessageJobj["recipient"]); } WidgetChannels widgetChannel = null; Widgets widget = null; try { widgetChannel = _context.WidgetChannels.Where(wc => wc.ChanneUUID == ChannelUUId && wc.ConversationTypeId == 2).FirstOrDefault(); LogProperties.info("widgetChannel for message: " + widgetChannel.WidgetId); widget = _context.Widgets.Where(w => w.Id == widgetChannel.WidgetId).FirstOrDefault(); LogProperties.info("widget for message: " + widgetChannel.WidgetId); } catch (Exception dbEx) { widgetChannel = _context.WidgetChannels.Where(wc => wc.Id == 2).FirstOrDefault(); LogProperties.info("widgetChannel for message catch: " + widgetChannel.WidgetId); widget = _context.Widgets.Where(w => w.Id == 6).FirstOrDefault(); LogProperties.info("widget for message catch: " + widget.Id); } // var widgetChannel = _context.WidgetChannels.Where(wc => wc.ChanneUUID == ChannelUUId && wc.ConversationTypeId == 2).FirstOrDefault(); // LogProperties.info("widgetChannel for message: " + widgetChannel.WidgetId ); //[HttpPost("{account_id}/widgets/{widget_id}/conversations/{conversation_id}/{is_endchat}/replies")] if (widget != null) { if (!outgoing) { JObject jObject = new JObject(); jObject = JObject.Parse(MessageJobj.ToString()); // await ProcessIncomingMessageAsync(widget, MessageJobj); LogProperties.info("Whats api ougoing enter"); string CustomerMobile = ""; string CustomerName = ""; string CustomerProfileImage = ""; int AccountId = widget.AccountId; int WidgetId = widget.Id; int ConverstationId = 0; long ConverstationMessageId = 0; int CustomerId = 0; JObject CustJobj = new JObject(); CustomerMobile = Convert.ToString(MessageJobj["sender"]); ChannelUUId = Convert.ToString(MessageJobj["recipient"]); CustomerName = Convert.ToString(MessageJobj["payload"]["user"]["name"]); CustomerProfileImage = Convert.ToString(MessageJobj["payload"]["user"]["image"]); ConversationsController conController = new ConversationsController(_context, _configuration); CustJobj = GetCustomerId(AccountId, CustomerName, CustomerMobile, CustomerProfileImage); CustomerId = Convert.ToBoolean(CustJobj["Success"]) ? Convert.ToInt32(CustJobj["CustomerId"]) : -1; LogProperties.info("Whats api after get customer"); var PrevConverstations = (from Con in _context.Conversations where Con.WidgetId == WidgetId && Con.CustomerId == CustomerId orderby Con.Id descending select new { Con.Id, Con.AgentId }).FirstOrDefault(); if (PrevConverstations != null) { ConverstationId = PrevConverstations.Id; } LogProperties.info("Whats api after Conversations"); var PrevConMessages = (from ConMess in _context.ConversationMessages where ConMess.ConversationId == ConverstationId orderby ConMess.Id descending select new { ConMess.Id, ConMess.CreatedTimeUTC, ConMess.AgentId }).FirstOrDefault(); DateTime RecentMsgTime; if (PrevConMessages != null && PrevConMessages.Id > 0) { ConverstationMessageId = PrevConMessages.Id; RecentMsgTime = PrevConMessages.CreatedTimeUTC; } else { RecentMsgTime = DateTime.Today.AddDays(-10); } LogProperties.info("Whats api after Conversation messages"); DateTime CurrentUtcNow = DateTime.UtcNow; TimeSpan MessageSpan = CurrentUtcNow - RecentMsgTime; double totalSecForDay = 3 * 60 * 60; // Static condiftion bool IsNewChat = false; if (MessageSpan.TotalSeconds > totalSecForDay) // create new conversations after 24 hours { Conversations conversations = new Conversations() { StatusId = 1, CustomerId = CustomerId, Mobile = CustomerMobile, ConversationTypeId = 2 }; ActionResult <Conversations> newCon = await conController.PostConversations(AccountId, WidgetId, conversations); // JObject Con = await CreateConversation(AccountId, WidgetId, conversations); OkObjectResult okResult = newCon.Result as OkObjectResult; if (okResult.StatusCode == 200) { Conversations NewConversation = okResult.Value as Conversations; ConverstationId = NewConversation.Id; } IsNewChat = true; } LogProperties.info("Whats api after Conversation save"); ConversationMessages conversationMessages = new ConversationMessages(); int IsBotEnd = 0; //"MessageTypeId": "1", // "Message":msg conversationMessages.ConversationId = ConverstationId; conversationMessages.MessageTypeId = 1; conversationMessages.ConversationTypeId = 2; if (IsNewChat == false) { conversationMessages.AgentId = PrevConverstations.AgentId; } //message payload table conversationMessages.Message = Convert.ToString(MessageJobj["payload"]["text"]); string CustomerMessage = Convert.ToString(MessageJobj["payload"]["text"]); string MessageType = Convert.ToString(MessageJobj["payload"]["type"]); if (MessageType != "text") { //attachment conversationMessages.AttachmentUrl = Convert.ToString(MessageJobj["payload"]["attachment"]); conversationMessages.Message = ConstructMediaMessage(conversationMessages.AttachmentUrl, MessageType, conversationMessages.Message, ref MdeiaType); } var ConInfo = _context.ConversationInfo.Where(w => w.ConversationId == ConverstationId).FirstOrDefault(); if (ConInfo != null) { IsBotEnd = ConInfo.IsBotEnd; } if (IsBotEnd > 0) { conversationMessages.MessageTypeId = 3; } ActionResult <ConversationMessages> newConMsg = await conController.PostConversationMessages(AccountId, WidgetId, ConverstationId, IsBotEnd, conversationMessages); OkObjectResult okResultMesg = newConMsg.Result as OkObjectResult; if (okResultMesg.StatusCode == 200) { ConversationMessages NewConvMsg = okResultMesg.Value as ConversationMessages; } LogProperties.info("Whats api after Conversation message save"); if (IsBotEnd > 0) { // table for botend //if (IsPingAgent == "true") //{ // cust_jsonObj = { "conversationId": conversationId, "from": conversationId, "to": agentId, "messageType": "0", "message": "Customer OnBoard" }; //} //else //{ // cust_jsonObj = { "conversationId": conversationId, "from": fromId, "to": agentId, "messageType": "0", "message": "Customer OnBoard" }; //} if (IsNewChat == false && IsBotEnd > 0) // send message to agent through socket { //JObject jobj = new JObject(); //jobj.Add(new JProperty("conversationId", conversationMessages.ConversationId)); //jobj.Add(new JProperty("from", "WhatsApp_"+ conversationMessages.ConversationId)); //jobj.Add(new JProperty("to", "Hub_" + conversationMessages.AgentId)); //jobj.Add(new JProperty("message", conversationMessages.Message)); //jobj.Add(new JProperty("messageType", "0")); //WebSocketSubscriber.Send(jobj); JObject jobjs = new JObject(); JObject wsMessageObj = new JObject(); JObject CustomerDetails = new JObject(); // "data":{"fromName" :"" ,"fromMobile",""} CustomerDetails.Add(new JProperty("fromName", CustomerName)); CustomerDetails.Add(new JProperty("fromMobile", CustomerMobile)); jobjs.Add(new JProperty("conversationId", Convert.ToString(ConverstationId))); jobjs.Add(new JProperty("from", "WhatsApp_5f2d3a8e31197a445686653b")); jobjs.Add(new JProperty("to", "Hub_" + PrevConverstations.AgentId)); jobjs.Add(new JProperty("message", CustomerMessage)); jobjs.Add(new JProperty("mediaUrl", conversationMessages.AttachmentUrl)); jobjs.Add(new JProperty("type", MdeiaType)); jobjs.Add(new JProperty("data", CustomerDetails)); jobjs.Add(new JProperty("messageType", "0")); jobjs.Add(new JProperty("ConversationTypeId", 2)); wsMessageObj = new JObject(new JProperty("Module", "Chat"), new JProperty("Event", "NewChat"), new JProperty("Channel_Name", "WhatsApp_Hub_" + PrevConverstations.AgentId), new JProperty("Data", jobjs)); // WebSocketSubscriber wb = new WebSocketSubscriber(); WebSocketSubscriber.pushSocket(SocketPublishUrl, wsMessageObj); LogProperties.info("Whats api after websocket publish"); } } } } } catch (Exception ex) { LogProperties.error("expection at WhatsApp Handler: " + ex.ToString()); } }