npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-rasa

v0.3.0

Published

A simple react native project integration with Rasa Open Source

Downloads

255

Readme

react-native-rasa

A simple react native project integrated with Rasa Open Source with using REST Channel. Please see more at Rasa Rest API.

This project uses react-native-gifted-chat so you can use all the props from it.

Install

yarn add react-native-rasa

or

npm install react-native rasa

Setup your Rasa host

The REST channel will provide you with a REST endpoint where you can post user messages and receive the assistant's messages in response.

Add the REST channel to your credentials.yml:

rest:
  # you don't need to provide anything here - this channel doesn't
  # require any credentials

Restart your Rasa X or Rasa Open Source server to make the REST channel available to receive messages. You can then send messages to http://<host>:<port>/webhooks/rest/webhook, replacing the host and port with the appropriate values from your running Rasa X or Rasa Open Source server.

Message Format

Please see more informations from Rasa Doc at here, you also need to know about react-native-gifted-chat message format to understand how this libray works.

Rasa Example

Installation

On the example-rasa folder there is a sample code using poetry and Rasa 3.0.4. If you do not have poetry installed yet you can install it from here. It requires you have python = ">=3.7,<3.9" installed.

You can activate a python environment and install packages with the following commands. Make sure you are on example-rasa folder

poetry shell
poetry install

Running the Rasa and Action Server

At the root of your rasa project, run the following command to start the action server. It will be defaulted to port 5055.

rasa train
rasa run actions

You should see the following output at the terminal action-server-img

Open a new terminal and activate the same virtual environment with poetry shell. Change to directory example-rasa. Run the following command to start the server. The default port is 5005.

rasa run --enable-api --cors "*"

enable-api is optional but cors is required to allow secure data transfer and prevent you from getting Cross-Origin Resource Sharing error. The terminal will show the following output. For Windows users, you need to use double quotes to ensure that CORS registered correctly. api-server-img

Running ngrok

Android and iOS apps will requiere secure https connections. If you are testing locally we recommend you to use ngrok. You should copy the https address on host props.

./ngrok http 5005

action-server-img

Basic chat configuration

import React from 'react';
import {SafeAreaView, StatusBar, StyleSheet} from 'react-native';
import RNRasa from 'react-native-rasa';
// your rasa host, for example:
const HOST = 'http://localhost:5005';
const App = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView style={styles.container}>
        <RNRasa
          host={HOST}
          onSendMessFailed={(error) => console.log(error)}
          emptyResponseMessage="Sorry, I don't understand"
          onEmptyResponse={() => console.log('Handle with your custom action')}
        />
      </SafeAreaView>
    </>
  );
};

export default StyleSheet.create({
  container: {
    flex: 1,
  },
});

For a custom Chat setup, please check the App.tsx file.

Props

  • host (string) - (Required) Your Rasa host, http://<host>:<port>/webhooks/rest/webhook, replacing the host and port with the appropriate values from your running Rasa X or Rasa Open Source server.

  • onSendMessFailed (Function) - (Optional) Callback when sending a message failed.

  • onEmptyResponse (Function) - (Optional) Callback when the bot return empty reponse (Sometimes it happens to Rasa Open Source).

  • emptyResponseMessage (String) - (Optional) The message the bot will return in case the reponse is empty.

  • userId (String) - (Optional) Sets the user Id..

  • userAvatar (String) - (Optional) Sets the user Avatar using an image uri.

  • userName (String) - (Optional) Sets the user name.

  • botName (String) - (Optional) Sets the bot name.

  • botAvatar (String) - (Optional) Sets the bot Avatar using an image uri.

  • You can also use all the props from react-native-gifted-chat

Methods

  • resetMessages (Function) - This clear all messages on the widget.
  • resetBot (Function) - It sends a reset intent to Rasa server (It will requiere a correct configuration on Rasa server to handle this intent. Check how to do that on the our sample code).
  • sendCustomMessage (Function) - It allows to send custom text messages to Rasa server.

Preview

TODO List:

  • [x] Reset bot on destroy
  • [x] Add restart bot options
  • [x] Add checkbox messages and quick replies
  • [x] Add bot avatar
  • [x] Add example
  • [x] Add Video reponses
  • [ ] Voice support
  • [ ] Allow that users attach files and images

PR are welcome ❤️

License