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

$session


This object is used for storing any session data. When a new session begins, all the data is erased.

A new session can be initiated forcibly by means of the newSession tag.


Special attributes

  • contextPath is the current dialog context. It is intended to be used internally by the platform in order to restore the context upon each subsequent user request.

How to use

  • Storing user's name:
 state: Hello
        q!: * my name is $Name *
        script:
            $session.name = $Name
        a: Hello, {{ $session.name }}!

  • Storing random number:
state: Game
    script:
        $session.number =  $jsapi.random(100) + 1;
        $reactions.answer("My number is {{$session.number}}");
        $reactions.transition("/Check");

  • Storing goods quantities in $session.quantity and adding parametres in $session.cart array:
state: GetQuantity
    script:
        $session.cart = [];
        $session.quantity = parseInt($request.query);
        $session.cart.push({name: $session.pizza_name, id: $session.pizza_id, quantity: $session.quantity});
        a: Would you like anything else?

  • Storing chat ID depending on executed condition:
state: chatId
    script:
        if ($request.channelType.indexOf("chatwidget") > -1) {
            $session.chatId = $request.channelUserId;
        } else {
            $session.chatId = $request.data.chatId;
        }