@voiceflow/react-chat
TypeScript icon, indicating that this package has built-in type declarations

1.65.2 • Public • Published

react-chat

Installation

yarn add @voiceflow/react-chat

Usage

For a more complete example see our demo-react-chat repository.

import {
  Chat,
  ChatWindow,
  Launcher,
  SessionStatus,
  SystemResponse,
  TurnType,
  UserResponse,
  useRuntime,
} from '@voiceflow/react-chat';
import { useState } from 'react';
import { match } from 'ts-pattern';

const IMAGE = 'https://picsum.photos/seed/1/200/300';
const AVATAR = 'https://picsum.photos/seed/1/80/80';

const MyChat: React.FC = () => {
  const [open, setOpen] = useState(false);

  const runtime = useRuntime({
    verify: { authorization: '< DIALOG API KEY >' },
    session: { userID: '< UNIQUE USER ID >' },
  });

  const handleLaunch = async () => {
    setOpen(true);
    await runtime.launch();
  };

  const handleEnd = () => {
    runtime.setStatus(SessionStatus.ENDED);
    setOpen(false);
  };

  if (!open) {
    return (
      <span
        style={{
          position: 'absolute',
          right: '2rem',
          bottom: '2rem',
        }}
      >
        <Launcher onClick={handleLaunch} />
      </span>
    );
  }

  return (
    <div
      style={{
        position: 'absolute',
        right: '1rem',
        top: '3rem',
        bottom: '3rem',
        width: '400px',
        border: '1px solid #ddd',
        borderRadius: '8px',
        overflowX: 'hidden',
        overflowY: 'scroll',
      }}
    >
      <ChatWindow.Container>
        <Chat
          title="My Assistant"
          description="welcome to my assistant"
          image={IMAGE}
          avatar={AVATAR}
          withWatermark
          startTime={runtime.session.startTime}
          hasEnded={runtime.isStatus(SessionStatus.ENDED)}
          isLoading={!runtime.session.turns.length}
          onStart={runtime.launch}
          onEnd={handleEnd}
          onSend={runtime.reply}
          onMinimize={handleEnd}
        >
          {runtime.session.turns.map((turn, turnIndex) =>
            match(turn)
              .with({ type: TurnType.USER }, ({ id, type: _, ...props }) => <UserResponse {...props} key={id} />)
              .with({ type: TurnType.SYSTEM }, ({ id, type: _, ...props }) => (
                <SystemResponse
                  key={id}
                  {...props}
                  avatar={AVATAR}
                  isLast={turnIndex === runtime.session.turns.length - 1}
                />
              ))
              .exhaustive()
          )}
          {runtime.indicator && <SystemResponse.Indicator avatar={AVATAR} />}
        </Chat>
      </ChatWindow.Container>
    </div>
  );
};

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.65.238latest
2.58.1-andrew-end-voice-conversation-when-widget-is-closed-COR-4852.00canary
2.42.0-alpha30alpha
2.62.31next

Version History

