@botpress/webchat
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

Webchat

Installation

npm install @botpress/webchat # for npm
yarn add @botpress/webchat # for yarn
pnpm add @botpress/webchat # for pnpm

Usage

import { useEffect, useState } from 'react'
import { getClient, Webchat, WebchatProvider, WebchatClient, Configuration } from '@botpress/webchat'

// also known as the webhookId; You can copy it from the Botpress Dashboard
const clientId = '$CLIENT_ID'

const userData = { foo: 'bar' }
const configuration: Configuration = {
  botAvatar: 'https://upload.wikimedia.org/wikipedia/commons/9/91/T-bone-raw-MCB.jpg',
  botDescription: 'Hello, world!',
  botName: 'Hello Bot',
}

function App() {
  const [client, setClient] = useState<WebchatClient | null>(null)

  useEffect(() => {
    const client = getClient({ clientId })
    setClient(client)

    // You can listen on events sent by the Webchat backend like this:
    client.on('*', (ev) => {
      console.log('Event:', ev)

      // You can also call the Webchat backend API like this:
      client.getUser().then((user) => {
        console.log('User:', user)
      })
    })
  }, [])

  if (!client) {
    return <div>Loading...</div>
  }
  return (
    <WebchatProvider client={client} configuration={configuration} userData={userData}>
      <Webchat />
    </WebchatProvider>
  )
}

export default App

/@botpress/webchat/

    Package Sidebar

    Install

    npm i @botpress/webchat

    Weekly Downloads

    3,558

    Version

    3.1.0

    License

    MIT

    Unpacked Size

    1.41 MB

    Total Files

    12

    Last publish

    Collaborators

    • slvnperron
    • chsir17
    • botpress-cloud-ops
    • franklevasseur
    • michael.masson