2.18.0 • Published 11 days ago

@predictivehire/phchatbot v2.18.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 days ago

Information

PredictiveHire AI chatbot. You can contact PredictiveHire for more information. https://www.predictivehire.com

Usage

  1. Preparation
  2. use React
  3. use Vue(SPA mode)
  4. use Vue(SSR mode)

0. prepare

In order to initiate the request correctly when developing locally, you need to add the host of app.localhost.com

Note: If you use vue-cli to create a new project, you might meet a Invalid Host/Origin header error when you open the page with app.localhost.com. This is because the new version of webpack-dev-server adds security verification. The hostname is checked by default. If the hostname is not in the configuration, the access will be interrupted.

Solution: Create the file vue.config.js in the root directory, and then fill in the following content:

module.exports = {
  devServer: {
    disableHostCheck: true,
  }
}

1. use React

create TestPage component

|-- TestPage

|---- TestPage.tsx

|---- style.css

// ----------------------------------- TestPage.tsx ----------------------------
import "./style.css"

import * as React from "react"
import { PHChatBot } from "@predictivehire/phchatbot"

export const TestPage = () => {
  // for assessmentId you can contact PredictiveHire for more information, so do appId and region
  const appId = "appId"
  const assessmentId = "assessmentId"
  const region = "region" // need to confirm with PredictiveHire
  const env = "qa" // this one is used to decide which domain name to use to initiate an api request

  const chatbotATS = new PHChatBot({
    appId: appId,
    region: region,
    env: env,
    assessmentId: assessmentId
  })

  // developers can add the event callback they want
  chatbotATS.addCallbackHandler({
    FI_ASSESSMENT_STARTED: payload => {
      console.info(payload)
    },
    FI_ASSESSMENT_ANSWER_SAVED: payload => {
      console.info(payload)
    },
    FI_ASSESSMENT_ENDED: assessmentId => {
      console.info(assessmentId)
    }
  })
  chatbotATS.setTheme({
    theme: {
      question: {
        backgroundColor: "#ef8200",
        fontColor: "#fff"
      }
    }
  })
  chatbotATS.attachTo({ selector: "#rootATS" })

  return (
    <div className="main">
      <div className="chat-bot-box" id="rootATS" />
    </div>
  )
}

//-------------------------------------- style.css ----------------------------
.main {
  position: relative;
  text-align: center;
  width: 500px;
  height: 90vh;
  margin: 5vh auto;
  background-color: #fff;
}

.chat-bot-box {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  background-color: #fff;
}

@media screen and (max-width: 980px) {
  .chat-bot-box {
    position: fixed;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    transform: none;
  }
}

2. use Vue(SPA mode)

<template>
  <div class="main">
    <div class="chat-bot-box" id="rootATS" />
  </div>
</template>

<script>
import {PHChatBot} from "@predictivehire/phchatbot"
export default {
  name: 'HelloWorld',
  mounted: () => {
    // for assessmentId you can contact PredictiveHire for more information, so do appId and region
    const appId = "appId"
    const assessmentId = "assessmentId"
    const region = "region" // need to confirm with PredictiveHire
    const env = "qa" // this one is used to decide which domain name to use to initiate an api request

    const chatbotATS = new PHChatBot({
      appId: appId,
      region: region, // need to confirm with PredictiveHire
      env: env, // this one is used to decide which domain name to use to initiate an api request
      assessmentId: assessmentId
    })

    // developers can add the event callback they want
    chatbotATS.addCallbackHandler({
      FI_ASSESSMENT_STARTED: payload => {
        console.info(payload)
      },
      FI_ASSESSMENT_ANSWER_SAVED: payload => {
        console.info(payload)
      },
      FI_ASSESSMENT_ENDED: assessmentId => {
        console.info(assessmentId)
      }
    })
    chatbotATS.setTheme({
      theme: {
        question: {
          backgroundColor: "#ef8200",
          fontColor: "#fff"
        }
      }
    })
    chatbotATS.attachTo({ selector: "#rootATS" })
  }
}
</script>

<style scoped>
.main {
  position: relative;
  text-align: center;
  width: 500px;
  height: 90vh;
  margin: 5vh auto;
  background-color: #fff;
}

.chat-bot-box {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  background-color: #fff;
}

@media screen and (max-width: 980px) {
  .chat-bot-box {
    position: fixed;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    transform: none;
  }
}
</style>

3. use Vue(SSR mode)

<template>
  <div class="main">
    <div class="chat-bot-box" id="rootATS" />
  </div>
</template>

<script>
let PHChatBot
if (typeof window !== 'undefined') {
  // Ensure that the window object has been defined. Otherwise you will encounter window is not defined error
  PHChatBot = require('@predictivehire/phchatbot')
}
export default {
  name: 'HelloWorld',
  mounted: () => {
    // for assessmentId you can contact PredictiveHire for more information, so do appId and region
    const appId = "appId"
    const assessmentId = "assessmentId"
    const region = "region" // need to confirm with PredictiveHire
    const env = "qa" // this one is used to decide which domain name to use to initiate an api request

    const chatbotATS = new PHChatBot.PHChatBot({
      appId: appId,
      region: region, // need to confirm with PredictiveHire
      env: env, // this one is used to decide which domain name to use to initiate an api request
      assessmentId: assessmentId
    })

    // developers can add the event callback they want
    chatbotATS.addCallbackHandler({
      FI_ASSESSMENT_STARTED: payload => {
        console.info(payload)
      },
      FI_ASSESSMENT_ANSWER_SAVED: payload => {
        console.info(payload)
      },
      FI_ASSESSMENT_ENDED: assessmentId => {
        console.info(assessmentId)
      }
    })
    chatbotATS.setTheme({
      theme: {
        question: {
          backgroundColor: "#ef8200",
          fontColor: "#fff"
        }
      }
    })
    chatbotATS.attachTo({ selector: "#rootATS" })
  }
}
</script>

