This site is no longer updated.Go to new Conversational Cloud docs

switch


Switches the dialog from the bot to the agent.

Properties

Optional properties:

  • firstMessage — the message that will be displayed in the chat with the agent. By default: the last phrase of the client.
  • closeChatPhrases — an array of strings, passing a list of commands. Using them, the client will be able to close the chat and return to the dialog with the bot.

When the client sends one of the commands passed as closeChatPhrases, the chat is closed, and the command gets processed by the bot script in the context of the state where switching took place.

  • appendCloseChatButton - control the display of a button for closing the chat with the agent. Accepts true/false: if true - when the agent answers, the button will be displayed, if false - not displayed. The title of the button will be taken from the specified array of lines closeChatPhrases.
  • ignoreOffline — perform a transfer to the agent, ignoring the lack of available agents. By default false.
  • oneTimeMessage — send the text of the firstMessage to the agent without performing the transfer. Designed to transmit data to the agent without entering a dialog. By default false.
  • destination — an agent group to which you want to redirect customers.
  • lastMessage — message that will be passed to the user after they end the conversation with closeChatPhrases.
  • attributesprechat fields. Gets JSON as pairs {"key":"value"}. The properties will be passed to the agent as additional information about the client.
  • hiddenAttributes — prechat fields that will not be passed to the agent. The format is similar to attributes.
  • phoneNumber — the phone number to which you want to redirect the call. Only for the telephone channel. Please, note that the number format depends on the telephony provider.
  • headers — when transferred to an agent, you can set SIP headers for the telephone channel, which will be transmitted in the invite message to the specified number. This feature is usually used for transfer of client information to AON.
  • transferChannel — specify in the field botId for transfer of call via SIP trunk, which belongs to this channel. This will apply the properties of the connected SIP trunk.
  • continueCall — if true, the customer will be returned to the dialog with the bot after talking with the agent, and also if the agent is not available.
  • continueRecording — if true, the conversation continues to be recorded, including the conversation with the agent and when the customer returns to the dialog with the bot again. The call recording will be available in the dialog logs.
  • sendMessagesToOperator — if true, message history will be sent to the agent.
  • sendMessageHistoryAmount — the number of last messages that will be sent to the agent.

Syntax

{
    "type":"switch",          // reply type
  "firstMessage":"..." ,      // optional property
  "closeChatPhrases": [".."],
  "ignoreOffline":true|false,
  "oneTimeMessage": true|false
}

Channel restrictions

switch is not supported in Vonage and Zendesk Chat.

How to use

$response.replies = $response.replies || [];
$response.replies.push({
    type:"switch",
    closeChatPhrases: ["/close", "return to the conversation"],
    firstMessage: $client.history,  // last client message
});
$response.replies = $response.replies || [];
$response.replies.push({
    type:"switch",
    phoneNumber:*****,                     // for the telephone channel
    closeChatPhrases: ["/close", "return to the conversation"],
    firstMessage: $client.history,         // last client message
    destination: catchAll.operatorGroup,   // agent group
});
$response.replies = $response.replies || [];
$response.replies.push({
    type:"switch",
    closeChatPhrases: ["/closeLiveChat", "Close chat"],
    firstMessage: $client.history,
    lastMessage: "See you later!",
    attributes: {
                 "Name": "John",
                 "Surname": "Doe"
    }
});
$response.replies = $response.replies || [];
$response.replies.push({
  type:"switch",
  sendMessagesToOperator: true,     //send message history to the agent
  sendMessageHistoryAmount: 20
})

To transfer the history of the client's conversations with the bot when transferring to an agent you can use preProcess and postProcess:

// saving client chat history
 init:
    $jsapi.bind({
        type: "preProcess",
        name: "savingVisitorChatHistory",
        path: "/",
        handler: function($context) {
            // initialize chat history
            $context.client.chatHistory = $context.client.chatHistory || [];
            var chatHistory = $context.client.chatHistory;
            if ($context.request.query) {
                // add chat history to array
                chatHistory.push({type: "CLIENT", text:$context.request.query});
            }
            // leave last 10 messages in the chat history
            chatHistory.splice(0, chatHistory.length - 10);
        }
    });
// saving bot chat history
    $jsapi.bind({
        type: "postProcess",
        name: "savingBotChatHistory",
        path: "/",
        handler: function($context) {
            // initialize chat history
            $context.client.chatHistory = $context.client.chatHistory || [];
            var chatHistory = $context.client.chatHistory;
            if ($context.response.replies) {
                // add bot's messages to array
                $context.response.replies
                        .filter(function(val) { return val.type === "text"; })
                        .forEach(function(val) { chatHistory.push({ type:"BOT", text: val.text }); });
            }
            // leave last 10 messages in the chat history
            chatHistory.splice(0, chatHistory.length - 10);
        }
 });

Transfer of client's conversations history with the bot to the Salesforce customer engagement platform:

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", text:$context.request.query});
            }
            // if the client sent a file/image/audio, add a link to them
            if ($context.request.event === 'fileEvent' || $context.request.event === 'imageEvent'
                        || $context.request.event === 'audioEvent') {
                chatHistory.push({type:"CLIENT", text:$context.request.data.eventData.url});
            }
            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) {
                // add bot's messages to array
                $context.response.replies
                    .filter(function(val) { return val.type === "text"; })
                    .forEach(function(val) { chatHistory.push({ type:"BOT", text: val.text }); });
            }
             if ($context.response.replies) {
                // add bot's images to array
                $context.response.replies
                    .filter(function(val) { return val.type === "image"; })
                    .forEach(function(val) { chatHistory.push({ type:"BOT", text: val.imageUrl }); });
            }
            if ($context.response.replies) {
                // add bot's audio messages to array
                $context.response.replies
                    .filter(function(val) { return val.type === "audio"; })
                    .forEach(function(val) { chatHistory.push({ type:"BOT", text: val.audioUrl }); });
            }
            chatHistory.splice(0, chatHistory.length - 10);
        }
});