1.0.72-rc14 • Published 2 years ago

react-native-verloop-sdk v1.0.72-rc14

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

react-native-verloop-sdk

Getting started

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

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 { *; }

Installation

iOS - Cocoapods

  1. After adding the dependency react-native-verloop-sdk in package.json and running npm install, go to ios subdirectory and run pod install. You should find two dependencies getting installed, RNVerloopSDK and VerloopSDKiOS. You should be good to go.

Android - Manual

  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 = "hello"; // it is same as https://<YOUR CLIENT ID>.verloop.io
        const userId = "raghav"; // it is the unique userID to identify all the chats for this user

        // VerloopSdk.createAnonymousUserConfig(clientId);
        //or
        VerloopSdk.createUserConfig(clientId, userId);

        const eventEmitter = new NativeEventEmitter(VerloopSdk);
        this.eventListener = eventEmitter.addListener('veloop_button_clicked', (event) => {
           console.log(event.title);
           console.log(event.type);
           console.log(event.payload);
        });
        this.eventListener = eventEmitter.addListener('veloop_url_clicked', (event) => {
           console.log(event.url);
        });

        //optional
        VerloopSdk.putCustomField(key, value);
        //optional
        VerloopSdk.putCustomFieldWithScope("test", "value", "USER");
        //optional
        VerloopSdk.putCustomFieldWithScope("test2", "value2", "ROOM");
        //optional
        VerloopSdk.setRecipeId(recipeId);
        //optional
        VerloopSdk.setUserEmail(email);
        //optional
        VerloopSdk.setUserPhone(phoneNumber);
        //optional
        VerloopSdk.setUserName(name);

        VerloopSdk.showChat();
        // VerloopSdk.hideChat();
    }

    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.0.72-rc9

2 years ago

1.0.72-rc8

2 years ago

1.0.72-rc10

2 years ago

1.0.72-rc11

2 years ago

1.0.72-rc12

2 years ago

1.0.72-rc14

2 years ago

1.0.72-rc7

2 years ago

1.0.71-rc8

2 years ago

1.0.71-rc7

2 years ago

1.0.71-rc6

2 years ago

1.0.71-rc5

2 years ago

1.0.71-rc9

2 years ago

1.0.72-rc5

2 years ago

1.0.72-rc4

2 years ago

1.0.72-rc6

2 years ago

1.0.72-rc3

2 years ago

1.0.72-rc2

2 years ago

1.0.71-rc1

3 years ago

1.0.71

3 years ago

1.0.70

3 years ago

1.0.69-rc08

3 years ago

1.0.69-rc01

3 years ago

1.0.69-rc02

3 years ago

1.0.69-rc03

3 years ago

1.0.69-rc04

3 years ago

1.0.69-rc05

3 years ago

1.0.69-rc06

3 years ago

1.0.69-rc07

3 years ago

1.0.68

3 years ago

1.0.67

4 years ago

1.0.66

4 years ago

1.0.65-rc04

4 years ago

1.0.65-rc03

4 years ago

1.0.65-rc02

4 years ago

1.0.65-rc01

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.64-rc16

4 years ago

1.0.64-rc14

4 years ago

1.0.64-rc15

4 years ago

1.0.64-rc13

4 years ago

1.0.64-rc12

4 years ago

1.0.64-rc11

4 years ago

1.0.64-rc08

4 years ago

1.0.64-rc09

4 years ago

1.0.64-rc10

4 years ago

1.0.64-rc07

4 years ago

1.0.64-rc04

4 years ago

1.0.64-rc05

4 years ago

1.0.64-rc06

4 years ago

1.0.64-rc02

4 years ago

1.0.64-rc03

4 years ago

1.0.64-rc01

4 years ago

1.0.63

4 years ago

1.0.62-rc25

4 years ago

1.0.62-rc24

4 years ago

1.0.62-rc23

4 years ago

1.0.62-rc21

4 years ago

1.0.62-rc22

4 years ago

1.0.62-rc20

4 years ago

1.0.62-rc19

4 years ago

1.0.62-rc18

4 years ago

1.0.62-rc17

4 years ago

1.0.62-rc16

4 years ago

1.0.62-rc15

4 years ago

1.0.62-rc14

4 years ago

1.0.62-rc13

4 years ago

1.0.62-rc12

4 years ago

1.0.62-rc11

4 years ago

1.0.62-rc10

4 years ago

1.0.62-rc09

4 years ago

1.0.62-rc07

4 years ago

1.0.62-rc08

4 years ago

1.0.62-rc06

4 years ago

1.0.62-rc05

4 years ago

1.0.62-rc04

4 years ago

1.0.62-rc03

4 years ago

1.0.62-rc02

4 years ago

1.0.62-rc01

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.29

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.40

4 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.48

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.49

4 years ago

1.0.51

4 years ago

1.0.50

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.19

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago