3.4.7 • Published 4 years ago

@cxco/core v3.4.7

Weekly downloads
1
License
ISC
Repository
bitbucket
Last release
4 years ago

CXCO CORE

The CORE is a package that provides common functionalities to the VA implementations.

  • Default exposed javascript API.
  • Utilities (Markdown parser, etc)

Config

The configuration object is a JSON object that should be available the moment the core loads:

window.cxcoConfig = {
        project: {
            publicApiKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
            culture: 'en',
            customerKey: 'customerA',
            key: 'projectB'
        },
        dci: {
            /* check the documentation for the complete ci configuration */
        }
    };

Some of the configuration parameters are stored in the sessionStorage under 'cxco.dci' as part of the initial state that will define how the DCI will load.

Global Options root of the configuration object

optionoptionaldescriptionexample
engineUrloptionalSpecifies which base url to use'https://proxy.domain.com/customerA/projects/projectB'
lazyLoadoptionalDefines how the DCI initializes. Defaults to falsetrue
sessionoptionalSets Session variables{ mode: 'test' }

Project Options window.cxcoConfig.project

optionoptionaldescriptionexample
publicApiKeymandatorythe given API Key'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
culturemandatorylanguage country code'en'
customerKeymandatorythe given customer key'customerA'
keymandatorythe given project key'projectB'

Options

const instance = new CxcoCore({ useWindowConfig: true, useWindowApi: true, component: 'dci' })
Optiontypedescription
useWindowConfigbooleanGet options from window.cxcoConfig
useWindowApibooleanListen to events from window.cxco
componentstringComponent name

When the option useWindowApi is true the core can be use from the browser's window object.

You can then trigger actions such as:

  • sendEvent
  • ask
  • answer
  • on
  • changeState
  • transcript
  • archive

Examples

// 1 - add metadata to ask request

cxco.push([
        'on',
        'ask',
        function (result) {
            console.log('ask received on the window listener', result)

            if (result.metadata.dimensions) {
                result.metadata.dimensions.push({ 'LoggedIn': 'true' })
            } else {
                result.metadata.dimensions = [{ 'LoggedIn': 'true' }]
            }

        }
    ]);   

// 2 -modify or replace an answer
cxco.push([
        'on',
        'answer',
        function (result) {
            console.log('answer received on the window listener', result)
            result.data.answer = '<p>Modified Answer</p>'
        }
    ])

// 3 - hide input field
cxco.push(['showInput', false])

// 4 - send and event
cxco.push(['sendEvent', 'event_name'])

// 4b - send event with extra metadata
cxco.push(['sendEvent', { data: { eventName: 'event_name'} , metadata: { session: { mode: 'internal'} } }])

/** 5 - Change State of the chatbot.
* modifiable properties: 
* - 'isHidden' (boolean)
* - 'isOpen'(boolean) 
*/
cxco.push(['changeState', { isHidden: true }])

// 6 - trigger a question.
cxco.push(['ask', 'hello world!'])

// 6b - trigger a question passing additional metadata.
cxco.push(['ask', { data: { userInput: 'hello world!'} , metadata: { session: { firstName: 'Joe'} } }])	

// 7 - adding a question message bubble bypassing DCX.
cxco.push(['ask', { data: { userInput: 'hello world!'} , metadata: { target: 'ui' } }])	

// 7b - asking a question in DCX message bubble bypassing the UI.
cxco.push(['ask', { data: { userInput: 'hello world!'} , metadata: { target: 'api' } }])	

// 8 - adding an answer message bubble bypassing DCX.
cxco.push(['answer', { data: { answer: 'The quick brown fox\n\njumps over the lazy dog.'}}])

Plugins

The core allows to register plugins that will listen to core events.

import CxcoCore from '@cxco/core'
import cxcoChatWidget, { htmlAnswers } from '@cxco/ui-chat'
import cxcoDcxApi from '@cxco/api-dcx'

const elm = document.createElement('div')

const instance = new CxcoCore({ useWindowConfig: true, useWindowApi: true })

instance.use(htmlAnswers)
instance.use(cxcoChatWidget(elm))
instance.use(cxcoDcxApi({}))

The plugin package must expose a install function that accepts the core as an argument. In that function you can bind your functions to core events.

// plugin example
export default function (elm) {
    // ...
    return {
        install (core) {

            const chatApp = app(state, actions, view, elm)

            core.on('answer', chatApp.onAnswer)

            core.on('ui.showInput', chatApp.showInput)
        }
    }
}

The Core Answer Object

The core answers with an JSON object that has two main properties: data and metadata.

The data property contains the information that can be show to the user. The metadata contains the extra information that among other things can be used to adapt the GUI.

An example answer would look like:

{
    "data": {
        "type": "answer",
        "answer": "The answer\n",
        "images": [],
        "videos": [],
        "outputAdditions": {},
        "links": []
    },
    "metadata": {
        "sessionId": "257f9ad8-7885-4ffc-99e9-41dc3a6d5014",
        "interactionId": "ba51d5b8-461c-4ea9-acec-72195d810391",
        "culture": "en",
        "escalation": "escalation_1x_noanswer",
        "relatedFaqs": [
            {
                "id": 289,
                "question": "Which are the best pizzas in town?",
                "categories": [
                    1,
                    33
                ]
            },
            {
                "id": 257,
                "question": "Which are the best burgers in town?",
                "categories": [
                    1,
                    98
                ]
            }
        ],
        "originalRequest": {
            "config": {
            },
            "data": {
                "userInput": "I want to eat."
            },
            "metadata": {
                "minFaqs": 1,
                "maxFaqs": 3,
                "classificationId": 1,
                "sessionId": "257f9ad8-7885-4ffc-99e9-41dc3a6d5014",
                "dimensions": [
                    {
                        "LoggedIn": "false"
                    }
                ]
            }
        }
    }
}

In this particular payload there are some contextual FAQs in metadata.relatedFaqs so, the GUI could use them to present more options to the user. It also contains a metadata.escalation stating that the engine couldn't recognize the question.

3.4.7

4 years ago

3.4.0

5 years ago

3.3.0

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.6.4

7 years ago

1.6.0

7 years ago

1.5.5

7 years ago

1.5.4

7 years ago

1.5.3

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago