/// <summary> /// This is the primary hander for “new” call event’s from the CIT system. /// This event is raised by the call state manager after primary translation from the base CTI event. /// This event is used to create a Search Request to the system search provider or do other “pre-search” handling /// </summary> /// <param name="sender">Call State Manager that raised this request.</param> /// <param name="e">New Event call Arguments</param> private void OnCallManagerStateNewCall(object sender, NewCallEventArgs e) { // This is how to determin if the current session has a call if (((AgentDesktopSession)localSessionManager.ActiveSession).CtiCallRefId != Guid.Empty) { // I have a call. // Do some alert or compenstation logic here. // maybe return ; } // Form a request to the customer provider to launch a customer lookup with CTI data.. CtiLookupRequest lookupRequest = new CtiLookupRequest( e.CallInfo.GetCtiCallRefId, // Internal UII Call ID this.ApplicationName, // Application Name that is raising the Lookup Request. e.CallInfo.CallType, // Type of call e.CallInfo.Ani, // Number that called me. e.CallInfo.Dnis); // Number that they called. //If you would like to add in custom properties that can be access by the search provider, use this construct // lookupRequest.AddLookupRequestItem("CUSTOMERID", GetParamFromCallState(e.UiiRefCallID, "custID")); // Now Serilize the Request and send it to the UII enviroment. string sData = GeneralFunctions.Serialize <CtiLookupRequest>(lookupRequest); // This is a custom implemented action sender that uses a threaded approach to send this request. // It is very important that you do this in a threaded manner because actions are blocking and // can slow down response to the Cti system. SendCommandParams cmd = new SendCommandParams("*", CtiLookupRequest.CTILOOKUPACTIONNAME, sData); new Thread(new ParameterizedThreadStart(SendAction)).Start(cmd); }
/// <summary> /// The Worker Thread. /// </summary> /// <param name="obj">The object.</param> private void RequestWorker(object obj) { while (true) { // Get request data HttpListenerContext httpContext = this.crmListener.GetContext(); string rawdata = ""; using (StreamReader sr = new StreamReader(httpContext.Request.InputStream)) { rawdata = sr.ReadToEnd(); } // Get Query parameters Dictionary <string, string> qParams = new Dictionary <string, string>(); List <LookupRequestItem> itemsList = new List <LookupRequestItem>(); NameValueCollection nvpQuery = HttpUtility.ParseQueryString(rawdata); nvpQuery.Add(httpContext.Request.QueryString); foreach (string s in nvpQuery.Keys) { qParams.Add(s, nvpQuery[s]); itemsList.Add(new LookupRequestItem(s, nvpQuery[s])); } // Process the request try { if (qParams["eventname"] != null || qParams["eventname"] != "") { switch (qParams["eventname"]) { case "ScreenPop": Dispatcher.Invoke(() => { CtiLookupRequest data = new CtiLookupRequest(Guid.NewGuid(), base.ApplicationName, qParams["calltype"], qParams["ani"], qParams["dnis"]); data.Items.AddRange(itemsList); base.FireRequestAction(new RequestActionEventArgs("*", CtiLookupRequest.CTILOOKUPACTIONNAME, GeneralFunctions.Serialize <CtiLookupRequest>(data))); SendResponse(httpContext, ""); } ); continue; default: if (qParams.ContainsKey("askresponse") && qParams["askresponse"].ToLower() == "true") { lock (eventDataReturn) { eventDataReturn.Add(qParams["eventname"], new HttpReturnContext(qParams["eventname"], httpContext, responseTimeout)); } Dispatcher.Invoke(() => { base.FireEvent(qParams["eventname"], qParams); }); continue; } Dispatcher.Invoke(() => { base.FireEvent(qParams["eventname"], qParams); }); break; } } } catch { // TODO: implement error logging } SendResponse(httpContext, ""); } }
//The generic listener will listen on this method when a url is hit. You can write or handle your custom //logic from this code. When a screen pop happens from the CTI clients (finesse, InContact etc.), this //method is triggered. private void RequestWorker(object obj) { while (true) { HttpListenerContext context = crmListener.GetContext(); string query = ""; using (StreamReader streamReader = new StreamReader(context.Request.InputStream)) { query = streamReader.ReadToEnd(); } string ani = string.Empty; string dnis = string.Empty; string callType = string.Empty; string direction = string.Empty; List <LookupRequestItem> list = new List <LookupRequestItem>(); NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(query); nameValueCollection.Add(context.Request.QueryString); string[] allKeys = nameValueCollection.AllKeys; foreach (string text in allKeys) { if (!string.IsNullOrEmpty(text)) { switch (text.ToLower()) { case "ani": ani = nameValueCollection[text]; //Custom Code - to remove the incoming phone number prefix "91" from the CISCO Finesse //if (ani.Length.Equals(12) && ani.Substring(0, 2).Equals("91")) if (ani.Substring(0, 2).Equals("91")) { ani = ani.Substring(2); Case incident = new Case(); //We will pass the IncidentId and the CaseTitle to the CTI replacement parameters. //We can then use these replacement parameters within USD to perform different operations //like opening a case record and creating/opening a new phone call record. Entity entityCase = incident.GetCase(ani); if (entityCase != null) { string IncidentId = Convert.ToString(entityCase.Id); list.Add(new LookupRequestItem("IncidentId", IncidentId)); if (entityCase.Contains("title")) { string caseTitle = Convert.ToString(entityCase.Attributes["title"]); list.Add(new LookupRequestItem("CaseTitle", caseTitle)); } } } // break; case "dnis": dnis = nameValueCollection[text]; break; case "type": callType = nameValueCollection[text]; break; case "direction": direction = nameValueCollection[text]; break; default: list.Add(new LookupRequestItem(text, nameValueCollection[text])); break; } } } try { if (direction.Equals("outgoing")) { } else { using (StreamWriter streamWriter = new StreamWriter(context.Response.OutputStream)) { context.Response.AddHeader("cache-control", "no-cache"); context.Response.AddHeader("pragma", "no-cache"); context.Response.AddHeader("expires", "0"); context.Response.AddHeader("expiresabsolute", "-1"); streamWriter.WriteLine("<html><head></head></html>"); streamWriter.Close(); } CtiLookupRequest ctiLookupRequest = new CtiLookupRequest(Guid.NewGuid(), base.ApplicationName, callType, ani, dnis); ctiLookupRequest.Items.AddRange(list); FireRequestAction(new RequestActionEventArgs("*", CtiLookupRequest.CTILOOKUPACTIONNAME, GeneralFunctions.Serialize(ctiLookupRequest))); } } catch { } try { //CtiLookupRequest ctiLookupRequest = new CtiLookupRequest(Guid.NewGuid(), base.ApplicationName, callType, ani, dnis); //ctiLookupRequest.Items.AddRange(list); //FireRequestAction(new RequestActionEventArgs("*", CtiLookupRequest.CTILOOKUPACTIONNAME, GeneralFunctions.Serialize(ctiLookupRequest))); } catch { } } }