GithubHelp home page GithubHelp logo

genesys / genesys-cloud-messenger-mobile-sdk-rn-wrapper Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 5.0 149 KB

[⛔️ DEPRECATED] An SDK that provides a simple react native wrapper for the Genesys Cloud Messenger SDK.

License: MIT License

Kotlin 64.75% Ruby 4.48% JavaScript 0.84% Objective-C 29.93%
archived deprecated deprecated-repo obselete-not-in-use

genesys-cloud-messenger-mobile-sdk-rn-wrapper's Introduction

No Maintenance Intended

Warning

This repo is ⛔️ DEPRECATED. This can serve as a valuable resource for code examples for creating a React Native wrapper for the Mobile Messenger SDK. Please, check Genesys documentation for further info.

DEPRECATED

Genesys Cloud Messaging SDK for React Native

The SDK provides a simple react native wrapper for the Genesys Cloud Messenger SDK.

Author: Genesys

Platform Support: Android, iOS

Getting Started

Pre-requisites

In order to use this SDK you need a Genesys account with the Messaging feature enabled.

Install

Run the following on the application root directory.

  • Option 1 - npm install

    npm install genesys-cloud-messenger-mobile-sdk-rn-wrapper --save
  • Option 2 - yarn add

    yarn add genesys-cloud-messenger-mobile-sdk-rn-wrapper
  • Install Genesys chat module native dependency

    react-native link genesys-cloud-messenger-mobile-sdk-rn-wrapper

Update

To update your project to the latest version of genesys-messenger-mobile-sdk-rn-wrapper

npm update genesys-cloud-messenger-mobile-sdk-rn-wrapper

Platform specific additional steps

android

In order to be able to use the chat module on android please follow the next steps.

  1. Go to build.gradle file, on the android project of your react native app.
    YourAppFolder
    ├── android
    │   ├── app
    │   │   ├── build.gradle  
    │   │   ├── proguard-rules.pro
    │   │   └── src
    │   ├── build.gradle   <---
    │   ├── gradle
    │   │   └── wrapper
    │   ├── gradle.properties
    │   ├── gradlew
    │   ├── gradlew.bat
    │   └── settings.gradle
    |
  • Add the following repositories:
    mavenCentral()
    maven {url "https://genesysdx.jfrog.io/artifactory/genesysdx-android.dev"}

ios

In order to be able to use the chat module on iOS please follow the next steps.

  1. Go to Podfile file, on the ios project of your react native app.

    YourAppFolder
    ├── ios
    │   ├── Podfile   <---
    • validate your platform is set to iOS13 or above.
    platform :ios, '13.0'
    • Add Genesys Messeging SDK sources.
    source 'https://github.com/genesys/dx-sdk-specs-dev'
    source 'https://github.com/CocoaPods/Specs'
    • Add use_frameworks! inside target scope.
    • Add below post_install inside target scope.
        target 'YourAppTargetName' do
        config = use_native_modules!
        use_frameworks!
    
        use_react_native!(
            :path => config[:reactNativePath],
            # to enable hermes on iOS, change `false` to `true` and then install pods
            :hermes_enabled => false
        )
    
        post_install do |installer|
            react_native_post_install(installer)
    
            installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
            end
    
            if (target.name&.eql?('FBReactNativeSpec'))
                target.build_phases.each do |build_phase|
                if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
                    target.build_phases.move(build_phase, 0)
                end
                end
            end
            end
        end
        end

    Podfile Full Example

    • Disable Flipper if activated.
         # use_flipper!()

    2 . Make sure you run pod update genesys-cloud-messenger-mobile-sdk-rn-wrapper to get latest version.

Usage

import

Import GenesysCloud module.

import { NativeModules } from 'react-native';
const { GenesysCloud } = NativeModules;

start-chat

Call startChat to get the messenging view and start conversation with an agent.

// Start a chat using the following line:
GenesysCloud.startChat(deploymentId, domain, tokenStoreKey, logging);

chat-events

The wrapper allows listenning to events raised on the chat.

  • Error events Error event has the following format: {errorCode:"", reason:"", message:""}

  • State events Currently only started and ended are supported. State event has the following format: {state:""}

In order to register to chat events, add the following to your App:

import { DeviceEventEmitter, NativeEventEmitter } from 'react-native';

// Create event emitter to subscribe to chat events
const eventEmitter = Platform.OS ===  'android' ? DeviceEventEmitter : new NativeEventEmitter(GenesysCloud)

//-> Before calling to startChat, make sure to subscribe to chat events.

// Adds a listener to messenger chat errors.
listeners['onMessengerError'] = eventEmitter.addListener('onMessengerError', (error) => {});

// Adds a listener to messenger chat state events.
listeners['onMessengerState'] = eventEmitter.addListener('onMessengerState', (state)=>{});

//-> Once the chat was ended, the listeners should be removed.
listeners['onMessengerError'].remove();
listeners['onMessengerState'].remove();


// E.g. Usage of the `ended` state event to remove chat listeners:  
const onStateChanged = (state) => {
    if(state.state == 'ended'){
        Object.keys(listeners).forEach((key)=>{
            const listener = listeners[key]
            console.log(`removing listener: ${key}`);
            if(listener) listener.remove();
        })
    }
};

👉 Checkout Sample Application for more details


Android

Configure chat screen orientation

Before startChat is called, use GenesysCloud.requestScreenOrientation() API to set the chat orientation to one of the available options provided by GenesysCloud.getConstants().

  • SCREEN_ORIENTATION_PORTRAIT
  • SCREEN_ORIENTATION_LANDSCAPE
  • SCREEN_ORIENTATION_UNSPECIFIED
  • SCREEN_ORIENTATION_LOCKED
// E.g.
GenesysCloud.requestScreenOrientation(   
                    GenesysCloud.getConstants().SCREEN_ORIENTATION_LOCKED)

MinifyEnabled and proguard rules

If the hosting app is using the minifyEnabled on gradle configurations, the following line should be added to the proguard-rules.pro file:
-keep class com.genesys.cloud.messenger.transport.shyrka.** { *; }

License

MIT

genesys-cloud-messenger-mobile-sdk-rn-wrapper's People

Contributors

afanasievanton avatar bjdupuis avatar elizasapir avatar inindevevangelists avatar timsmithgenesys avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.