GithubHelp home page GithubHelp logo

voiceflow / react-chat Goto Github PK

View Code? Open in Web Editor NEW
44.0 14.0 76.0 172.86 MB

React-based chat widget for conversations powered by Voiceflow

Home Page: https://voiceflow.github.io/react-chat/

JavaScript 0.21% TypeScript 94.79% Shell 0.06% HTML 3.82% CSS 1.11%

react-chat's Introduction

React Chat

A react-based chat widget built to interact seamlessly with Voiceflow's runtime.

Installation

yarn add @voiceflow/react-chat
# or
npm install @voiceflow/react-chat

Configuration

interface Configuration {
  verify: {
    /**
     * the ID of your voiceflow project, the project must have `apiPrivacy: public`
     * find this under integrations tab
     */
    projectID: string;
  };

  /**
   * [optional] userID to track users and persist/continue sessions
   */
  userID?: string;

  /**
   * [optional] user metadata for transcripts
   */
  user?: {
    name?: string;
    image?: string;
  };

  /**
   * [optional] the version ID of your project, defaults to 'development'
   * can be a 'development' or 'production' alias or a specific versionID
   */
  versionID?: string;

  /**
   * [optional] voiceflow dialog management runtime endpoint
   * defaults to https://general-runtime.voiceflow.com
   */
  url?: string;

  /**
   * [optional] override configured assistant definitions on integrations tab
   */
  assistant?: {
    title?: string;
    image?: string;
    color?: string;
    description?: string;
    stylesheet?: string;
  };

  launch?: {
    event?: RuntimeAction;
  };
}

Browser Usage

You can use a simple JavaScript snippet to add the chat widget to any HTML page. Ensure that the verify: { projectID: ... } field is replaced with your Voiceflow projectID.

<script type="text/javascript">
  (function (d, t) {
    var v = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    v.onload = function () {
      window.voiceflow.chat.load({
        verify: { projectID: 'XXXXXX...' },
      });
    };
    v.src = 'https://cdn.voiceflow.com/widget/bundle.mjs';
    v.type = 'text/javascript';
    s.parentNode.insertBefore(v, s);
  })(document, 'script');
</script>

Browser API

When the react-chat script is loaded it will register an API as window.voiceflow.chat. It has the following interface:

interface VoiceflowAPI {
  // (re)load the chat
  // chat will not be visible until called
  load: (config: Configuration) => void;

  // open the chat
  open: () => void;

  // close the chat
  close: () => void;

  // hide the chat + button
  hide: () => void;

  // show the chat + button
  show: () => void;

  // send custom interaction to voiceflow
  interact: (action: RuntimeAction) => void;

  proactive: {
    push: (...messages: Trace[]) => void;
    clear: () => void;
  };
}

Example call:

window.voiceflow.chat.show();

Running Locally

To run the chat locally you will need to create a local .env file with your configuration. This will include our Voiceflow project ID and the runtime endpoint.

Create a new file packages/react-chat/.env.development.local with the following contents:

VITE_VF_PROJECT_ID='< your project ID >'
VITE_VF_VERSION_ID='< your version ID [development | production] >'
VITE_VF_RUNTIME_URL='https://general-runtime.voiceflow.com'

Now that the chat is configured, let's install dependencies and run the development server.

# install dependencies
yarn install

# build all packages
yarn build

# run dev server
yarn dev

Once the server is running it should automatically open your browser with the chat widget.

react-chat's People

Contributors

bors-vf[bot] avatar decathectzero avatar effervescentia avatar filipemerker avatar jonahsnider avatar joshthedeveloper avatar matheuspoleza avatar ninabondar avatar vf-service-account avatar viniciusdacal avatar xavidop avatar xavientois avatar z4o4z avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-chat's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>voiceflow/renovate-config-private)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
github-actions
.github/workflows/docs.yml
npm
package.json
  • @voiceflow/commitlint-config 2.0.0
  • @voiceflow/git-branch-check 1.4.1
