Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,35 @@ Open up your apps help center

`Promise<boolean>`

___
### `Intercom.displayHelpCenterCollections()`

Present the help center with specific collections only .

###### Note: If the requested collections cannot be found, the full help center will be shown instead.
### Options

| Type | Type | Required |
| ------- | -------- | -------- |
| collections| string[] |no |

### Returns

`Promise<boolean>`

___
### `Intercom.displayArticle(articleId)`

Displays article with given id.

| Type | Type | Required |
| ------- | -------- | -------- |
| articleId| string |yes |

### Returns

`Promise<boolean>`

___

### `Intercom.displayCarousel(carouselId)`
Expand Down
8 changes: 6 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
def packageJsonFile = file('../package.json')
def packageJson = new groovy.json.JsonSlurper().parseText(packageJsonFile.text)


buildscript {
if (project == rootProject) {
repositories {
Expand All @@ -24,7 +28,7 @@ android {
minSdkVersion safeExtGet('IntercomReactNative_minSdkVersion', 21)
targetSdkVersion safeExtGet('IntercomReactNative_targetSdkVersion', 29)
versionCode 1
versionName "1.0"
versionName packageJson.version

}

Expand Down Expand Up @@ -55,5 +59,5 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'io.intercom.android:intercom-sdk:9.+'
implementation 'io.intercom.android:intercom-sdk:10.+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ public class IntercomErrorCodes {
public static final String DISPLAY_CAROUSEL = "203";
public static final String DISPLAY_HELP_CENTER = "204";
public static final String SET_IN_APP_MESSAGE_VISIBILITY = "205";
public static final String HIDE_MESSENGER = "206";
public static final String HIDE_INTERCOM = "206";
public static final String DISPLAY_ARTICLE = "207";
public static final String SET_LAUNCHER_VISIBILITY = "208";
public static final String SET_BOTTOM_PADDING = "209";
public static final String DISPLAY_HELP_CENTER_COLLECTIONS = "210";
public static final String HANDLE_PUSH_MESSAGE = "301";
public static final String SEND_TOKEN_TO_INTERCOM = "302";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ public static List<Object> recursivelyDeconstructReadableArray(ReadableArray rea
return deconstructedList;
}

public static List<String> readableArrayToStringList(ReadableArray readableArray) {
List<String> deconstructedList = new ArrayList<>();
for (int i = 0; i < readableArray.size(); i++) {
ReadableType indexType = readableArray.getType(i);
switch (indexType) {
case String:
deconstructedList.add(i, readableArray.getString(i));
break;
}
}
return deconstructedList;
}

public static UserAttributes buildUserAttributes(ReadableMap readableMap) {
UserAttributes.Builder builder = new UserAttributes.Builder();
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
Expand Down
30 changes: 25 additions & 5 deletions android/src/main/java/com/intercom/reactnative/IntercomModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.module.annotations.ReactModule;
import com.google.firebase.messaging.RemoteMessage;

import java.util.List;
import java.util.Map;

import io.intercom.android.sdk.Intercom;
import io.intercom.android.sdk.UserAttributes;
import io.intercom.android.sdk.api.ReactNativeHeaderInterceptor;
import io.intercom.android.sdk.identity.Registration;
import io.intercom.android.sdk.push.IntercomPushClient;

Expand Down Expand Up @@ -272,6 +275,20 @@ public void displayHelpCenter(Promise promise) {
}
}

@ReactMethod
public void displayHelpCenterCollections(ReadableArray collectionsId, Promise promise) {
try {
List<String> list = IntercomHelpers.readableArrayToStringList(collectionsId);
Intercom.client().displayHelpCenterCollections(list);
Log.d(NAME, "displayHelpCenterCollections");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "displayHelpCenterCollections error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.DISPLAY_HELP_CENTER_COLLECTIONS, err.toString());
}
}

@ReactMethod
public void displayCarousel(String carouselId, Promise promise) {
try {
Expand All @@ -284,6 +301,7 @@ public void displayCarousel(String carouselId, Promise promise) {
promise.reject(IntercomErrorCodes.DISPLAY_CAROUSEL, err.toString());
}
}

@ReactMethod
public void displayArticle(String articleId, Promise promise) {
try {
Expand Down Expand Up @@ -311,15 +329,15 @@ public void setInAppMessageVisibility(String visibility, Promise promise) {
}

@ReactMethod
public void hideMessenger(Promise promise) {
public void hideIntercom(Promise promise) {
try {
Intercom.client().hideMessenger();
Log.d(NAME, "hideMessenger");
Intercom.client().hideIntercom();
Log.d(NAME, "hideIntercom");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "hideMessenger error:");
Log.e(NAME, "hideIntercom error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.HIDE_MESSENGER, err.toString());
promise.reject(IntercomErrorCodes.HIDE_INTERCOM, err.toString());
}
}

Expand Down Expand Up @@ -350,6 +368,8 @@ public void setBottomPadding(int paddingBottom, Promise promise) {
}

public static synchronized void initialize(Application application, String apiKey, String appId) {
String sdkVersion = BuildConfig.VERSION_NAME;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure when we call this sdkVersion, is BuildConfig.VERSION_NAME the native SDK version eg 10.0.1 or the React Native wrapper version eg. 1.0.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will take React Native module version from gradle Here

ReactNativeHeaderInterceptor.setReactNativeVersion(application.getApplicationContext(), sdkVersion);
Intercom.initialize(application, apiKey, appId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.intercom.android.sdk.api;

import android.content.Context;
import android.util.Log;

public class ReactNativeHeaderInterceptor {
public static void setReactNativeVersion(Context context, String rnVersion) {
HeaderInterceptor.setReactNativeVersion(context, rnVersion);
Log.d("ReactNativeHeader", "Registered RN Header");
Log.d("ReactNativeHeader", rnVersion);
}
}
21 changes: 18 additions & 3 deletions example/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,28 @@ const closeOverlay = async () => {
};
browser.addCommand('closeOverlay', closeOverlay);

const closeHelpCenterOverlay = async () => {
const closeArticleOverlay = async () => {
if (browser.isAndroid) {
await closeOverlay();
const closeButton = await $(
`/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ImageButton`
);
await closeButton.waitForDisplayed({ timeout: 22000 });
await closeButton.click();
} else {
const closeButton = await $(`~intercom help center close button`);
await closeOverlay();
}
};
browser.addCommand('closeArticleOverlay', closeArticleOverlay);

const closeHelpCenterOverlay = async () => {
if (browser.isAndroid) {
const closeButton = await $(
`/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.ImageButton`
);
await closeButton.waitForDisplayed({ timeout: 22000 });
await closeButton.click();
} else {
await closeOverlay();
}
};
browser.addCommand('closeHelpCenterOverlay', closeHelpCenterOverlay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Intercom E2E', () => {

it('Should display article', async () => {
await (await $('~display-article')).click();
await driver.closeOverlay();
await driver.closeArticleOverlay();
});

it('Should message composer', async () => {
Expand All @@ -37,6 +37,14 @@ describe('Intercom E2E', () => {
await driver.closeHelpCenterOverlay();
});

it('Should display help center collections', async () => {
await driver.scrollToElementByAccessibilityLabel(
'display-help-center-collections'
);
await (await $('~display-help-center-collections')).click();
await driver.closeHelpCenterOverlay();
});

it('Should display carousel', async () => {
await driver.scrollToElementByAccessibilityLabel('display-carousel');
await (await $('~display-carousel')).click();
Expand All @@ -63,10 +71,10 @@ describe('Intercom E2E', () => {
);
await driver.clickWithDelay('~toggle-launcher-visibility', 12000);

const laincherId = driver.isAndroid
const launcherId = driver.isAndroid
? '~Intercom launcher'
: '~intercom launcher';
await (await $(laincherId)).waitForDisplayed({ timeout: 12000 });
await (await $(launcherId)).waitForDisplayed({ timeout: 12000 });
await driver.clickWithDelay('~toggle-launcher-visibility', 12000);
});

Expand Down
1 change: 1 addition & 0 deletions example/e2e/types/wido.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare global {
wait: (milis: number) => Promise<void>;
clickWithDelay: (element: string, milis: number) => Promise<void>;
closeHelpCenterOverlay: () => Promise<void>;
closeArticleOverlay: () => Promise<void>;
closeOverlay: () => Promise<void>;
closeAlert: () => Promise<void>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,12 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-IntercomReactNativeExampleUI/Pods-IntercomReactNativeExampleUI-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/intercom-react-native/IntercomFramework.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/IntercomFramework.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand All @@ -551,10 +553,12 @@
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-IntercomReactNativeExample/Pods-IntercomReactNativeExample-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle",
"${PODS_CONFIGURATION_BUILD_DIR}/intercom-react-native/IntercomFramework.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle",
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/IntercomFramework.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ PODS:
- DoubleConversion
- glog
- glog (0.3.5)
- Intercom (9.3.6)
- Intercom (10.0.1)
- intercom-react-native (0.1.0):
- Intercom (~> 9.3.6)
- Intercom (~> 10.0)
- React-Core
- libevent (2.1.12)
- OpenSSL-Universal (1.1.180)
Expand Down Expand Up @@ -457,8 +457,8 @@ SPEC CHECKSUMS:
FlipperKit: 651f50a42eb95c01b3e89a60996dd6aded529eeb
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
Intercom: d44bd4264f61a3e343cac46d7b88d4db0f860077
intercom-react-native: ffdf95e08035567701665c258fa9b67bb508aa8a
Intercom: 9512379fa2a4aaf84cd8884f23b932002edb3147
intercom-react-native: 41bba370e914eaa8ae2f2a84eb312e580c27460d
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
RCTRequired: 082f10cd3f905d6c124597fd1c14f6f2655ff65e
Expand All @@ -485,6 +485,6 @@ SPEC CHECKSUMS:
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: f137f43a8864eea77c51e3f09b5ae3cf758392a4
PODFILE CHECKSUM: 242765731e522625435b8c46a95480e6552fe3d6

COCOAPODS: 1.10.1
12 changes: 10 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import Button from './Button';
import type { Registration } from '../../lib/typescript';
import Config from 'react-native-config';

const COLLECTIONS: string[] = []; //Provide help center collections ids
// To change, replace values in .env
const CAROUSEL_ID = Config.CAROUSEL_ID;
const EVENT_NAME = Config.EVENT_NAME;
const ARTICLE_ID = Config.ARTICLE_ID;
const USER_NAME = Config.USER_NAME;

const TOKEN = Platform.select({
ios: 'RN-IOS-TOKEN',
default: 'RN-ANDROID-TOKEN',
Expand Down Expand Up @@ -185,10 +185,18 @@ export default function App() {
Intercom.displayHelpCenter();
}}
/>
<Button
accessibilityLabel="display-help-center-collections"
disabled={!loggedUser}
title={'Display Help Center Collections'}
onPress={() => {
Intercom.displayHelpCenterCollections(COLLECTIONS);
}}
/>
<Button
accessibilityLabel="display-carousel"
disabled={!loggedUser}
title="Display Carousel"
title={'Display Carousel'}
onPress={() => {
console.log(CAROUSEL_ID);
Intercom.displayCarousel(CAROUSEL_ID);
Expand Down
Loading