Skip to main content

Submitting additional data

You can add the customData parameter in the switch response to submit additional data when the script switches the chat to an agent.

The customData parameter accepts JSON data. For example:

$response.replies.push({
type:"switch",
closeChatPhrases: ["/closeLiveChat", "Close chat"],
firstMessage: $client.history,
lastMessage: "We’ll be waiting for your return!",
customData: {
"prechatDetails": [
{
"label": "Email",
"value": $client.email
}
]
}
});

You can use the preProcess and postProcess handlers to pass the client and bot chat history when the chat is switched to an agent:

 init:
$jsapi.bind({
type: "preProcess",
name: "savingVisitorChatHistory",
path: "/",
handler: function($context) {
$context.client.chatHistory = $context.client.chatHistory || [];
var chatHistory = $context.client.chatHistory;
if ($context.request.query) {
chatHistory.push({type: "Client name", text:$context.request.query});
}
chatHistory.splice(0, chatHistory.length - 10);
}
});
$jsapi.bind({
type: "postProcess",
name: "savingBotChatHistory",
path: "/",
handler: function($context) {
$context.client.chatHistory = $context.client.chatHistory || [];
var chatHistory = $context.client.chatHistory;
if ($context.response.replies) {
$context.response.replies
.filter(function(val) { return val.type === "text"; })
.forEach(function(val) { chatHistory.push({ type:"BOT", text: val.text }); });
}
chatHistory.splice(0, chatHistory.length - 10);
}
});