1.1.0-rc.5 • Published 11 months ago

react-native-verloop-sdk v1.1.0-rc.5

Weekly downloads
158
License
MIT
Repository
github
Last release
11 months ago

Getting started

$ npm install react-native-verloop-sdk --save

Mostly automatic installation

$ react-native link react-native-verloop-sdk

If you are using proguard in android add the following

-keepattributes *Annotation*
-keepclassmembers class ** {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

Pods installation

iOS

  1. Navigate to Your iOS Directory: Open a terminal and navigate to the ios directory of your React Native project: cd ios
  2. Edit Your Podfile: Open the generated Podfile in your favorite text editor and add the necessary ,uncomment platform set like below : platform :ios, '13.0'
  3. Install Pods: pod install

    Updating Pods : (if needed) cd ios pod install --repo-update

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.reactlibrary.VerloopSdkPackage; to the imports at the top of the file
  • Add new VerloopSdkPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-verloop-sdk'
    project(':react-native-verloop-sdk').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-verloop-sdk/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-verloop-sdk')

Usage

import { Component } from 'react';
import { NativeEventEmitter, NativeModules } from 'react-native';
import VerloopSdk from 'react-native-verloop-sdk';

export default class VerloopLiveChat extends Component {
  async componentDidMount() {
    const clientId = 'reactnative'; // it is same as https://<YOUR COMPANY ID>.verloop.io
    const userId = 'TestReactNative'; // it is the unique userID to identify all the chats for this user

    VerloopSdk.createUserConfig(clientId, userId);
    //or
    //VerloopSdk.createAnonymousUserConfig(clientId);
  
    const eventEmitter = new NativeEventEmitter(VerloopSdk);
    VerloopSdk.setButtonClickListener()
    VerloopSdk.setUrlClickListener()
    this.eventListener = eventEmitter.addListener(
      'veloop_button_clicked',
      (event) => {
        console.log('veloop_button_clicked',event);
      }
    );
    this.eventListener = eventEmitter.addListener(
      'veloop_url_clicked',
      (event) => {
        console.log('veloop_url_clicked',event);
      }
    );
    
    //optional
    VerloopSdk.putCustomFieldWithScope('test', 'value', 'USER');
    //optional
    //VerloopSdk.setRecipeId("<recipeId>");
    //optional
    VerloopSdk.setUserEmail('<userEmail>');
    //optional
    VerloopSdk.setUserPhone('<userPhone>');
    //optional
    VerloopSdk.setUserName('<userPhone>');

    VerloopSdk.enableiOSNotification('<device token>')

    VerloopSdk.showChat();
    
  }

  render() {
    return null;
  }
  componentWillUnmount() {
    this.eventListener.remove(); //Removes the listener
  }
}

Steps to enable notification:

Create your application on firebase console. (https://console.firebase.google.com)

Download google-services.json and GoogleService-Info.plist for android and iOS respectively.\ Make sure your google-services.json and GoogleService-Info.plist are placed in correct folders.\ google-services.json is placed inside /android/app\ GoogleService-Info.plist is placed inside /ios

Android

Configure gradle files. https://firebase.google.com/docs/cloud-messaging/android/client#set-up-firebase-and-the-fcm-sdk

Add dependency: implementation 'com.google.firebase:firebase-messaging:20.0.1'

Edit MainApplication.java:

import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;                       
import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
   new MainReactPackage(),
   new RNFirebasePackage(),
   new RNFirebaseMessagingPackage(),
   new RNFirebaseNotificationsPackage()
  );                               
}

Add these lines in settings.gradle

include ':react-native-firebase'                       
project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android')

In app build gradle, add dependency:

dependencies {
   compile(project(':react-native-firebase')) {   
       transitive = false
   }
   // ... other dependencies listed
}

Install firebase as a dependency\ npm install --save react-native-firebase

React Native Code

import React, {Component} from 'react';
import VerloopSdk from 'react-native-verloop-sdk';
import firebase from 'react-native-firebase';
import { AsyncStorage } from 'react-native';

export default class VerloopLiveChat extends Component {

    async componentDidMount() {
        const token = await checkPermissionAndGetToken();
        if(token != null){
          await VerloopSdk.setFcmToken(token);
        }
          
        await VerloopSdk.createAnonymousUserConfig('hello.stage');
        VerloopSdk.showChat();
    }
   
    async checkPermissionAndGetToken() {
      const enabled = await firebase.messaging().hasPermission();
      if (enabled) {
          return this.getToken();
      } else {
          const permissionGranted = this.requestPermission();
          if(permissionGranted){
            return this.getToken();
          }
      }
      return null;
    }
    
