I want to integrate an social chat App (WeChat) into Salesforce, I wish this integration can implement an complete chat communication between Live agent and customer such as following:
- customer send a message to an Org (Salesforce plateform)
- this message become a chat request for Live Chat agent, if any Live Chat agent accept that request, customer also become a chat visitor.
- customer can communicate with Live agent in WeChat App layout by seamless
- Live agent can start to chat with customer or chat visitor by using Live Chat app layout
I already can make step 1 and 2 above happen based on Salesforce oficial guide as following:
a.) Create a Live Agent Session
b.) Create a Chat Visitor Session
but now I cannot start step 3 because every time I follow official guide to start a chat, I always receive error message as following:
Can someone help me to fix this problem?
ps: everyone who try to help me fix this problem, you no need to concern about WeChat side technical issues because I already handle all of it and I'm sure problem what I'm proposed not coming from WeChat APP. Now, What I need is technical support from Salesforce side.
@Ilya Lepesh
=================================================================
New update 1:
I already can achieve my step 3 by using "ChatMessage" method as following:
HttpRequest req = new HttpRequest();
Http h = new Http();
String bodyRes = '';
req.SetEndPoint('https://d.la10.salesforceliveagent.com/chat/rest/Chasitor/ChatMessage');
req.setMethod('POST');
req.setHeader('X-LIVEAGENT-API-VERSION','36');
req.setHeader('X-LIVEAGENT-AFFINITY', affinityToken);
req.setHeader('X-LIVEAGENT-SESSION-KEY', key);
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('text', '1');
gen.writeEndObject();
String sendMsg = gen.getAsString();
req.setBody(sendMsg);
try {
HttpResponse res = h.send(req);
bodyRes = res.getBody();
} catch (System.CalloutException e) {
System.debug('Callout error: '+ e);
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, e.getMessage()));
}
The reason I'm using "ChatMessage" method because new incoming message come from WeChat(social APP), then I have to handle this message first by extracting from WeChat API, and then I using code above to push this message to the Salesforce Live Agent as following:
WeChat Layout "send"
As you can see, every message either I send from Live Agent or receive from WeChat, I have to pre-process first to make sure all incoming or outcoming message are fix to Live Agent and WeChat.
Now, I got new problem is I don't know how to achieve my step 4 because I don't know how to obtain Live Agent message and send it to WeChat client. Because if I just directly input my message into Live Agent panel and click "send" button, then WeChat client will receive nothing.
If I can can control the Live Agent send message behavior, then I can send it to specific URL and WeChat client can see it appear in the WeChat layout.
Can you help me to fix this problem?
Best Answer
Part1
If you look at
SessionId
response, you will see parameterclientPollTimeout
:The number of seconds before you must make a Messages request before your Messages long polling loop times out and is terminated.
And then you refer to Your Message Long Polling Loop:
If you don’t make another Messages request to continue the messaging loop, your session will end after a system timeout on the Live Agent server.
This means that LiveChat was designed in way to listen to client messages. If client isn't active in 30(clientPollTimeout value) seconds, livechat will terminate session.
Now let's move on to Messages service:
Returns all messages that were sent between agents and chat visitors during a chat session.
For example during your session, agent could perform some actions, and livechat will send back everything to the client.
req.SetEndPoint('https:example/chat/rest/System/Messages?ack=' + sequence);
You can parse your responses or use increment operation for this.
Finally we're going to check code:
updated:
Make sure, that yo have following structure: