Showing posts with label RESTAPI. Show all posts
Showing posts with label RESTAPI. Show all posts

Monday, February 10, 2020

How To Search/Open Record Detail Page in Live Agent Using REST API

In my previous posts we have seen how to send the pre-chat details,how to store pre-chat details in transcript object.

In this post I will explain how to perform the search in specified object with given filed names and details.If record found with given criteria how to open this record in chat details automatically .This in turn will helps the agents to save the time to look for the record by doing the manual search to answers the customer.

The key area that we need to look at is "entityMaps" array in prechatdetails and "prechatEntities" array .
  • entityMaps - Store object api name search field name and it's values
  • prechatEntities - which will stores the search object,search field,perform the search or not,create a new if not exist and whether to do exact match or not. 
{
   
   "organizationId":"00XXXXXXxfQ",
   "buttonId":"573xxxxxl",
   "deploymentId":"572xxxxxx9",
   "userAgent":"",
   "language":"en-US",
   "screenResolution":"1920x1080",
   "visitorName":"John A",
   "prechatDetails":[
       {
         "label":"search field api name",
         "value":"value for the search field",
         "displayToAgent":true,
         "transcriptFields": [],
          "entityMaps":[
            {
               "entityName":"object api name",
               "fieldName":"search field api name"
            }
         ]
      }
     
   ],
   "prechatEntities":[
      {
         "entityName":"object api name",
         "showOnCreate":true,
         "entityFieldsMaps":[
            {
               "fieldName":"field api name",
               "label":"field api name",
               "doFind":true,
               "isExactMatch":true,
               "doCreate":false
            }
         ]
      }
 ],
   "receiveQueueUpdates":true,
   "isPost":true
}

Sample Request:


  • Object To be Searched - Booking_Details__c
  • Filed Name to be Searched - Pnr__c
  • Field value - PNR_3563788883

{
   
   "organizationId":"00XXXXXXxfQ",
   "buttonId":"573xxxxxl",
   "deploymentId":"572xxxxxxx9",
   "userAgent":"",
   "language":"en-US",
   "screenResolution":"1920x1080",
   "visitorName":"John A",
   "prechatDetails":[
       {
         "label":"Pnr__c", // search field api name
         "value":"PNR_3563788883",//Value for pnr to be search
         "displayToAgent":true,
         "transcriptFields": [],
          "entityMaps":[
            {
               "entityName":"Booking_Details__c", //object api name
               "fieldName":"Pnr__c" //search field api name
            }
         ]
      }
     
   ],
   "prechatEntities":[
      {
         "entityName":"Booking_Details__c", //object api name
         "showOnCreate":true,
         "entityFieldsMaps":[
            {
               "fieldName":"Pnr__c", //search field api name
               "label":"Pnr__c", //search field api name
               "doFind":true, //tells to do search or not
               "isExactMatch":true, // do exact match value or not
               "doCreate":false // want to create if not found the record
            }
         ]
      }
 ],
   "receiveQueueUpdates":true,
   "isPost":true
}

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!




Sunday, December 29, 2019

Continuation Integration In Salesforce

Problem: 

When multiple agents are using same visual force page (User Interface) and we are making an external call out to fetch the data from the back end systems,if the external service is taking more time (more than 5 sec) to respond ,all such transactions will be treated as a long running transactions in salesforce .At at any given point of time salesforce allows only 5 long running processes in system and it automatically terminates the other requests and it will not allow the agents to perform any other actions.

New Approach: 

Our salesforce system is more dependent on other services to provide the necessary data to the agent usually we will end up with same issue many times.So,we have decided to change the existing integration model and for all new integrations we have started using continuation frame work.In this frame work all the external call outs which are taking longer time ,all these long running requests will be converted into asynchronous callout and this will not be counted under the salesforce limits and also it will not stop the agents doing other works.

Usually agent can request for data on click of any button or action in visual force and this will make an external call out (step 1) and the app server will handover the request to continuation server before it returning to the visual force page  (steps 2–3) .The Continuation server sends the request to the Web service and receives the response (steps 4–7), then hands the response back to the app server (step 8). Finally, the response is returned to the Visual force page (step 9).



Hope this helps you..Enjoy..!

Thursday, December 12, 2019

Unable To Fetch The affinityToken From SessionId API In Live Agent REST API


  • According to the salesforce documentation to get the affinityToken first in headers you  have to set the X-LIVEAGENT-AFFINITY as null.
  • If your not setting or if your not passing this header without null value in your request will not receive any affinityToken.


Sample request without X-LIVEAGENT-AFFINITY header:








Sample request with X-LIVEAGENT-AFFINITY header:








Hope this helps you..Enjoy..!

Monday, December 9, 2019

How To Store The Pre Chat Details in Live Agent Transcript Object Using REST API

In my previous post we have learn how to pass the pre-chat details in REST API and how it shown to agent etc .Now,if you want to store this information in ChatTranscript (Object Name -LiveChatTranscript ) for future reference we can do it easily just by setting few things the same request body by making some changes at "transcriptFields":[] property in the request.

This information will get stored only after agent has ended the chat conversation with customer and if has chosen a option to store the transcript.

