public void _01_ShouldGetToken() { var service = new TokenService(); var authResult = service.GetAccessToken(CrmSession.CreateDefault()); Assert.IsFalse(string.IsNullOrEmpty(authResult.AccessToken)); }
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)); }
public CrmService(TokenService tokenService, LeadService leadService, ChatLogService chatlogService, CrmSession session) { _tokenService = tokenService; _chatLogService = chatlogService; _leadService = leadService; _session = session; _session.AuthenticationResult = Connect(); }
public LeadModel[] GetLeads(CrmSession session) { var client = GetClient(session); var leadUrl = "https://saxohack.api.crm11.dynamics.com/api/data/v9.1/leads"; var getLeadsResponse = client.GetAsync(leadUrl).Result; var leadListRawJsonString = getLeadsResponse.Content.ReadAsStringAsync().Result; var leads = JsonConvert.DeserializeObject <RootObject <LeadModel> >(leadListRawJsonString).Value; return(leads); }
public void _01_ShouldGetLeads() { var session = CrmSession.CreateDefault(); var service = new TokenService(); var authResult = service.GetAccessToken(session); Assert.IsFalse(string.IsNullOrEmpty(authResult.AccessToken)); var leadService = new LeadService(); var leads = leadService.GetLeads(session); Assert.IsTrue(leads.Count() > 0); }
public void CreateLead(LeadModel lead, CrmSession session) { var leadUrl = "https://saxohack.api.crm11.dynamics.com/api/data/v9.1/leads"; var client = GetClient(session); var leadString = JsonConvert.SerializeObject(lead, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); HttpContent leadJsonContent = new StringContent(leadString, Encoding.UTF8, "application/json"); var createLeadResponse = client.PostAsync(leadUrl, leadJsonContent).Result; lead.CreatedLeadGuid = createLeadResponse.Headers.Location.Segments[4]; lead.LeadId = lead.CreatedLeadGuid.Substring(4, lead.CreatedLeadGuid.Length - 6); }
public AuthenticationResult GetAccessToken(CrmSession session) { try { var clientCredential = new ClientCredential(session.ApplicationId, session.ClientSecret); var authenticationContext = new AuthenticationContext($"{session.AadInstanceUrl}/{session.TenantId}"); var authenticationResult = authenticationContext.AcquireTokenAsync(session.OrganizationUrl, clientCredential).Result; session.AuthenticationResult = authenticationResult; return(authenticationResult); } catch (Exception ex) { throw ex; } }
public static void RegisterComponents(BaiduSession baiduSession, bool isInternal) { var container = new UnityContainer(); var chatSessions = new ChatLogCache(); var crmSession = CrmSession.CreateDefault(isInternal); container.RegisterInstance(crmSession); container.RegisterInstance(baiduSession, InstanceLifetime.Singleton); container.RegisterInstance(chatSessions, InstanceLifetime.Singleton); container.RegisterType <ChatService>(); container.RegisterType <RobotService>(); container.RegisterType <TokenService>(); container.RegisterType <ChatLogService>(); container.RegisterType <LeadService>(); container.RegisterType <CrmService>(); GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container); }
public void _02_CreateLeads() { var session = CrmSession.CreateDefault(); var service = new TokenService(); var authResult = service.GetAccessToken(session); Assert.IsFalse(string.IsNullOrEmpty(authResult.AccessToken)); var lead = new LeadModel { Firstname = "Morten", Lastname = "Stanley", Emailaddress1 = "*****@*****.**", Mobilephone = "13917163120", Telephone1 = "8485000" }; var leadService = new LeadService(); leadService.CreateLead(lead, session); Assert.IsFalse(string.IsNullOrEmpty(lead.CreatedLeadGuid)); }
private HttpClient GetClient(CrmSession session) { HttpClient client; if (!session.IsInternal) { client = new HttpClient(); } else { client = new HttpClient(new HttpClientHandler() { Proxy = new WebProxy("http://sg.pachost.mid.dom") { UseDefaultCredentials = true } }); } client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", session.AuthenticationResult.AccessToken); return(client); }
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); } }