VersionDownloads (Last 7 Days)Published
2.62.31
2.62.21
2.62.10
2.62.00
2.61.10
2.61.01
2.60.00
2.59.01
2.58.1-andrew-end-voice-conversation-when-widget-is-closed-COR-4852.00
2.58.00
2.57.00
2.56.40
2.56.31
2.56.20
2.56.14
2.56.01
2.55.60
2.55.50
2.55.40
2.55.4-evgeny-assistant-crash-COR-4777.10
2.55.4-evgeny-assistant-crash-COR-4777.00
2.55.4-xavier-this-is-a-ver-long-name-chrash-test-xavier-portilla-IN-000.10
2.55.4-xavier-this-is-a-ver-long-name-chrash-test-xavier-portilla-IN-000.00
2.55.3-xavier-fake-IN-000.20
2.55.30
2.55.3-xavier-fake-IN-000.10
2.55.21
2.55.10
2.55.00
2.54.11
2.54.1-evgeny-assistant-crash-COR-4777.00
2.54.00
2.53.10
2.53.00
2.52.10
2.52.00
2.50.3-Gilly-streaming-issues-again-COR-4714.120
2.50.3-Gilly-filter-empty-messages-COR-4758.120
2.50.3-mikaal-avatar-flashing-DSN-2723.120
2.51.2-mikaal-standardize-loader-DSN-2727.00
2.51.30
2.51.3-ben-dsn-2711.30
2.51.3-renovate-npm-happy-dom-vulnerability-VF-000.00
2.51.2-renovate-npm-happy-dom-vulnerability-VF-000.10
2.51.20
2.51.2-ben-dsn-2728.00
2.51.2-dependabot-npm-and-yarn-happy-dom-15.10.2.00
2.51.2-renovate-npm-happy-dom-vulnerability-VF-000.01
2.51.1-renovate-npm-happy-dom-vulnerability-VF-000.10
2.51.10
2.51.1-mikaal-safari-ui-issues-DSN-2720.11
2.51.1-mikaal-incorrect-default-font-DSN-2704.00
2.51.1-xavier-prerelease-on-demand-IN-2227.120
2.51.1-xavier-prerelease-on-demand-IN-2227.110
2.50.3-Gilly-complete-test-COR-0000.160
2.51.1-mikaal-disable-send-while-receiving-message-DSN-2721.120
2.50.3-Gilly-complete-test-COR-0000.151
2.50.3-Gilly-complete-test-COR-0000.141
2.50.3-Gilly-complete-test-COR-0000.130
2.50.3-Gilly-complete-test-COR-0000.120
2.50.3-Gilly-streaming-issues-again-COR-4714.100
2.50.3-Gilly-streaming-issues-again-COR-4714.90
2.50.3-Gilly-streaming-issues-again-COR-4714.80
2.50.3-ben-streaming-issues-again-COR-4714.50
2.50.3-Gilly-streaming-issues-again-COR-4714.41
2.50.3-Gilly-streaming-issues-again-COR-4714.31
2.50.3-Gilly-streaming-issues-again-COR-4714.20
2.50.1-mikaal-card-hyperlinks-DSN-2699.50
2.51.1-dependabot-npm-and-yarn-happy-dom-15.10.2.00
2.51.1-renovate-npm-happy-dom-vulnerability-VF-000.01
2.50.3-renovate-npm-happy-dom-vulnerability-VF-000.10
2.51.00
2.50.3-andrew-fix-console-error-audio-play-COR-4733.00
2.50.3-Gilly-streaming-issues-again-COR-4714.10
2.50.3-dependabot-npm-and-yarn-happy-dom-15.10.2.00
2.50.3-renovate-npm-happy-dom-vulnerability-VF-000.01
2.50.2-renovate-npm-happy-dom-vulnerability-VF-000.10
2.50.20
2.50.2-Gilly-revert-fix-COR-4714.00
2.50.2-mikaal-loading-indicator-fixes-DSN-2713.120
2.50.1-mikaal-loading-indicator-fixes-DSN-2713.130
2.50.2-dependabot-npm-and-yarn-happy-dom-15.10.2.00
2.50.2-renovate-npm-happy-dom-vulnerability-VF-000.00
2.50.1-renovate-npm-happy-dom-vulnerability-VF-000.10
2.50.10
2.48.1-mikaal-loading-indicator-fixes-DSN-2713.160
2.48.1-Gilly-streaming-issues-COR-4714.140
2.48.2-mikaal-respect-newlines-in-message-DSN-2712.30
2.48.1-Gilly-streaming-issues-COR-4714.130
2.50.1-dependabot-npm-and-yarn-happy-dom-15.10.2.00
2.50.1-renovate-npm-happy-dom-vulnerability-VF-000.00
2.48.1-Gilly-streaming-issues-COR-4714.120
2.48.1-Gilly-streaming-issues-COR-4714.110
2.49.1-renovate-npm-happy-dom-vulnerability-VF-000.10
2.50.00
2.48.2-andrew-pass-on-launcher-toggle-COR-4724.30
2.48.1-Gilly-streaming-issues-COR-4714.90
2.49.1-dependabot-npm-and-yarn-happy-dom-15.10.2.00
2.49.1-renovate-npm-happy-dom-vulnerability-VF-000.00
2.49.00
2.48.2-andrew-show-popover-COR-4684.30
2.48.2-renovate-npm-happy-dom-vulnerability-VF-000.31
2.48.2-mikaal-safari-ui-issues-DSN-2720.30
2.48.2-renovate-npm-happy-dom-vulnerability-VF-000.20
2.48.2-xavier-test-IN-2147.30
2.48.2-alpha.10
2.46.1-alpha.80
2.46.1-alpha.60
2.48.10
2.46.1-alpha.10
2.48.00
2.47.00
2.46.10
2.46.1-alpha.00
2.46.00
2.45.00
2.44.00
2.43.40
2.43.4-rc.10
2.43.4-rc.00
2.43.30
2.43.20
2.43.11
2.42.30
2.42.20
2.42.11
2.42.01
2.42.0-alpha30
2.42.0-alpha20
2.42.0-alpha10
2.41.30
2.41.21
2.41.10
2.41.00
2.40.00
2.39.00
2.38.80
2.38.70
2.38.61
2.38.51
2.38.40
2.38.30
2.38.20
2.38.11
2.38.00
2.37.00
2.36.00
2.35.00
2.34.10
2.34.00
2.33.00
2.32.10
2.32.00
2.31.00
2.30.3-rc.30
2.30.3-rc.20
2.30.3-rc.10
2.30.3-rc.00
2.30.20
2.30.10
2.29.1-rc.00
2.30.00
2.29.11
2.29.01
2.28.1-rc.01
2.28.00
2.27.00
2.26.01
2.25.10
2.25.00
2.23.1-rc.140
2.23.1-rc.131
2.23.1-rc.120
2.23.1-rc.110
2.23.1-rc.100
2.23.1-rc.91
2.24.10
2.24.00
2.23.1-rc.80
2.23.1-rc.70
2.23.1-rc.60
2.23.1-rc.50
2.23.1-rc.30
2.23.1-rc.20
2.23.1-rc.10
2.23.1-rc.00
2.6.3-rc.00
2.23.00
2.22.20
2.22.10
2.22.01
2.21.20
2.21.10
2.21.00
2.20.00
2.19.00
2.18.00
2.17.21
2.17.10
2.17.01
2.16.20
2.16.10
2.16.00
2.15.10
2.15.00
2.14.00
2.13.10
2.13.00
2.12.40
2.12.30
2.12.20
2.12.10
2.12.00
2.11.20
2.11.10
2.11.00
2.10.00
2.9.10
2.9.00
2.8.10
2.8.00
2.7.20
2.7.10
2.7.00
2.6.40
2.6.30
2.6.20
2.6.10
2.6.00
2.5.20
2.5.10
2.5.00
2.4.10
2.4.00
2.3.10
2.3.00
2.2.50
2.2.41
2.2.30
2.2.20
2.2.10
2.2.00
2.1.10
2.1.00
1.65.238
1.65.1498
1.65.00
1.64.00
1.63.00
1.62.10
1.62.00
1.61.00
1.60.40
1.60.34
1.60.20
1.60.10
1.60.00
1.59.40
1.59.30
1.59.20
1.59.10
1.59.00
1.58.30
1.58.21
1.58.10
1.58.00
1.57.00
1.56.50
1.56.40
1.56.30
1.56.20
1.56.10
1.56.00
1.55.40
1.55.30
1.55.20
1.55.10
1.55.00
1.54.00
1.53.10
1.53.00
1.52.10
1.52.00
1.51.30
1.51.20
1.51.10
1.51.00
1.50.40
1.50.30
1.50.21
1.50.10
1.50.00
1.49.60
1.49.50
1.49.40
1.49.30
1.49.20
1.49.10
1.49.00
1.48.10
1.48.00
1.47.80
1.47.70
1.47.60
1.47.50
1.47.40
1.47.30
1.47.20
1.47.10
1.47.00
1.46.70
1.46.61
1.46.50
1.46.40
1.46.30
1.46.20
1.46.12
1.46.00
1.45.40
1.45.30
1.45.20
1.45.10
1.45.00
1.44.10
1.44.00
1.43.00
1.42.00
1.41.00
1.40.20
1.40.10
1.40.00
1.39.00
1.38.10
1.38.00
1.37.10
1.37.00
1.36.00
1.35.00
1.34.00
1.33.00
1.32.00
1.31.20
1.31.10
1.31.00
1.30.10
1.30.00
1.29.00
1.28.20
1.28.10
1.28.00
1.27.60
1.27.50
1.27.40
1.27.30
1.27.20
1.27.10
1.0.40
1.0.30
1.26.00
1.25.40
1.25.30
1.25.20
1.25.10
1.25.00
1.24.150
1.24.140
1.24.130
1.24.120
1.24.110
1.24.100
1.24.90
1.24.80
1.24.70
1.24.60
1.24.50
1.24.40
1.24.30
1.24.20
1.24.10
1.24.00
1.23.230
1.23.220
1.23.210
1.23.200
1.23.190
1.23.180
1.23.170
1.23.160
1.23.150
1.23.140
1.23.130
1.23.120
1.23.110
1.23.100
1.23.90
1.23.80
1.23.70
1.23.60
1.23.50
1.23.40
1.23.30
1.23.20
1.23.10
1.23.00
1.22.00
1.21.10
1.21.00
1.20.00
1.19.00
1.18.00
1.17.20
1.17.10
1.17.00
1.16.00
1.15.00
1.14.00
1.13.00
1.12.00
1.11.00
1.10.00
1.9.00
1.8.00
1.7.00
1.6.00
1.5.00
1.4.10
1.4.00
1.3.00
1.2.00
1.1.00
1.0.00

Package Sidebar

Install

npm i @voiceflow/react-chat

Weekly Downloads

583

Version

1.65.2

License

MIT

Unpacked Size

3.96 MB

Total Files

365

Last publish

Collaborators

  • pmvrmc
  • matheuspoleza
  • amandasteinhauer
  • filipemerker
  • andrewlawrence
  • tylerhhan
  • effervescentia
  • josh_vf
  • voiceflow-gallagan
  • z4o4z
  • sssoflyyy
  • xavidop
  • vf-serviceaccount
  • zhilight
  • trs
  • viniciusdacal
  • ytolun
  • shelone.grantwatson
  • sanasarjanjughazyan
  • ose-voiceflow
  • dandonovan78
  • gillyb
  • theprof
  • abuyak
  • matthewnaik
  • ninabondar
  • jbydeley
  • superzooper3
  • yasminm
  • stabletables
  • sdey02