<style scoped>
.main {
  position: relative;
  text-align: center;
  width: 500px;
  height: 90vh;
  margin: 5vh auto;
  background-color: #fff;
}

.chat-bot-box {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  background-color: #fff;
}

@media screen and (max-width: 980px) {
  .chat-bot-box {
    position: fixed;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    transform: none;
  }
}
</style>

Params

paramdesc
envenum(local, qa, sandbox, product) For third-party developers, qa or sandbox will be good for development, and use product for online environments, different value of env will be call the apis with different domain
appIdstring, used to retrieve cross-domain whitelist. Pls contact PredictiveHire for more information(https://www.predictivehire.com/)
regionstring, PredictiveHire will provide API endpoint with different regions for different customers. Pls contact PredictiveHire for more information(https://www.predictivehire.com/)
assessmentIdThis one is generate by PredictiveHire. Pls contact PredictiveHire for more information(https://www.predictivehire.com/)

API

APIdefinitiondesc
attachTo({ selector, index }: { selector: string; index?: number; }) => voidThis selector must be a valid CSS selector string. the default value of index is 0, which means when multiple qualified doms are matched, the index element in the domList should be selected
addCallbackHandler(callbacks: PHChatBotCallback): => voidDevelopers can add the event callback they want. The callBack functions will be called in corresponding stage. You can check the PHChatBotCallback below
setTheme({ theme }: { theme: Theme; }) => voidYou can use this api to customized theme color, the complete data structure is as follows

Params Type

Theme

{
  hint: {
    backgroundColor: string
    fontColor: string
  },
  question: {
    backgroundColor: string
    fontColor: string
  },
  response: {
    backgroundColor: string
    fontColor: string
  },
  listItem: {
    backgroundColor: string
    fontColor: string
  },
  selectedItem: {
    backgroundColor: string
    fontColor: string
  },
  button: {
    backgroundColor: string
    fontColor: string
  }
}

PHChatBotCallback

{
  FI_ASSESSMENT_STARTED: (payload: {
    assessmentId
    chatLogs
    branding
  }) => void;
  FI_ASSESSMENT_ANSWER_SAVED: (payload: {
    assessmentId: string
    question: string
    answer: string
    types: string[]
  }) => void;
  FI_ASSESSMENT_ENDED: (payload: { assessmentId: string }) => void;
}
2.18.0

11 days ago

2.17.1

1 month ago

2.17.0

2 months ago

2.16.2

3 months ago

2.16.1

4 months ago

2.16.0

5 months ago

2.11.0

9 months ago

2.11.1

9 months ago

2.9.1

10 months ago

2.15.2

6 months ago

2.15.3

5 months ago

2.15.0

6 months ago

2.15.1

6 months ago

2.13.0

7 months ago

2.12.0

9 months ago

2.10.0

9 months ago

2.14.1

6 months ago

2.14.2

6 months ago

2.12.1

9 months ago

2.14.0

6 months ago

2.9.0

10 months ago

2.6.1

1 year ago

2.8.0

12 months ago

2.7.3

12 months ago

2.7.0

12 months ago

2.7.2

12 months ago

2.7.1

12 months ago

2.6.0

1 year ago

2.5.8

1 year ago

2.5.7

1 year ago

2.5.9

1 year ago

2.5.10

1 year ago

2.5.6

1 year ago

2.4.1

2 years ago

2.4.0

2 years ago

2.4.2

1 year ago

2.5.5

1 year ago

2.5.0

1 year ago

2.3.2

2 years ago

2.3.1

2 years ago

2.5.2

1 year ago

2.5.1

1 year ago

2.5.4

1 year ago

2.5.3

1 year ago

2.3.0

2 years ago

2.2.1

2 years ago

2.2.3

2 years ago

1.4.40

2 years ago

2.2.2

2 years ago

2.2.4

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.4.39

2 years ago

1.4.37

2 years ago

1.4.36

2 years ago

1.4.38

2 years ago

1.4.33

2 years ago

1.4.35

2 years ago

1.4.34

2 years ago

1.4.32

2 years ago

1.4.31

2 years ago

1.4.30

2 years ago

1.4.26

2 years ago

1.4.28

2 years ago

1.4.27

2 years ago

1.4.29

2 years ago

1.4.24

3 years ago

1.4.23

3 years ago

1.4.25

3 years ago

1.4.22

3 years ago

1.4.21

3 years ago

1.4.20

3 years ago

1.4.19

3 years ago

1.4.18

3 years ago

1.4.17

3 years ago

1.4.16

3 years ago

1.4.15

3 years ago

1.4.14

3 years ago

1.0.26

3 years ago

1.4.13

3 years ago

1.4.12

3 years ago

1.4.11

3 years ago

1.4.10

3 years ago