Last active
January 18, 2017 05:25
-
-
Save yazgazan/f0a96d298bb651dd31aec1cfc056fed1 to your computer and use it in GitHub Desktop.
react bridge for Intercom 3.+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import NativeModules from 'NativeModules'; | |
const Intercom = NativeModules.Intercom; | |
export default class IntercomHelper { | |
static registerWithUserId(userId) { | |
Intercom.registerIdentifiedUser(userId); | |
} | |
static reset() { | |
Intercom.reset(); | |
} | |
static updateEmail(email) { | |
Intercom.updateEmail(email); | |
} | |
static updateName(name) { | |
Intercom.updateName(name); | |
} | |
static presentMessageComposer() { | |
Intercom.displayMessageComposer(); | |
} | |
static presentConversationList() { | |
Intercom.displayConversationsList(); | |
} | |
static handlePushMessage() { | |
Intercom.handlePushMessage(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Intercom from 'react-native-intercom'; | |
export default class IntercomHelper { | |
static registerWithUserId(userId) { | |
Intercom.registerIdentifiedUser({ userId }); | |
} | |
static reset() { | |
Intercom.reset(); | |
} | |
static updateEmail(email) { | |
Intercom.updateUser({ email }); | |
} | |
static updateName(name) { | |
Intercom.updateUser({ name }); | |
} | |
static presentMessageComposer() { | |
Intercom.displayMessageComposer(); | |
} | |
static presentConversationList() { | |
Intercom.displayConversationsList(); | |
} | |
static handlePushMessage() {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.pimmr.intercom; | |
import com.facebook.react.bridge.ReactApplicationContext; | |
import com.facebook.react.bridge.ReactContextBaseJavaModule; | |
import com.facebook.react.bridge.ReactMethod; | |
import io.intercom.android.sdk.Intercom; | |
import io.intercom.android.sdk.identity.Registration; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class IntercomModule extends ReactContextBaseJavaModule { | |
private ReactApplicationContext _context; | |
public IntercomModule(ReactApplicationContext reactContext) { | |
super(reactContext); | |
_context = reactContext; | |
} | |
@Override | |
public String getName() { | |
return "Intercom"; | |
} | |
@ReactMethod | |
public void registerIdentifiedUser(String userId) { | |
Intercom.client().registerIdentifiedUser(Registration.create().withUserId(userId)); | |
} | |
@ReactMethod | |
public void reset() { | |
Intercom.client().reset(); | |
} | |
@ReactMethod | |
public void updateEmail(String email) { | |
Map opts = new HashMap(); | |
opts.put("email", email); | |
Intercom.client().updateUser(opts); | |
} | |
@ReactMethod | |
public void updateName(String name) { | |
Map opts = new HashMap(); | |
opts.put("name", name); | |
Intercom.client().updateUser(opts); | |
} | |
@ReactMethod | |
public void displayMessageComposer() { | |
Intercom.client().displayMessageComposer(); | |
} | |
@ReactMethod | |
public void displayConversationsList() { | |
Intercom.client().displayConversationsList(); | |
} | |
@ReactMethod | |
public void handlePushMessage() { | |
Intercom.client().handlePushMessage(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.pimmr.intercom; | |
import com.facebook.react.bridge.ReactApplicationContext; | |
import com.facebook.react.ReactPackage; | |
import com.facebook.react.uimanager.ViewManager; | |
import com.facebook.react.bridge.JavaScriptModule; | |
import com.facebook.react.bridge.NativeModule; | |
import com.pimmr.intercom.IntercomModule; | |
import java.util.List; | |
import java.util.Collections; | |
import java.util.ArrayList; | |
public class IntercomPackage implements ReactPackage { | |
public IntercomPackage() {} | |
@Override | |
public List<Class<? extends JavaScriptModule>> createJSModules() { | |
return Collections.emptyList(); | |
} | |
@Override | |
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | |
return Collections.emptyList(); | |
} | |
@Override | |
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | |
List<NativeModule> modules = new ArrayList<>(); | |
modules.add(new IntercomModule(reactContext)); | |
return modules; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment