1. Webchat Template
  2. Default Context

Webchat Template

Default Context

Explains Webchat default context setup for ongoing conversations. Useful for managing continuing chat interactions and stubsession behavior.

The default context handles the ongoing conversation after the initial connection is made.

What is the Default Context Used For?

  • Handle interactions between the user and other systems in stubber
  • React and respond to the user's incoming messages
  • Create a stubsession between the new stub and the webchat session for ongoing communication

Setting Up the Default Context

  1. Navigate to default context and click on Edit Flow

  2. Create Basic Flow Structure

    • Create a state called pending-message (This will be the state that the stub will be in when replying to messages)
    • Add an action called reply (This action will send a message to the webchat client)
    • Add an action called _create (This action runs when the stub is created)
    • Add an action called _update_from_webchat (This action will be used to trigger a reply when a user sends a message)

  3. Configure the Reply Action

    In the reply action, add the Webchat notification to session from the library and configure it as follows:

            "platforms": {
      "webchat": {
        "sessionuuid": "~~stub.data._incoming_webchat_data.sessionuuid",
        "webchat_message": {
          "type": "markdown",
          "value": "~~stubpost.message"
        },
        "stubsession": {
          "set_new_with_timeout_hours": 24
        }
      }
    }
    
          

    Set webchat.sessionuuid to ~~stub.data._incoming_webchat_data.sessionuuid so the notification reaches the correct client.

  4. Configure the _create Action

    In the _create action, add the task Send action from the library and configure it as follows:

            {
      "tasktype": "sendaction",
      "params": {
        "action_name": "reply",
        "message": "A stub has been created",
        "stubref": "~~stub.stubref"
      },
      "name": "sendaction",
      "__key": "sendaction"
    }
    
          

    This triggers a reply when the new stub is created. Once the reply is sent, a stubsession is created between the new stub and the webchat client, routing all future messages into the _update_from_webchat action.

  5. Configure the _update_from_webchat Action

    To respond to future messages, add the task Send action to _update_from_webchat:

            {
      "tasktype": "sendaction",
      "params": {
        "action_name": "reply",
        "message": "Conversation stub is now handling all future replies",
        "stubref": "~~stub.stubref"
      },
      "name": "sendaction",
      "__key": "sendaction"
    }
    
          

    Now all future messages will be handled by the conversation stub: