       @el.find('.zammad-chat-agent').addClass('zammad-chat-is-hidden')
       @el.find('.zammad-chat-agent-status').addClass('zammad-chat-is-hidden')
 
-    onConnectionEstablished: (agent) =>
+    setSessionId: (id) =>
+      @sessionId = id
+      sessionStorage.setItem 'sessionId', id
+
+    onConnectionEstablished: (data) =>
       @inQueue = false
-      @agent = agent
+      @agent = data.agent
+      @setSessionId data.session_id
 
       @el.find('.zammad-chat-agent').html @view('agent')
-        agent: agent
+        agent: @agent
 
       @enableInput()
 


      @el.css 'bottom', -remainerHeight

    disableInput: ->
      @el.find('.zammad-chat-input').prop('disabled', true)
      @el.find('.zammad-chat-send').prop('disabled', true)

      @sendMessage()

    sendMessage: ->
      message = @input.val()

      return if !message

      sessionStorage.removeItem 'unfinished_message'

      messageElement = @view('message')
        message: message