packages/react-chat/package.json
  • @voiceflow/base-types 2.90.1
  • @voiceflow/sdk-runtime 1.7.0
  • @voiceflow/slate-serializer 1.5.5
  • @voiceflow/voiceflow-types 3.24.0
  • @voiceflow/eslint-config 6.1.0
  • @voiceflow/prettier-config 1.2.1
  • @voiceflow/tsconfig 1.4.8
  • vite 3.2.2
packages/widget/package.json
  • @voiceflow/eslint-config 6.1.0
  • @voiceflow/prettier-config 1.2.1
  • @voiceflow/sdk-runtime 1.7.0
  • @voiceflow/tsconfig 1.4.8
  • vite 3.2.2

  • Check this box to trigger a request for Renovate to run again on this repository

Import errors when installed in Next JS project

Hi,

I've just installed this to my Next JS typescript project to test it out. Following the basic instructions in the React-Chat folder I'm getting an import error on multiple components on the react import:

import * as Xe from "react";
^^^^^^

SyntaxError: Cannot use import statement outside a module

I'm using

  • node version 18.16.0
  • Typescript v5.1.3
  • React v18.2.0

My library is configured to use "node" module resolution. Here is the ts.config:

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "esnext",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "exclude": [
    "node_modules"
  ],
  "include": [
    "next-env.d.ts",
    "module.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ]
}

PSA: This package works best with Next.js version >= 13

Tried to get it to work forever with Next.js v12, but no luck. Some of my struggles were documented here:

#71

Even after importing the Voiceflow component dynamically, the kept throwing a useState is undefined error at this line:

https://github.com/voiceflow/demo-react-chat/blob/main/src/context.tsx#L25

I'd then be shown this Invalid Hook Call error, which was a red herring:

https://legacy.reactjs.org/warnings/invalid-hook-call-warning.html

Upgrading to Next.js fixed most of my problems (if not all of them: #76)

`Error: notImplemented` when calling createTranscript

Hi, I ported this @voiceflow/demo-react-chat app found here from vite to Next.js. I then migrated it into my app. Currently, it's throwing this error:

index.es.js:10276 Uncaught (in promise) Error: not implemented
    at _D.createTranscript (index.es.js:10276:1)
    at DD.createTranscript (index.es.js:10364:1)
    at B (index.es.js:14940:1)
    at Object.reply (index.es.js:14955:1)
    at handleSend (Demo.js:37:15)
    at onSend (index.es.js:9535:1)
    at onKeyPress (index.es.js:9454:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
    at executeDispatch (react-dom.development.js:9041:1)
    at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)
    at processDispatchQueue (react-dom.development.js:9086:1)
    at dispatchEventsForPlugins (react-dom.development.js:9097:1)
    at eval (react-dom.development.js:9288:1)
    at batchedUpdates$1 (react-dom.development.js:26140:1)
    at batchedUpdates (react-dom.development.js:3991:1)
    at dispatchEventForPluginEventSystem (react-dom.development.js:9287:1)
    at dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay (react-dom.development.js:6465:1)
    at dispatchEvent (react-dom.development.js:6457:1)
    at dispatchDiscreteEvent (react-dom.development.js:6430:1)

It happens whenever I send a message to the chatbot. It seems like maybe a typing error?

This is my @voiceflow/react-chat version:

"@voiceflow/react-chat": "^1.46.1"

I will report back with more info.

Chat widget full html page

Hi, How could I implement a full HTML page by embedding javascript snippet? I checked out the "Browser Usage" but it was the bubble chat, not full page

Register a "custom action"

When importing @voiceflow/react-chat into my project, there is not method to register custom actions. Therefore, the Voiceflow runtime is ignoring the custom action payload that is returned from the Voiceflow runtime endpoint.

For additional context, the "React Chat Demo" project uses an outdated version of this repo, but that older version did have a way to register custom actions. I'm using the latest release (1.51.3) in my project.

Current release: 1.51.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.