Display agent's & customer's images on custom chat window for Live Agent - Salesforce
Live Agent always been a very interesting part to me especially when we talk about incorporating custom features into this.
A very interesting scenario came in front of me wherein we need to add a custom chat window for a button and need agent's image as well as customer's/visitor's image on window for better customer experience and usability.
Initially, it was very difficult to get agent's details as I was unaware where to look for it. But it is given right there in live agent documentation about a JS function that can be used directly to fetch agent's details who accepted the chat request. The name of function is : liveagent.chasitor.getDetails()
To know more about it, please visit getDetails page in Live Agent guide.
I have created a sample page with few styling to look similar like whatsapp chat images with bubbles.
There are three standard events given by salesforce to listen and use chasitor.getDetails method accordingly. You can refer them in documentation.
For this particular page, I did something different. I check for message insertion event in DOM and check who added that message. It can be agent as well as visitor and displays image accordingly. below is the steps I followed for this page:
Check for message insertion event in DOM.
Check who added the message.
If added by agent, get user id from liveagent.chasitor.getDetails method and pass this Id in RemoteAction method in controller to get smallPhotoUrl for agent.
Note : smallPhotoUrl is standard field on User object and pick thumbnail chatter image for user
Add images appropriately in positions in HTML.
JS methods & conditions used:
I check message insertion through following listener:
then , check who added the message by following condition:
- I have used a hard coded image url for visitor. Images for visitors can be picked if you are using community/portal or you use some custom logic to store your visitors and their details
- message inserted by agent has classname as 'operator' and those by visitor has classname as 'client'
To get this full working code, Please visit this github repo. It has all logic with custom css.