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", 
            "apiPayloadFromContext": [],  
            "apiHeaders": {"Authorization": "Bearer 1234567890"},  
            "apiParameters": {"customerID": "chat-{{guestid}}"},
            "apiUrl": "http://localhost:5001/mock/guestinfo/123456/{{guestid}}",
            "apiTargetContextAttribute": "guestInfo"
        }
    ]
}

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

{
    "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}}.

Parameters

apiMethod
Type: string
Description: Possible value are GET and POST

apiPayloadFromContext
Type: list
Description: list of attributes from context to be included in JSON payload. Will only be included in POST requests. Header 'Content-Type application/json' will be automatically set for the request.

apiHeaders
Type: dict Description: Request headers to be used in request (HTTP Auth, etc.)

apiParameters
Type: dict Description: URL parameters to be used in request. Templating can be used in the parameter value. {"customerid": "123", "foo": "bar"} will be translated in url parameter customerid=123&foo=bar

apiUrl
Type: string Description: Endpoint URI to be used. Include protocol (e.g. http:// or https://). Templating tags are allowed.

apiTargetContextAttribute
Type: string Description: If this attribute is set the JSON response will be stored as value of this defined attribute (see above example). If this attribute is not set (omitted) the json payload of the request response is saved directly into the user context.

Example: 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 variables customerChoice and handle is posted to the defined endpoint with request headers 'Content-Type application/json'.

{
    "apiRequests": [
        {
            "apiMethod": "POST", 
            "apiPayloadFromContext": ["customerChoice", "handle"], 
            "apiHeaders": {},  
            "apiParameters": {},
            "apiUrl": "http://localhost:5001/mock/guestinfo/123456",
            "targetAttribute": "apiResponseJSON"
        }
    ]
}