Get Chat Visitors and Operators Information in ASP.NET Application with Banckle.Chat for Cloud API
This article explains how to develop a simple application to get Banckle Chat Visitors’ information using Banckle.Chat for Cloud API. Our basic purpose of this article is to explain how easily anyone can work with Banckle Cloud APIs in their ASP.NET applications.
This application gives a working solution of how to get the visitors and operators information using Banckle.Chat for Cloud API. The application is developed using ASP.NET and we will get the details regarding online visitors, visitors in queue and details of operators by using a valid API Key and Authorized Token. Following is the screenshot of the simple GUI of the application.
Get Authorized Token
As per the prerequisites, we need to provide a valid key and to get the authorization token we will pass the email address and password as shown in the above picture to work with Banckle.Chat for Cloud API.
Following method is used to get the authorized token based on the email address and password:
protected void Get_Authorized_Token()
// Create JSON object to be sent
JObject request_json = new JObject();
request_json.Add("userEmail", new JValue(txtEmail.Text));
request_json.Add("password", new JValue(txtPassword.Text));
string request_body = request_json.ToString();
string request_url = "https://apps.banckle.com/api/v2/auth/token";
// Create request object
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(request_url));
// Add custom headers for authentication
// request.Headers.Add("X-Resource", session_resource);
// Set request parameters
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = request_body.Length;
// Add the required JSON to request object
StreamWriter request_writer = new StreamWriter(request.GetRequestStream());
// Retrieve response object
WebResponse response = request.GetResponse();
Stream response_stream = response.GetResponseStream();
// Fetch response as string
string response_body = new StreamReader(response_stream).ReadToEnd();
// Close response stream to release resources
// Parse response as JSON object
JObject response_json = JObject.Parse(response_body);
auth_token = response_json["authorization"]["token"].ToString();
Create New Session
After providing a valid key and getting an authorized token, a new session is created which is used to get the information from Cloud. We need to pass a valid token to get the session information. Following method is used to get the session resource:
As you can see, we are getting the JSON response and then we are deserializing the response (using simple VisitorsResponse class) and binding the data with our first grid view control to display Online Visitors information.
Get Queued Visitors' Information
After getting the details of online visitors, now we will use the API call to get the visitors who are in queue. For that, we have used the following method:
In the above method we get the information for both online and offline operators. We have used the OperatorsResponse class to get the deserialized response of JSON and bound the data with our third grid view control.
That's it, by using these simple Banckle.Chat for Cloud API calls; we are able to get the detailed information of visitors and operators. We have only displayed a limited information regarding visitors to keep the application simple. You can easily modify the VisitorsResponse class to get more detailed information e.g. City, State, Time Zone, Last Accessed time etc. as required.
Complete source code and the working sample is available at Codeplex. You can simply download the application; provide a valid token and API Key and press "Get Info" button to get the information regarding your visitors and operators.