I am accessing Salesforce Live Agent through REST API version 40.
I am able to create session, do chasitorInit and get
Messages successfully.
When I send Chat Message which user types to agent via ChatMessage call,
I get this error,
Out of sync Ack. Expected 4. Actual 1
The documentation doesn't say to send ack param along with url for /Chasitor/ChatMessage
like how we do for /System/Messages
call
Below is my code,
`public void sendUserChatMessage(LiveAgentData liveAgentData, String text) {
LOGGER.entry(liveAgentData,text);
LiveAgentSessionBean liveAgentSessionBean = liveAgentData.getLiveAgentSessionBean();
Map<String,String> headers = new HashMap<String,String>();
headers.put("X-LIVEAGENT-AFFINITY",liveAgentSessionBean.getAffinityToken());
headers.put("X-LIVEAGENT-API-VERSION","40");
headers.put("X-LIVEAGENT-SESSION-KEY",liveAgentSessionBean.getKey());
LOGGER.debug("CHAT_MESSAGE::: SEQUENCE_ID: "+liveAgentSessionBean.getSequenceId());
headers.put("X-LIVEAGENT-SEQUENCE",liveAgentSessionBean.getSequenceId());
String jsonBody = "{\"text\": \""+text+"\"}";
String response = null;
try {
response = HttpUtils.performPostRequest("https://hostname/chat/rest/Chasitor/ChatMessage",jsonBody,headers);
if("OK".equalsIgnoreCase(response)){
LOGGER.debug("Success sending message")
} else{
throw new Exception("Could not send user chat message: "+response);
}
} catch (Exception e) {
e.printStackTrace();
}
}`
Can someone help me with this.?
Best Answer
I tried to access Salesforce Live Agent REST API(version 40) through a standalone Java class and was able to call all methods successfully. Please see the below code and check if you have missed anything. Hope this helps.
Java Class
Console Screenshots:
Java Console Output: