0.1.9 • Published 4 years ago

react-native-slang-flight-assistant v0.1.9

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

react-native-slang-flight-assistant

react-native-slang-flight-assistant

This file showcases all of SlangFlightAssistant features.

Before you begin

  • You’d need <API_KEY> and <BUDDY_ID> for this. You should’ve received this from the Slang team. If not, please ask :)

  • Install the package below in your project.

$ yarn add react-native-slang-flight-assistant

or

$ npm install react-native-slang-flight-assistant --save

Mostly automatic installation

$ react-native link react-native-slang-flight-assistant

  • Add the maven repo below to android/build.gradle file
allprojects {
    repositories {
        mavenLocal()
        (...)
 
        maven {
            url "http://maven.slanglabs.in:8080/artifactory/gradle-release"
        }

       (...)
    }
}
  • Import the voice flight assistant wrapper in the relevant file
import SlangFlightAssistant from 'react-native-slang-flight-assistant';

SlangFlightAssistant;

Usage

SlangFlightAssistant.initialize

Using the initialize api like in the example below

SlangFlightAssistant.initialize({
      requestedLocales: ['en-IN'], // possible values ['en-IN', 'hi-IN']
      buddyID: '<buddy id>',
      apiKey: '<api key>',
      flightAssistantListener: {
        onTrackStatus:  onTrackStatusFunc , 
        onAssistantError: onAssistantErrorFunc, 
      },
    });

// onTrackStatusFunc: A function that will recieve 
// the flight status once the intent resolution is complete,
// more details below.

// onAssistantErrorFunc: Notify any error that 
//the Slang Flight Assistant may encounter, 
// more details on this below.    

Important: the initialize API will will load slang in the background and the slang trigger will not show up until SlangFlightAssistant.show(); is called.

SlangFlightAssistant.show

Show Slang trigger

SlangFlightAssistant.show();

SlangFlightAssistant.hide

Hide Slang trigger

SlangFlightAssistant.hide();

flightAssistantListener

There are 2 listeners available onTrackStatus and onAssistantError

onTrackStatus

In the case where the user searches via voice the status of a flight.

Example utternace: What is the status of the flight AB1234

This function is meant to return flight information based on the user voice query.

Once a voice query returns successfully, you can do something with the flight information.

Register a callback function when src_airport, dest_airport, status_date:, flight_number, is available.

SlangFlightAssistant.initialize({
...
      flightAssistantListener: {
        onTrackStatus:  this.onTrackStatusFunc , 
       ...
      },
    });

onTrackStatusFunc = ({
        src_airport,
        dest_airport,
        status_date,
        flight_number,
}) => {

    this.setState({
        src_airport,
        dest_airport,
        status_date,
        flight_number,
    });

    // Do something else with this


  };

Note: based on what the user speaks the listener returns, an example is below.

Example: status of the flight AB1234 will return {status_date: "2020-08-17",flight_number: "1234"} src_airport and dest_airport will be undefined

onAssistantError

This notifies the app when an error occurs in the react-native-slang-flight-assistant

Example: when the assistant cannot connect to the internet

Register a callback function like below

SlangFlightAssistant.initialize({
...
      flightAssistantListener: {
        onAssistantError:  this.onAssistantErrorFunc , 
       ...
      },
    });

  onAssistantErrorFunc = ({
      description,
      type
  }) => {
    console.log(description);
    this.setState({
      error: description,
    });
    // Do somthing else
  };

The description gives you the details of the error.

The type gives an error code int value.

Analytics

SlangFlightAssistant.setUserProperties

This may be used while initialising your app to track analytics for a particular user.

    SlangFlightAssistant.setUserProperties('USER_ID', {
      foo: 'bar',
      location: 'some place else',
    });

SlangFlightAssistant.notifyNonVoiceStatusQuery

This may be used to track analytics for touch based flight status searches.

    SlangFlightAssistant.notifyNonVoiceStatusQuery({
      src_airport: 'BOM',
      dest_airport: 'DEL',
      status_date: '2020-08-08',
      flight_number: 1234,
    });
Contact

For any queries contact us support@slanglabs.in