Skip to content

chadzxrex/nativescript-intercom-bridge

 
 

Repository files navigation

Intercom for NativeScript

This is a plugin that allows your NativeScript app to use Intercom for iOS and/or Intercom for Android. Forked from narusevic's nativescript-intercom-bridge-update, originally developed by Emre.

  • Intercom for iOS supports iOS 10+.
  • Intercom for Android supports API 15 and above.

Generate tgz file

To generate a tgz file that can be used by other NS project

npm build
npm pack

Installation

To install the plugin in your NativeScript app, run the following:

tns plugin add ./{your-local-folder}/nativescript-intercom-bridge-xrex

To use

  1. Prepare your Intercom APP key, checkout the installation section of settings page..
  2. Import nativescript-intercom-bridge-xrex into your component / service (recommend)
import { IntercomBridge } from 'nativescript-intercom-bridge-xrex';

...

ngOninit() {
    
    this.initIntercom()
    
    // Display the native Launcher button.
    IntercomBridge.setLauncherVisibility(true);
}

initIntercom() {
    let SDKKey = isIOS ? environment.iosSDKKey : environment.androidSDKKey;
    
    // Intercom App Id
    let appID = environment.intercomAPPId;
    
    IntercomBridge.init(SDKKey, appID);
    IntercomBridge.enableLogging();
}

handleUserLogin(userId, email, userInfo) {

    // After register, Intercom start to recognize user in the current conversation, only accept id and email.
    IntercomBridge.registerIdentifiedUser({ userId, email });

    // If you want to update user's information after registeration, use updateUser.
    this.updateUser(userInfo)
}

/**
 * 
 * userInfo: {name: string, phone_name: string, [custom_field]: any}
 * more info abt userInfo: https://www.intercom.com/help/en/articles/320-tracking-user-data-in-intercom
*/
updateUser(userInfo) {
    IntercomBridge.updateUser(userInfo);
}


// logout then login as annoymous.
handleUserLogout() {
    IntercomBridge.logout();
    IntercomBridge.registerAnnoymous();
}

// Use displayMessenger while implementing customize launcher button.
displayMessenger() {
    IntercomBridge.displayMessenger();
}


/**
 * 
 * If the identify verification is turned on, you should call setUserHash before registeration. hash is the digest of id or email of user.
 * More info: https://www.intercom.com/help/en/articles/183-enable-identity-verification-for-web-and-mobile 
 */
setUserHash(hash: string) {
    IntercomBridge.setUserHash(hash);
}

/**
 * 
 * Log event of user's behavior in the Intercom.
 * 
 * eventName: Recommend defined the event name as 'verb-noun'
 * metaData: Object consists of event's information, i.e. order_item, order_date.
 * More info: https://developers.intercom.com/intercom-api-reference/reference#event-model
 */
logEvent(eventName: string, metaData?: any) {
    IntercomBridge.logEvent(eventName, metaData);
}

License

nativescript-intercom-bridge-xrex is released under the MIT License.

About

NativeScript Plugin for Intercom

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.7%
  • Ruby 0.3%