slang-flight-assistant

0.1.4 • Public • Published

react-native-slang

SlangFlightAssistant

This file showcases all of SlangFlightAssistant features.

Before you begin

  • Install the the two packages below in your project.

$ yarn add react-native-slang@0.1.6

$ yarn add slang-flight-assistant

  • Import the voice flight assistant wrapper in the relevant file

import SlangFlightAssistant from 'slang-flight-assistant';

Usage

SlangFlightAssistant.init

Initialise slang with the below example

SlangFlightAssistant.init({
      buddyID: '<buddy id>', // required
      apiKey: '<api key>', // required
      environment: 'STAGING', // PRODUCTION|STAGING default STAGING
      visibility: 'SHOWN', //  HIDDEN|SHOWN default SHOWN
      requestedLocales: ['en-IN'], // en-IN , hi-IN
      uiConfig: {
        definedPosition: 'CENTER_BOTTOM', // TOP_LEFT, CENTER_CENTER, BOTTOM_RIGHT etc...
        triggerImageResourceName: 'slang_custom_trigger_1', // add the required png to the `/res/drawable` folder to use a different trigger image (png)
      },
    });

SlangFlightAssistant.show

Show Slang trigger

SlangFlightAssistant.show();

SlangFlightAssistant.hide

Hide Slang trigger

SlangFlightAssistant.hide();

SlangFlightAssistant.onFlightStatusWithNumber

Registering a callback function when flightNumber is available, origin and destination will be null


// sample callback function
flightStatusNumber = ({
    origin,
    destination,
    flightNumber,
    StartDateTime,
    EndDateTime,
    clientTimeZone,
  }) => {

    console.log(
      origin,
      destination,
      flightNumber,
      StartDateTime,
      EndDateTime,
      clientTimeZone,
    );

    // Do something with the above values


  };

SlangFlightAssistant.onFlightStatusWithNumber(flightStatusNumber);


SlangFlightAssistant.onFlightStatusWithRoute

Registering a callback function when origin and destination are available. Here flightNumber might be available depending on what the user spoke.


// sample callback function
flightRoute = ({
    origin,
    destination,
    flightNumber,
    StartDateTime,
    EndDateTime,
    clientTimeZone,
  }) => {

    console.log(
      origin,
      destination,
      flightNumber,
      StartDateTime,
      EndDateTime,
      clientTimeZone,
    );

    // Do something with the above values


  };

SlangFlightAssistant.onFlightStatusWithRoute(flightRoute);

SlangFlightAssistant.onResult (optional)

Once the callback is executed and results page is shown, this API can be used to complete the user journey. If true , results were a success, false when there was an error

SlangFlightAssistant.onResult(true); // Responds with: "Here are your results"
// OR
SlangFlightAssistant.onResult(false); // Responds with: "There was an error showing you the results"

Sample implementation

...

import SlangFlightAssistant from 'slang-flight-assistant';

class Features extends Component {
  constructor(props) {
    super(props);
    this.state = {
      origin: null,
      destination: null,
      flightNumber: null,
      StartDateTime: null,
      EndDateTime: null,
      clientTimeZone: null,
    };
  }


  flightStatus = ({
    origin,
    destination,
    flightNumber,
    StartDateTime,
    EndDateTime,
    clientTimeZone,
  }) => {

    this.setState({
      origin,
      destination,
      flightNumber,
      StartDateTime,
      EndDateTime,
      clientTimeZone,
    });


  };

  flightRoute = ({
    origin,
    destination,
    flightNumber,
    StartDateTime,
    EndDateTime,
    clientTimeZone,
  }) => {

    this.setState({
      origin,
      destination,
      flightNumber,
      StartDateTime,
      EndDateTime,
      clientTimeZone,
    });


  };

   componentDidMount() {

    SlangFlightAssistant.init({
      buddyID: '<buddy id>', // required
      apiKey: '<api key>', // required
      environment: 'STAGING', // PRODUCTION|STAGING default STAGING
      visibility: 'SHOWN', //  HIDDEN|SHOWN default SHOWN
      requestedLocales: ['en-IN'], // en-IN , hi-IN
      uiConfig: {
        definedPosition: 'CENTER_BOTTOM', // TOP_LEFT, CENTER_CENTER, BOTTOM_RIGHT etc...
        triggerImageResourceName: 'slang_custom_trigger_1', // add the required png to the `/res/drawable` folder to use a different trigger image (png)
      },
    });

    SlangFlightAssistant.onFlightStatusWithNumber(this.flightStatus);
    SlangFlightAssistant.onFlightStatusWithRoute(this.flightRoute);


  }

  ....

  // Render results with state

Contact

For any queries contact us support@slanglabs.in

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.4
    0
    • latest

Version History

Package Sidebar

Install

npm i slang-flight-assistant

Weekly Downloads

1

Version

0.1.4

License

MIT

Unpacked Size

12.7 kB

Total Files

4

Last publish

Collaborators

  • ritinkar-slang