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

$response


This object is used for filling in system responses.

$response.replies is a list of responses made while processing chatbot reactions. It is an array containing strictly typed elements and utilized in order to transfer chatbot replies to platform-specific chat adapters, such as Telegram, Google Assistant, etc.

replies supports objects of the following types:

  • text is a regular text response. Every element of this type is printed out as a separate message. The tts parameter should contain the same text with special markup rendered by speech synthesis systems. The markup parameter determines text formatting style.
{
  "type":"text",
  "text":"....",
  "tts":"....",
  "markup":
    "html|markdown|plain"
}

  • buttons — renders a regular button.
    "type": "buttons",
    "buttons": [
        {
            "text": "button"
            // all the remaining attributes will be
            // directly passed on to the messenger
        }
    ]
}

  • inlineButtons — renders an inline button. If a url attribute is present, then the specified link will be opened upon pressing the button.
{
    "type": "inlineButtons",
    "buttons": [
        {
            "text": "button",
            "url": "https://www.google.com"
        }
    ]
}

  • image — renders an image.
{
  "type":"image",
  "imageUrl":"http://..."
}

  • link — prints out a link.
{
  "type":"link",
  "url":"http://..."
}

  • raw — is used for passing on methods specific to a particular channel. The mandatory body parameter contains the response body transferred into the chat system. Parameters used for user identification are set up automatically.
{
    "type": "raw",
    "body": {
        ...
    },
    "method": "sendMessage"
}

  • switch — switches the dialog from the bot to a customer service agent. It supports the following additional attributes:

firstMessage:is the message that will be shown in the live chat. It is the last client response by default.

closeChatPhrases: is a string array of commands which the user can type in himself in order to close the live chat and get back to the bot.

ignoreOffline: is a flag indicating whether or not the transfer to a customer service agent should be made despite the lack of agents available. false by default.

oneTimeMessage: indicates if the value of firstMessage should be sent to a customer service agent without making the switch. It enables the agent to receive information on the dialog without initiating a live chat. false by default.

destination: is a group of customer service agents that the client should be transferred to.

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

  • location — prints out geographic coordinates. Its attributes are lat and lon.
{
  "type": "location",
  "lat": 59.934280,
  "lon": 30.335099
}

  • timeout — makes a transition to a specified state if the user gives no response.

interval: is the time limit (in seconds) for the user to make his response.

targetState: is the state transitioned into if there is no response from the user.

{
  "type":"timeout",
  "interval":10,
  "targetState":"/timedout"
}

  • dtmf — is a DTMF message signal (containing figures and characters typed on a touch-tone keypad). Intended for calls only.
$response.replies.push({type:"dtmf"});

  • hangup — cuts off the call. Intended for calls only.
$response.replies.push({type:"hangup"});

How to use

  • Image rendering.
  script:
     $response.replies.push( {
          type: "image",
          imageUrl: " https://testimageurl.jpg",
          text: "Image" // this field is optional
      } )

  • Switching to a customer service agent.
$response.replies .push({
     type:"switch",
     phoneNumber:74155,
     closeChatPhrases: catchAll.closeChatPhrases,
     firstMessage: $client.history,
     destination: catchAll.operatorGroup,
                    });

  • Changing the reply in the post-process if the bot tries to give the same reply for the third time in a row.
init:
    bind("postProcess", function(){
        var $session = $jsapi.context().session;
        var $response = $jsapi.context().response;
        var answer = $response.replies ? $response.replies.reduce (function (answers, current) {
            answers += " " + current.text;
            return answers;
        }, "")  : "";
        if ($session.lastAnswer && (answer == $session.lastAnswer)) {
            $session.answerRepetition = $session.answerRepetition || 0;
            $session.answerRepetition += 1;
        } else {
            $session.answerRepetition = 0;
        }
        if ($session.answerRepetition == 2) {
            $response.replies = [{
                "type": "text",
                "text": "We are going in circles. Could you ask me something else?"
            }];
        }
        $session.lastAnswer = answer;
    });