1. Webchat
  2. Webchat template create context

Webchat

Webchat template create context

Setting the create context for receiving webchat traffic

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

What does the create stub do?

  • The create stub will listen for when a new user sends a message
  • The create stub will create a new stub to handle the conversation

Setup create context for heimdall routing

Create an action register_heimdall_paths image

In register_heimdall_paths add the task heimdall_register from the task library image

Configure heimdall register task

        "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}}_reference_heimdall_implementation.webchatmessagetype.firstmessage",
      "mechanism": "cbh",
      "timeout_seconds": 3600
    }
  },
  "trigger_stubaction": {
    "action_name": "create_stub",
    "stubref": "~~stub.stubref",
    "message": "Created stub from webchat"
  }
}

      

params.uuid

Provides a UUID for the specific Heimdall registration. It uses a helper function to generate a UUID. The parameters stub.stubref, stub.program.branch, and 'initial' are taken to generate a unique ID for the create stub.

params.events.webchat_initial_message.path

stubber.systems.notifications.webchat.org.{{stub.orguuid}} is used to listen to all webchat traffic for your org

stubber.systems.notifications.webchat.org.{{stub.orguuid}}.name.{{stub.program.branch}}_reference_heimdall_implementation is used to listen to webchat traffic from a specific Chat name.

The Chat name being {{stub.program.branch}}_reference_heimdall_implementation.

This will resolve to live_reference_heimdall_implementation on a live stub

This will resolve to draft_reference_heimdall_implementation on a draft stub

You will replace the chat name with the Chat name from your webchat profile

The new chatname being {{stub.program.branch}}_your_chat_name.

image

stubber.systems.notifications.webchat.org.{{stub.orguuid}}.name.{{stub.program.branch}}_reference_heimdall_implementation.webchatmessagetype.firstmessage is used to listen to the firstmessage sent by a webchat user.

params.trigger_stubaction.action_name

This is the name of the action the stub will run when the heimdall event is triggered. We want to run create_stub

Configure create_stub action

In create_stub add the task create_stub (with data) from the task library image

Configure create_stub task

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

      

params.data

Data from heimdall events are placed in stub.data.heimdall Webchat data from heimdall events is placed in stub.data.heimdall.webchat

stubpost.data.heimdall will contain the new incoming data before it is merged into stub.data.heimdall

we want this data to be passed to the create stub as it contains the webchat session uuid this uuid is used to reply to a specific webchat instance

To pass the data to the new stub we configure params.data._incoming_webchat_data to have the value ~~stubpost.data.heimdall.webchat

Our new stub will use the data in stub.data._incoming_webchat_data to send messages to the end user

Create a draft stub and test webchat client

Create a draft stub and run the action register_heimdall_paths image

Open your webchat client and send a message.

After sending a message heimdall will execute the create_stub action.

image

Your setup for routing on heimdall is complete. Back and forth conversation is handled by the default context

Setup a draft create stub for stubref routing

Create an action _update_from_webchat image

Configure create stub task

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

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

      

Data from Webchat service is placed in stub.data._incoming_webchat_data

To pass the data to the new stub we configure params.data._incoming_webchat_data to have the value ~~stubpost.data._incoming_webchat_data

Our new stub will use the data in stub.data._incoming_webchat_data to send messages to the end user

Create a draft stub and test webchat client

Create a draft stub and copy the stubref

image

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

image

Paste your copied stubref into the stubref field

image

Open your webchat client and send a message.

After sending a message the webchat service will execute the _update_from_webchat action.

image

Your setup for stubref routing is complete. Back and forth conversation is handled by the default context