Skip to content

Configuration

The startChatbot function accepts a configuration object as its second argument. This object allows you to customize the chatbot's behavior and set some important options.

The only required options are the api auth options, which are used to authenticate the chatbot with the Mathew API.

This is the default configuration:

javascript
const chatbotOptions = {
    api: {
        baseUrl: 'https://app.mathew.ai/',
    },
    agent: {
        name: 'Mathew',
        language: 'es',
    },
    limits: {},
    showMessageRelevantContext: true,
}

Auth

HMAC-based auth

We use an HMAC-based system to authenticate the chatbot with the Mathew API. You get an API key (public/frontend) and an API secret (private/backend). You will use the API key to authenticate with the Mathew API and the API secret to create the signature needed to verify this authentication.

The signature has to be encoded in base 64. We accept the following methods to create the hash:

  • HMAC-SHA512
  • HMAC-SHA384
  • HMAC-SHA256

The process is the following:

  1. Get an API key and and API secret from Mathew.
  2. Store the API secret securely in your backend (an env variable is a good choice).
  3. Before the user starts using the chatbot, use their user id to calculate the HMAC signature:
    1. Hash the user id (with the chosen SHAXXX)
    2. Encoded it to base 64
    3. Sign the user id hash with the API secret (with the chosen SHAXXX)
    4. Encoded it to base 64
  4. Initialize the chatbot with the HMAC signature, the user id and the API key.
javascript
import { startChatbot } from '@adaptical/mathew-chatbot'
import '@adaptical/mathew-chatbot/style.css'

const chatbotRoot = document.querySelector('#app')

const apiKey = '<your-mathew-api-key>'
const userId = '<current-user-id>'
const method = 'HMAC-SHA256' // 'HMAC-SHA512' | 'HMAC-SHA384' | 'HMAC-SHA256'
const userIdHmac = await getUserIdHmac(userId) // Create this user id HMAC in your backend using your api secret

const apiAuth = { method, apiKey, userId, userIdHmac }
const chatbotOptions = { api: { auth: apiAuth } }

startChatbot(chatbotRoot, chatbotOptions)

Limits

Default: {}

You can configure the content that the chatbot will use to respond to the user using the limits option.

javascript
import { startChatbot } from '@adaptical/mathew-chatbot'
import '@adaptical/mathew-chatbot/style.css'

const chatbotRoot = document.querySelector('#app')

const chatbotOptions = {
    limits: {
        books: ['9780261102439', '9780575081406'],
    },
}

startChatbot(chatbotRoot, chatbotOptions)

Message relevant context

Default: true

You can decide wether you want to show the contents used to answer a user's question or not with the showMessageRelevantContext option.

javascript
import { startChatbot } from '@adaptical/mathew-chatbot'
import '@adaptical/mathew-chatbot/style.css'

const chatbotRoot = document.querySelector('#app')
const chatbotOptions = { showMessageRelevantContext: false }

startChatbot(chatbotRoot, chatbotOptions)