First,please goto the ChatTranscript object and create a custom fields to store the required data.

In my scenario I want to store the product category and price .So,I have created 3 new fields as Category__c,Product_Category__c,Price_Range__c. Product which comes from the chat request I want to store it 2 custom fields called Category__c,Product_Category__c and Price range in Price_Range__c.


API Details:


Headers:
X-LIVEAGENT-API-VERSION:34
X-LIVEAGENT-AFFINITYaffinityToken from SessionId API
X-LIVEAGENT-SESSION-KEYkey from from SessionId API
X-LIVEAGENT-SEQUENCE:1
Content-Type:application/json



Sample Request:

{
  "organizationId": "000008afQ",
  "deploymentId": "57228",
  "buttonId": "57328",
  "sessionId": "id-from-response",
  "userAgent": "Lynx/2.8.8",
  "language": "en-US",
  "screenResolution": "1900x1080",
  "visitorName": "Frank Underwood",
  "prechatEntities": [
    
  ],
  "receiveQueueUpdates": true,
  "isPost": true,
  "prechatDetails": [
   {
      "label": "Price Range",
      "value": "20,000-30,000",
      "displayToAgent": true,
      "transcriptFields": [ "Price_Range__c"],
      "entityFieldMaps": [
        
      ]
    },
{ "label": "Product Category", "value": "Smart Phone", "displayToAgent": true, "transcriptFields": ["Category__c","Product_Category__c"], "entityFieldMaps": [ ] }, { "label": "Description", "value": "I'm looking for a mobile with 8GB RAM and 256 GB ROM ", "displayToAgent": true, "transcriptFields": [ ], "entityFieldMaps": [ ] } ] }

Sample Response:

["Ok","200"]

                                             Hope this helps you..Enjoy..!

Friday, December 6, 2019

Live Agent REST API To Send The Pre Chat Details

Let's take a use case ,where you have bot or some custom FAQs to handle the basic customer queries and but sometimes it's required to connect the customer with one of your executives using salesforce live agent chat.

Whenever your connecting the customer with agent,it's required to pass the pre-chat conversation details to agents so that it will help him/her to greet the customer with issue details and also helps to resolve the customer queries quickly.

Luckily Salesforce supports all these features in their REST API.Please take a look at the api details below.

API Details:


Headers:
X-LIVEAGENT-API-VERSION:34
X-LIVEAGENT-AFFINITYaffinityToken from SessionId API
X-LIVEAGENT-SESSION-KEY: key from from SessionId API
X-LIVEAGENT-SEQUENCE:1
Content-Type:application/json


Sample Request:

{
  "organizationId": "000008afQ",
  "deploymentId": "57228",
  "buttonId": "57328",
  "sessionId": "id-from-response",
  "userAgent": "Lynx/2.8.8",
  "language": "en-US",
  "screenResolution": "1900x1080",
  "visitorName": "Frank Underwood",
  "prechatEntities": [
    
  ],
  "receiveQueueUpdates": true,
  "isPost": true,
  "prechatDetails": [
    {
      "label": "Product Category",
      "value": "Smart Phone",
      "displayToAgent": true,
      "transcriptFields": [  ],
      "entityFieldMaps": [
        
      ]
    },
    {
      "label": "Price Range",
      "value": "20,000-30,000",
      "displayToAgent": true,
      "transcriptFields": [  ],
      "entityFieldMaps": [
        
      ]
    },
    {
      "label": "Description",
      "value": "I'm looking for a mobile with 8GB RAM and 256 GB ROM ",
      "displayToAgent": true,
      "transcriptFields": [   ],
      "entityFieldMaps": [
        
      ]
    }
  ]
}

Sample Response:

["Ok","200"]

How Agent Looks in Salesforce This Data:
After mouse over on Accept


In chat Transcript



Hope this helps you..Enjoy..!




Live Agent REST API To Check Whether Agents Are Available(in Online or Not)

If you want to check whether any agent is available or not to take the new chat,then first we need to check whether a particular button is available to take the request or not.

Because agents are tagged under a particular button,if button status is online it means agents are under the same button is available to take the request.

Please look at the API details below


This api basically takes the list of button ids to which you want to verify ,if specified button id is online it will returns the flag called isAvailable or else isAvailable will not be present in the response.


EndPoint : 


https://HostName/chat/rest/Visitor/Availability?Availability.prefix=Visitor&Availability.ids=[List of Button Ids]&deployment_id=DeploymentId&org_id=OrganizationId

Headers:
X-LIVEAGENT-API-VERSION:34

Content-Type:application/json


Query parameters:

  • org_id - The ID of the Salesforce organization that’s associated with the Live Agent deployment.
  • deployment_id - The 15-digit ID of the Live Agent deployment that the chat request was initiated from.
  • Availability.ids - A comma separated button object IDs for which to verify availability.


{
"messages": [
{
"type": "Availability",
"message": {
"results": [
{
"id": "573280000l",
"isAvailable": true // Agents are available to accept new chat request 
},
{
"id": "573000004" // No agents are available to accept new chat request 
},
{
"id": "5730I00000",
"isAvailable": true //Agents are available to accept new chat request
}
]
}
}
]
}


Hope this helps you..Enjoy..!