1. Webchat Template
  2. Create Context

Webchat Template

Create Context

Setting up the create context to handle initial webchat connections

The create context is responsible for receiving the first message from a webchat user and initializing a new conversation stub.

What is the Create Context Used For?

  • In order to interact with end users through webchat, you need to have a stub that manages incoming traffic
  • The create context specifies actions that handle the first message a user sends from webchat
  • A stub will be created from the create context, and this stub will handle webchat events

Setup Options

You have two routing options for your webchat traffic:

  1. Navigate to the create context and open the canvas

  2. Create an action called _update_from_webchat

    Your canvas should look like this:

  3. Configure Create Stub Task

    In the _update_from_webchat action, add the task create_stub (with data) from the task library:

    Configure with the following parameters:

            "params": {
      "templateuuid": "~~template.templateuuid",
      "template_branch": "~~template.branch",
      "template_context": "default",
      "data": {
        "_incoming_webchat_data": "~~stubpost.data._incoming_webchat_data"
      }
    }
    
          

    Data from the webchat service is placed in stub.data._incoming_webchat_data. To pass this data to the new stub, we configure params.data._incoming_webchat_data to have the value ~~stubpost.data._incoming_webchat_data.

  4. Test Your Webchat Client

    • You will see that a draft stub was automatically created for you

    • Open that stub and copy the stubref

    • In your webchat profile, select the draft branch and enable Send webchat traffic to stub

    • Paste your copied stubref into the stubref field

    • Open your webchat client and send a message

    • After sending a message, the webchat service will execute the _update_from_webchat action

Option 2: Heimdall Routing (For Advanced Use Cases)

  1. Navigate to the create context and create an action register_heimdall_paths

    Your canvas should look like this when complete:

  2. Configure Heimdall Register Task

    In register_heimdall_paths, add the task heimdall_register from the task library:

    Configure with the following parameters:

            "params": {
      "uuid": "{{#deterministicuuid stub.stubref stub.program.branch 'initial'}}{{/deterministicuuid}}",
      "registration_name": "heimdall_webchat_initial_message",
      "on_trigger_method": "keep",
      "events": {
        "webchat_initial_message": {
          "path": "stubber.systems.notifications.webchat.org.{{stub.orguuid}}.name.{{stub.program.branch}}_your_chat_name.webchatmessagetype.firstmessage",
          "mechanism": "cbh",
          "timeout_seconds": 3600
        }
      },
      "trigger_stubaction": {
        "action_name": "create_stub",
        "stubref": "~~stub.stubref",
        "message": "Created stub from webchat"
      }
    }
    
          

    Important: Replace your_chat_name with the Chat name from your webchat profile.

  3. Configure Create_Stub Action

    In create_stub, add the task create_stub (with data) from the task library:

    Configure with the following parameters:

            "params": {
      "templateuuid": "~~template.templateuuid",
      "template_branch": "~~template.branch",
      "template_context": "default",
      "data": {
        "_incoming_webchat_data": "~~stubpost.data.heimdall.webchat"
      }
    }
    
          

    Data from heimdall events is placed in stub.data.heimdall.webchat. We want to pass this data to the new stub as it contains the webchat session uuid used to reply to a specific webchat instance.

  4. Test Your Webchat with Heimdall

    • Create a draft stub and run the action register_heimdall_paths

    • Open your webchat client and send a message

    • After sending a message, heimdall will execute the create_stub action