Skip to content

Context modifications

Customer context is a data store on chat user level. It contains three classes of information:

  1. All user specific information that is automatically collected by DialogShift core module (language, time stamps, behaviour scoring - if activated, etc.)
  2. All collected user responses during the conversation, information from legacy APIs, etc.
  3. All user infos the host website has stored about the user (e.g. username, user ID, user master data after website login)

The user context datastore can be read and edited by each element in the conversational content management system. Additionally the website javascript SDK has access to the user context datastore. It allows e.g. to set a foreign user ID and provide user master data to the chat framework after a user logs into the host website.

Set customer context - static

Use direct value assignments to store information on user level during the conversation.

{

    "setContext": {
        "variable1": "foo",
        "variable2": ["bar1", "bar2", "bar3"]
    }

}

setContext can be used on element level and on button level:

  • On element level the context will be modified if the conversational element get triggered in the course of a conversation.
  • On button level the context will be modified if the button gets pressed by the user.

Load customer context - API GET

Use API calls to 3rd party systems and store result from API call in a customer context variable.

{
    "apiRequests": [
        {
            "apiMethod": "GET",  # or POST
            "apiPayloadFromContext": "customerChoice",  # POST only! Variable name from user context; posted with header 'Content-Type application/json'
            "apiHeaders": {},  # request headers 
            "apiParameters": {}, # URL parameters for GET
            "apiUrl": "http://localhost:5001/mock/guestinfo/123456",   # Can use template tags in here
            "targetAttribute": "guestInfo"
        }
    ]
}

Let's assume the 3rd party endpoint returns the json:

{
    "firstname": "Peter",
    "lastname": "Brook"
}

In this example the json payload of the API response will be stored in attribute guestInfo in customer context. To access the lastname of the guest in a personalized text message use the templating tag {{guestInfo.lastname}}.

Write customer context - API POST

Use API calls to 3rd party systems and post customer context variables to REST APIs.

In this example the content of context variable customerChoice is posted to the defined endpoint with application/json.

{
    "apiRequests": [
        {
            "apiMethod": "POST", 
            "apiPayloadFromContext": "customerChoice",  # POST only! Variable name from user context; posted with header 'Content-Type application/json'
            "apiHeaders": {},  # request headers 
            "apiParameters": {}, # URL parameters for GET
            "apiUrl": "http://localhost:5001/mock/guestinfo/123456",   # Can use template tags in here
            "targetAttribute": "apiResponseJSON" # API JSON response is stored in user context.
        }
    ]
}