private void setupCommands() { SendMsgToChat = new Command(() => { if (this._nikName == null) { MessageBox.Show("Select User to send " + userMsg); return; } ChatLogModel.getInstance().addMsgToChat(_nikName, "You", userMsg); string[] words = userMsg.Split(); foreach (string word in words) { ObservableCollection <string> Answers = ChatBot.ChatBotModel.getInstance().getAnswers(word); if (Answers.Count < 1) { ChatLogModel.getInstance().addMsgToChat(_nikName, _nikName, "Ура!!!"); } else { ChatLogModel.getInstance().addMsgToChat(_nikName, _nikName, Answers[1]); } } Chat = ChatLogModel.getInstance().getChat(_nikName); OnPropertyChanged(nameof(Chat)); userMsg = ""; OnPropertyChanged(nameof(userMsg)); }); }
public void _01_CreateChatLogs() { var session = CrmSession.CreateDefault(); var service = new TokenService(); var authResult = service.GetAccessToken(session); Assert.IsFalse(string.IsNullOrEmpty(authResult.AccessToken)); var chatLog = new ChatLogModel { SessionId = "session id xxxx", Log = @"再多教它一些东西 通过对话模板让技能模型学习用户意图的多种表达方式 也可尽量多地告诉它用户的真实问句(对话样本),同时标出用户的意图和实现意图的关键信息 对话模型就像个儿童,您教得越多,它越能领会您的意思,而且还能举一反三呢~ 这部分在【效果优化--训练数据】里完成", Tags = "100000000,100000001,100000002,100000003", //LeadIdOdataBind = createdLeadGuid }; var chatLogService = new ChatLogService(); chatLogService.CreateChatLog(chatLog, session); Assert.IsFalse(string.IsNullOrEmpty(chatLog.CreatedChatLogGuid)); }
private Task Bot_MessageReceived( SocketMessage arg) { lock (this.LogIDHistory) { if (this.LogIDHistory.Contains(arg.Id)) { return(Task.CompletedTask); } this.LogIDHistory.Add(arg.Id); } var activeChannels = this.GetActiveChannels(); if (activeChannels == null) { return(Task.CompletedTask); } var ch = activeChannels .FirstOrDefault(x => x.DiscordChannelID == arg.Channel.Id.ToString()); if (ch == null) { return(Task.CompletedTask); } var model = ChatLogModel.FromDiscordLog(arg); model.ChatCode = ch.ChatCode; model.IsMe = string.Equals( model.OriginalSpeaker, SharlayanController.Instance.CurrentPlayer?.Name, StringComparison.OrdinalIgnoreCase); if (!model.IsMe || model.DiscordLog.Attachments.Any()) { WPFHelper.Dispatcher.Invoke(() => { ChatLogsModel.AddToBuffers(model); }); var chName = !string.IsNullOrEmpty(ch.ChannelShortName) ? ch.ChannelShortName : ch.ChannelName; ChatLogger.Write( chName, model.Speaker, model.SpeakerAlias, model.Message); } return(Task.CompletedTask); }
public ChatLogModel SaveChatlog(string sessionId, string log, string[] tags, string leadId = null) { var chatLog = new ChatLogModel { SessionId = sessionId, Log = log, Tags = GetTagKeys(tags), LeadIdOdataBind = string.IsNullOrEmpty(leadId) ? null: string.Format($"leads({leadId})") }; _session.AuthenticationResult = Connect(); var chatLogService = new ChatLogService(); chatLogService.CreateChatLog(chatLog, _session); return(chatLog); }
public void CreateChatLog(ChatLogModel chatLog, CrmSession session) { var chatLogUrl = "https://saxohack.api.crm11.dynamics.com/api/data/v9.1/new_chatlogs"; var client = GetClient(session); var chatLogString = JsonConvert.SerializeObject(chatLog, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var chatLogJsonContent = new StringContent(chatLogString, Encoding.UTF8, "application/json"); var createChatLogResponse = client.PostAsync(chatLogUrl, chatLogJsonContent).Result; var msg = createChatLogResponse.Content.ReadAsStringAsync().Result; try { createChatLogResponse.EnsureSuccessStatusCode(); chatLog.CreatedChatLogGuid = createChatLogResponse.Headers.TryGetValues("OData-EntityId", out var chatLogCreationheaders) ? chatLogCreationheaders.FirstOrDefault() : null; } catch (Exception ex) { throw new Exception(msg, ex); } }
private void SubscribeChatLog() { Thread.Sleep(TimeSpan.FromSeconds(DetectProcessInterval)); AppLogger.Write("FFXIV chat log subscriber started."); var previousPlayerName = string.Empty; while (true) { var interval = TimeSpan.FromMilliseconds(Config.Instance.ChatLogPollingInterval); var isExistLogs = false; try { // スレッドプライオリティを更新する if (Thread.CurrentThread.Priority != Config.Instance.ChatLogSubscriberThreadPriority) { Thread.CurrentThread.Priority = Config.Instance.ChatLogSubscriberThreadPriority; } if (!this.IsAttached || !Reader.CanGetChatLog()) { interval = TimeSpan.FromSeconds(DetectProcessInterval); continue; } var targetLogs = default(IEnumerable <ChatLogItem>); try { if (this.isWorking) { continue; } this.isWorking = true; if (this.currentPlayer != null && !string.IsNullOrEmpty(this.currentPlayer.Name)) { if (!string.IsNullOrEmpty(previousPlayerName) && previousPlayerName != this.currentPlayer.Name) { this.previousArrayIndex = 0; this.previousOffset = 0; } previousPlayerName = this.CurrentPlayer.Name; } var result = Reader.GetChatLog(this.previousArrayIndex, this.previousOffset); if (result == null) { continue; } this.previousArrayIndex = result.PreviousArrayIndex; this.previousOffset = result.PreviousOffset; if (!result.ChatLogItems.Any()) { continue; } targetLogs = result.ChatLogItems .Where(x => ChatCodes.All.Contains(x.Code)); isExistLogs = targetLogs.Any(); } finally { this.isWorking = false; } if (isExistLogs) { var models = targetLogs .Select(x => ChatLogModel.FromXIVLog(x, this.currentPlayerNames)) .ToArray(); WPFHelper.Dispatcher.Invoke(() => { ChatLogsModel.AddToBuffers(models); }); foreach (var model in models) { if (model.IsMe) { var playerName = this.currentPlayer?.Name; if (string.IsNullOrEmpty(playerName)) { playerName = previousPlayerName; if (string.IsNullOrEmpty(playerName)) { playerName = Config.Instance.ActiveProfile?.CharacterName; } } DiscordBotController.Instance.SendMessage( model.ChatCode, playerName, Config.Instance.ActiveProfile?.Alias, model.Message); } var chName = !string.IsNullOrEmpty(model.ChannelShortName) ? model.ChannelShortName : model.ChannelName; ChatLogger.Write( chName, model.Speaker, model.SpeakerAlias, model.Message); } } } catch (ThreadAbortException) { return; } catch (Exception ex) { AppLogger.Error("Happened exception from chat log subscriber.", ex); interval = TimeSpan.FromSeconds(DetectProcessInterval * 2); } finally { var now = DateTime.Now; if (isExistLogs) { this.lastChatLogReceivedTimestamp = now; Thread.Yield(); } else { if ((now - this.lastChatLogReceivedTimestamp) > ChatIdelThreshold) { interval = ChatIdleInterval; } Thread.Sleep(interval); } } } }
private void setupCommands() { SendMsgToChat = new Command(() => { if (this._correspondenceNickName == null) { MessageBox.Show("Select User to send meesage"); return; } ChatLogModel.getInstance().addMessageToLog(_correspondenceNickName, "It's me", userMsg); if (userMsg != "") { string[] words = userMsg.Split(); foreach (string word in words) { // TODO доработать логику выбора ответа ObservableCollection <string> Answers = ChatBotModel.getInstance().getAnswers(word); if (Answers.Count < 1) { ChatLogModel.getInstance().addMessageToLog(_correspondenceNickName, _correspondenceNickName, "Я тебя не понимаю, напиши что-то годное!"); } else { ChatLogModel.getInstance().addMessageToLog(_correspondenceNickName, _correspondenceNickName, Answers[1]); } } chatList = ChatLogModel.getInstance().getChat(_correspondenceNickName); OnPropertyChanged(nameof(chatList)); userMsg = ""; OnPropertyChanged(nameof(userMsg)); } }); keyPress = new Command(() => { if (this._correspondenceNickName == null) { MessageBox.Show("Select User to send meesage"); return; } ChatLogModel.getInstance().addMessageToLog(_correspondenceNickName, "It's me", userMsg); if (userMsg != "") { string[] words = userMsg.Split(); foreach (string word in words) { // TODO доработать логику выбора ответа ObservableCollection <string> Answers = ChatBotModel.getInstance().getAnswers(word); if (Answers.Count < 1) { ChatLogModel.getInstance().addMessageToLog(_correspondenceNickName, _correspondenceNickName, "Я тебя не понимаю, напиши что-то годное!"); } else { ChatLogModel.getInstance().addMessageToLog(_correspondenceNickName, _correspondenceNickName, Answers[1]); } } chatList = ChatLogModel.getInstance().getChat(_correspondenceNickName); OnPropertyChanged(nameof(chatList)); userMsg = ""; OnPropertyChanged(nameof(userMsg)); } }); }