GithubHelp home page GithubHelp logo

richi2293 / react-chat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from voiceflow/react-chat

0.0 1.0 0.0 169.56 MB

React-based chat widget for conversations powered by Voiceflow

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

Shell 0.24% JavaScript 0.79% TypeScript 95.57% CSS 1.20% HTML 2.19%

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

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

Watchers

 avatar

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.