    async getToken() {
      let fcmToken = await AsyncStorage.getItem('fcmToken');
      if (!fcmToken) {
          fcmToken = await firebase.messaging().getToken();
          if (fcmToken) {
              // user has a device token
              await AsyncStorage.setItem('fcmToken', fcmToken);
          }
      }
      return fcmToken;
    }

    async requestPermission() {
      try {
          await firebase.messaging().requestPermission();
          return true;
      } catch (error) {
          // User has rejected permissions
          console.log('permission rejected');
      }
      return false;
    }

    render() {
        return null;
    }
}
1.1.0-rc.2

11 months ago

1.1.0-rc.5

11 months ago

1.1.0-rc.1

11 months ago

1.0.72-rc9

3 years ago

1.0.72-rc8

3 years ago

1.0.72-rc10

3 years ago

1.0.72-rc11

3 years ago

1.0.72-rc12

3 years ago

1.0.72-rc14

3 years ago

1.0.72-rc7

3 years ago

1.0.71-rc8

3 years ago

1.0.71-rc7

3 years ago

1.0.71-rc6

3 years ago

1.0.71-rc5

3 years ago

1.0.71-rc9

3 years ago

1.0.72-rc5

3 years ago

1.0.72-rc4

3 years ago

1.0.72-rc6

3 years ago

1.0.72-rc3

3 years ago

1.0.72-rc2

3 years ago

1.0.71-rc1

4 years ago

1.0.71

4 years ago

1.0.70

4 years ago

1.0.69-rc08

4 years ago

1.0.69-rc01

4 years ago

1.0.69-rc02

4 years ago

1.0.69-rc03

4 years ago

1.0.69-rc04

4 years ago

1.0.69-rc05

4 years ago

1.0.69-rc06

4 years ago

1.0.69-rc07

4 years ago

1.0.68

5 years ago

1.0.67

5 years ago

1.0.66

5 years ago

1.0.65-rc04

5 years ago

1.0.65-rc03

5 years ago

1.0.65-rc02

5 years ago

1.0.65-rc01

5 years ago

1.0.65

5 years ago

1.0.64

5 years ago

1.0.64-rc16

5 years ago

1.0.64-rc14

5 years ago

1.0.64-rc15

5 years ago

1.0.64-rc13

5 years ago

1.0.64-rc12

5 years ago

1.0.64-rc11

5 years ago

1.0.64-rc08

5 years ago

1.0.64-rc09

5 years ago

1.0.64-rc10

5 years ago

1.0.64-rc07

5 years ago

1.0.64-rc04

5 years ago

1.0.64-rc05

5 years ago

1.0.64-rc06

5 years ago

1.0.64-rc02

5 years ago

1.0.64-rc03

5 years ago

1.0.64-rc01

5 years ago

1.0.63

5 years ago

1.0.62-rc25

5 years ago

1.0.62-rc24

5 years ago

1.0.62-rc23

5 years ago

1.0.62-rc21

5 years ago

1.0.62-rc22

5 years ago

1.0.62-rc20

5 years ago

1.0.62-rc19

5 years ago

1.0.62-rc18

5 years ago

1.0.62-rc17

5 years ago

1.0.62-rc16

5 years ago

1.0.62-rc15

5 years ago

1.0.62-rc14

5 years ago

1.0.62-rc13

5 years ago

1.0.62-rc12

5 years ago

1.0.62-rc11

5 years ago

1.0.62-rc10

5 years ago

1.0.62-rc09

5 years ago

1.0.62-rc07

5 years ago

1.0.62-rc08

5 years ago

1.0.62-rc06

5 years ago

1.0.62-rc05

5 years ago

1.0.62-rc04

5 years ago

1.0.62-rc03

5 years ago

1.0.62-rc02

5 years ago

1.0.62-rc01

5 years ago

1.0.61

5 years ago

1.0.60

6 years ago

1.0.59

6 years ago

1.0.58

6 years ago

1.0.57

6 years ago

1.0.56

6 years ago

1.0.29

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.37

6 years ago

1.0.36

6 years ago

1.0.35

6 years ago

1.0.34

6 years ago

1.0.39

6 years ago

1.0.38

6 years ago

1.0.40

6 years ago

1.0.44

6 years ago

1.0.43

6 years ago

1.0.42

6 years ago

1.0.41

6 years ago

1.0.48

6 years ago

1.0.47

6 years ago

1.0.46

6 years ago

1.0.45

6 years ago

1.0.49

6 years ago

1.0.51

6 years ago

1.0.50

6 years ago

1.0.55

6 years ago

1.0.54

6 years ago

1.0.53

6 years ago

1.0.52

6 years ago

1.0.19

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago