2.3.0 • Published 4 years ago

@cxco/dcx-connector v2.3.0

Weekly downloads
59
License
ISC
Repository
-
Last release
4 years ago

@CXCO/DCX-CONNECTOR

Library to query DigitalCX endpoints using a common query interface and getting normalized answers.


Why should I use the @cxco/dcx-connector?

The @cxco/dcx-connector is a simple JavaScript library that wraps all the DigitalCX standard endpoints using a simple inbount/outbound data contract. It uses axios under the hood to make the HTTP requests. This library also exports the data contracts in case you want to use your own HTTP client but want to normalize the responses.

Installing

Using npm:

npm install @cxco/dcx-connector

Quickstart

Performing an 'ask' request:

import { doDcxRequest } from '@cxco/dcx-connector'

const payload = {
    type: 'ask',
    data: {
        userInput: 'some question'
    },
    metadata: {},
    config: {
        baseUrl: 'https://your-digitalcx-endpoint',
        apiKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx',
        culture: 'en',
        customerKey: 'your-customer-key' // only needed if you're using the new CAIC URL 
        projectKey: 'your-project-key' // only needed if you're using the new CAIC URL
    }
}

const answer = await doDcxRequest(payload)

you'll get a response with a payload with two objects inside (data and metadata):

{
  "data":  {
    "answer": "some answer",
    "dialogOptions":  [],
    "images":  [],
    "links":  [],
    "outputAdditions":  {},
    "type": "answer",
    "videos":  []
  },
  "metadata":  {
    "culture": "en",
    "interactionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "sessionId": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "id": 0
  }
}

Request Payload

Type

The request can be of the following types:

  • "ask"
  • "dialogstep"
  • "event"
  • "linkclick"
  • "feedback"
  • "faq"
  • "faqsincategory"
  • "defaultfaqs"
  • "categorytree"
  • "category"
  • "searchfaqs"
  • "autocomplete"

Data

The data section allows to pass the main information to the request, e.g. what question needs to be asked. The properties are added to the data object depending on the request being made.

Property NameDescription
userInputThe question to be asked to the engine. Used in "ask", "searchfaqs" and "autocomplete" requests
dialogPathWhen in a dialog, it's a node's "Dialog Path". Used in "ask" and "dialogstep" requests
eventNameThe event to be triggered. Used in the "event" request
classificationIdThe Classification Id. Used in "faqsincategory", "defaultfaqs", "categorytree", "category" and "searchfaqs" requests
categoryIdThe Category Id. Used in "faqsincategory" and "category" requests
faqIdThe FAQ Id. Used in the "faq" request
interactionIdThe interaction Id. Used in "linkclick" and "feedback" requests
linkIdThe clicked link id. Used in the "linkclick" request
linkUrlThe clicked link URL. Used in the "linkclick" request
scoreThe feedback score. Used in the "feedback" request
labelThe feedback label. Used in the "feedback" request
commentThe feedback comment. Used in the "feedback" request

Metadata

The metadata section allows to pass additional information to the request, e.g. minimum number of FAQs needed. The properties depend on the request being made.

Property NameDescription
contextArray of context variables and corresponding values
includeFaqsInclude FAQs in categories
maxFaqsMaximum number of FAQs to be included in the request
minFaqsMinimum number of FAQs to be included in the request
sessionSession properties and corresponding values
sessionIdThe current session Id
sessionModeThe session mode
tDialogStateThe TDialog state
userUser properties and corresponding values
maxMaximum number of words from dictionary
offsetOffset for autocomplete
regionThe region where the original data resides, e.g. West Europe or Southeast Asia
headersObject containing properties referer and userAgent

Config

The config section contains the information related to the how and where to do the request.

Property NameDescriptionMandatory
baseUrlthe URL of the APIyes
apiKeythe API keyyes
culturelanguage (en/nl/de)yes
timeouttime in milliseconds until request times outno
customerKeythe customer key (only needed when using the new CAIC URL)yes/no
projectKeythe project key (only needed when using the new CAIC URL)yes/no

If you're using the new CAIC URL, the project key and customer key are also needed in the config

Example: using just the data contrats

The "buildRequest" data contract generates an object that is accepted by axios as a request configuration.

// import data contracts from the @cxco/dcx-connector
import { buildRequest, buildResponse } from '@cxco/dcx-connector'


const dcxRequest = async (payload) => {

    const requestConfig = buildRequest(payload)

    if (requestConfig === null) {
      throw new Error('Invalid payload')
    }

    const dcxResponse = await httpClient.doRequest(requestConfig)

    return buildResponse(dcxResponse)
}
2.3.0

4 years ago

2.2.1

4 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

2.0.0-beta.2

5 years ago

2.0.0-beta.1

5 years ago

2.0.0-beta.0

5 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago