This technical tip will show you how to get online and queued chat visitors and operators information for Banckle users using Banckle.Chat for Cloud API and developers can embed this functionality in their own .NET application very easily.

The new blog post from Banckle explains how .NET developers can get online chat visitors information and queued chat visitors information along with the chat operators’ information using Banckle.Chat for Cloud API. Developers can easily embed this functionality in their own .NET application and can easily modify the VisitorsResponse class to get more detailed information e.g. City, State, Time Zone, Last Accessed time etc. as required.

Prerequisites

You can easily access Banckle.Chat APIby using Swagger API Explorer.

In order to use Swagger API Explorer, you must have:

  1. A valid Banckle Account. Create new Banckle account
  2. A valid Banckle API key. You will get API key from your Dashboard after successful login
  3. A Valid Banckle Authorize Token which you can get from this URL 
  4. Get permission to access Banckle.Chat API Service. See Create New Session for more information.

Application Details

This application is developed in ASP.NET and will you a solution of how to get the details regarding online visitors, visitors in queue and details of operators by using a valid API Key and Authorized Token. You can get API Key from your application dashboard once you have logged in and below is the code to get authorized token using the combination of your username and password.

Get Authorized Token

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("banckle-client-api-key", api_key);

    // 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());

    request_writer.Write(request_body);

    request_writer.Close();

    // 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

    response_stream.Close();

    // 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. Below is the code to create new session by passing authorized token in request url.

protected string Generate_Session()
{
 
    string request_url = "http://chat.banckle.com/v3/connect?token=" + auth_token;
 
    // Create request object
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(request_url));
    // Add custom headers for authentication
    request.Headers.Add("banckle-client-api-key", api_key);
 
    // 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
    response_stream.Close();
 
    // Parse response as JSON array
    JObject session = JObject.Parse(response_body);
    // Fetch session resource from JSON response
    string resource = session["return"]["resource"].ToString();
    return resource;
 
}

Get Online Visitors' Information

After creating new session you are ready to use Banckle Cloud API and to get online visitors information see the .NET code given below.

protected void Get_Visitors()
 {
     string request_url = "https://chat.banckle.com/v3/visitors/browsing.js";
 
     // Create request object
     WebRequest request = HttpWebRequest.Create(new Uri(request_url));
 
     // Add custom headers for authentication
     request.Headers.Add("banckle-client-api-key", api_key);
     request.Headers.Add("X-Resource", session_resource);
 
     // 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
     response_stream.Close();
 
     // Parse response as JSON object
     JObject response_json = JObject.Parse(response_body);
 
     VisitorsResponse vresp = JsonConvert.DeserializeObject<VisitorsResponse>(response_json.ToString());
 
     if (vresp.Return.Count > 0)
     {
         lblTotalV.Text = vresp.Return.Count.ToString();
         GridView1.DataSource = vresp.Return;
         GridView1.DataBind();
     }
 }

We are getting the response in JSON and then 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

See the following .NET code to get information about queued chat visitors using Banckle Cloud API for Chat.

protected void Get_Queued_Visitors()
        {
 
            string request_url = "https://chat.banckle.com/v3/visitors/queue.js";
 
            // Create request object
            WebRequest request = HttpWebRequest.Create(new Uri(request_url));
            // Add custom headers for authentication
            request.Headers.Add("banckle-client-api-key", api_key);
            request.Headers.Add("X-Resource", session_resource);
 
            // 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
            response_stream.Close();
 
            // Parse response as JSON object
            JObject response_json = JObject.Parse(response_body);
 
            VisitorsResponse vresp = JsonConvert.DeserializeObject<VisitorsResponse>(response_json.ToString());
 
            if (vresp.Return.Count > 0)
            {
                lblTotalQ.Text = vresp.Return.Count.ToString();
                GridView2.DataSource = vresp.Return;
                GridView2.DataBind();
            }
 
        }

The above method will get the details of visitors in queue and will display in our second grid view control.

Get Operators' Information

See the following .NET code to get information of operators using Banckle Cloud API.

public void Get_Operator_Info()
{
    string online_only = "false";
    string request_url = "https://chat.banckle.com/v3/operators.js?online=" + online_only;
 
    // Create request object
    WebRequest request = HttpWebRequest.Create(new Uri(request_url));
    // Add custom headers for authentication
    request.Headers.Add("banckle-client-api-key", api_key);
    request.Headers.Add("X-Resource", session_resource);
 
    // 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
    response_stream.Close();
 
    // Parse response as JSON object
    JObject response_json = JObject.Parse(response_body);
 
    OperatorsResponse vresp = JsonConvert.DeserializeObject<OperatorsResponse>(response_json.ToString());
 
    if (vresp.Return.Count > 0)
    {
        lblTotalOp.Text = vresp.Return.Count.ToString();
        GridView3.DataSource = vresp.Return;
        GridView3.DataBind();
    }
}

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.

By using simple Banckle.Chat for Cloud API calls given above; You can get detailed information about 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.

Download Banckle.Chat for Cloud API

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.

Overview: Banckle.Chat for Cloud API

Banckle.Chat for Cloud APIs provides useful live chat APIs to develop new and enhance your existing customer support and engagement web applications. With Banckle Chat API for websites, you can personalize your website visitors’ experience and turn them into potential customers. This web chat API has REST based architecture, which allows you to easily manipulate information and resources using simple HTTP requests and responses.

 

More about Banckle.Chat for Cloud API

-          Homepage of Banckle.Chat for Cloud API

-          Visit Banckle.Chat for Cloud API Marketplace

-          Post your technical questions/queries to Banckle Chat Forum

-          Receive notifications about latest news and supported features by subscribing to Banckle Chat blog

Contact Information

Suite 163, 79 Longueville Road

Lane Cove, NSW, 2066

Australia

Banckle – Social and Business Applications

This email address is being protected from spambots. You need JavaScript enabled to view it.

Phone: +1 214 329 1520

Share It!

Featured

release-news.com Webutation