diff --git a/CHANGELOG.md b/CHANGELOG.md
index 051df4e8..d31f50e6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,19 @@
# Intercom for Cordova/PhoneGap
+## 10.0.0 (2021-06-29)
+#### v10.0.0 of the Cordova plugin supports the latest version (10.0.1) of the Intercom mobile SDK.
+##### Enhancements
+* We have redesigned the Help Center for mobile apps. ✨
+* New UI, optimized specifically for mobile apps and small screens
+* Type-ahead search to help users find answers quicker than ever
+* Control whether users open up a specific collection of articles, a group of collections, or specific search results
+* Localization - with right to left language display
+* Accessibility support: screen readers, dynamic font sizes, and keyboard navigation - to support all end users
+* New Help Center Data API that enables you to build your own help center UI, enabling a much deeper and custom integration into your app.
+##### Improvements and bug fixes
+* Fixed an issue where the special notice message would not display.
+* `hideMessenger()` has now been deprecated and removed. Please use `hideIntercom()` instead. This method will hide all Intercom UI in your app.
+
## 9.4.0 (2020-11-17)
* Updated both the Android and iOS SDK to 9.0.0
* On iOS, cocoapods 1.10 is required to install the iOS SDK correctly.
diff --git a/Example/www/index.html b/Example/www/index.html
index cd72261c..245170ca 100644
--- a/Example/www/index.html
+++ b/Example/www/index.html
@@ -14,9 +14,14 @@
Login
Logout
Open Intercom
- Open Help Center
Display Carousel
Display Article
+ Open Help Center
+ Open Filtered Help Center
+ Help Center Data API
+ Fetch collections
+ Fetch collection content
+ Search help center
diff --git a/Example/www/js/index.js b/Example/www/js/index.js
index 3e1f7fd5..98418d40 100644
--- a/Example/www/js/index.js
+++ b/Example/www/js/index.js
@@ -62,6 +62,46 @@ var app = {
intercom.displayHelpCenter();
}, false);
+ document.getElementById("open-help-center-filtered-btn").addEventListener("click", function(){
+ // Replace this with your own collections
+ var ids = ["COLLECTION_ID1", "COLLECTION_ID2"];
+ intercom.displayHelpCenterCollections({collectionIds: ids});
+ }, false);
+
+ document.getElementById("help-center-data-api-fetch-btn").addEventListener("click", function(){
+ var onSuccess = function(data) {
+ console.log('Successfully fetched collections : ' + data);
+ }
+ var onError = function(code) {
+ console.log('Failed to fetch collections with code :' + data);
+ }
+ intercom.fetchHelpCenterCollections(onSuccess, onError);
+ }, false);
+
+ document.getElementById("help-center-data-api-fetch-content-btn").addEventListener("click", function(){
+ // Add your collection Id here
+ var collectionId = "COLLECTION_ID"
+ var onSuccess = function(data) {
+ console.log('Successfully fetched collection content : ' + data);
+ }
+ var onError = function(code) {
+ console.log('Failed to fetch collection content with code :' + data);
+ }
+ intercom.fetchHelpCenterCollection(collectionId, onSuccess, onError);
+ }, false);
+
+ document.getElementById("help-center-data-api-search-btn").addEventListener("click", function(){
+ // Add your search term here
+ var searchTerm = "SEARCH_TERM"
+ var onSuccess = function(data) {
+ console.log('Successfully searched help center : ' + data);
+ }
+ var onError = function(code) {
+ console.log('Failed to search help center with code :' + data);
+ }
+ intercom.searchHelpCenter(searchTerm, onSuccess, onError);
+ }, false);
+
document.getElementById("display-carousel-btn").addEventListener("click", function(){
intercom.displayCarousel("carousel-id");
}, false);
diff --git a/README.md b/README.md
index f44bf0d1..33538da8 100644
--- a/README.md
+++ b/README.md
@@ -45,7 +45,7 @@ cordova plugin add cordova-plugin-intercom
To add the plugin to your PhoneGap app, add the following to your `config.xml`:
```xml
-
+
```
## Example App
diff --git a/circle.yml b/circle.yml
index f6bf995f..3d7625b9 100644
--- a/circle.yml
+++ b/circle.yml
@@ -38,6 +38,7 @@ jobs:
- run:
name: Install node/npm
command: |
+ curl -O https://packages.cloud.google.com/apt/doc/apt-key.gpg && sudo apt-key add apt-key.gpg
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt install -y nodejs
- run:
@@ -64,6 +65,7 @@ jobs:
- run:
name: Install node/npm
command: |
+ curl -O https://packages.cloud.google.com/apt/doc/apt-key.gpg && sudo apt-key add apt-key.gpg
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt install -y nodejs
- run:
diff --git a/intercom-plugin/package.json b/intercom-plugin/package.json
index 9c7a0cf7..14fe09da 100644
--- a/intercom-plugin/package.json
+++ b/intercom-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-intercom",
- "version": "9.4.0",
+ "version": "10.0.0",
"description": "Official Cordova/PhoneGap plugin for Intercom",
"cordova": {
"id": "cordova-plugin-intercom",
diff --git a/intercom-plugin/plugin.xml b/intercom-plugin/plugin.xml
index 5b2127c4..edbb7304 100644
--- a/intercom-plugin/plugin.xml
+++ b/intercom-plugin/plugin.xml
@@ -1,5 +1,5 @@
-
+
Intercom
Intercom
MIT License
@@ -26,6 +26,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -52,13 +62,16 @@
-
+
+
+
+
diff --git a/intercom-plugin/src/android/HelpCenterCollectionContentModel.java b/intercom-plugin/src/android/HelpCenterCollectionContentModel.java
new file mode 100644
index 00000000..f043e8f9
--- /dev/null
+++ b/intercom-plugin/src/android/HelpCenterCollectionContentModel.java
@@ -0,0 +1,28 @@
+package io.intercom.android.sdk;
+
+import java.util.List;
+
+import io.intercom.android.sdk.helpcenter.sections.HelpCenterArticle;
+import io.intercom.android.sdk.helpcenter.sections.HelpCenterSection;
+
+public class HelpCenterCollectionContentModel {
+ private String collectionId;
+ private List articles;
+ private List sections;
+ private String summary;
+ private String title;
+
+ public HelpCenterCollectionContentModel(
+ String collectionId,
+ List articles,
+ List sections,
+ String summary,
+ String title
+ ) {
+ this.collectionId = collectionId;
+ this.articles = articles;
+ this.sections = sections;
+ this.summary = summary;
+ this.title = title;
+ }
+}
diff --git a/intercom-plugin/src/android/HelpCenterCollectionModel.java b/intercom-plugin/src/android/HelpCenterCollectionModel.java
new file mode 100644
index 00000000..78cd7278
--- /dev/null
+++ b/intercom-plugin/src/android/HelpCenterCollectionModel.java
@@ -0,0 +1,17 @@
+package io.intercom.android.sdk;
+
+public class HelpCenterCollectionModel {
+ private String collectionId;
+ private String summary;
+ private String title;
+
+ public HelpCenterCollectionModel(
+ String collectionId,
+ String summary,
+ String title
+ ) {
+ this.collectionId = collectionId;
+ this.summary = summary;
+ this.title = title;
+ }
+}
diff --git a/intercom-plugin/src/android/HelpCenterCollectionSectionModel.java b/intercom-plugin/src/android/HelpCenterCollectionSectionModel.java
new file mode 100644
index 00000000..fe582abf
--- /dev/null
+++ b/intercom-plugin/src/android/HelpCenterCollectionSectionModel.java
@@ -0,0 +1,18 @@
+package io.intercom.android.sdk;
+
+import java.util.List;
+
+import io.intercom.android.sdk.helpcenter.sections.HelpCenterArticle;
+
+class HelpCenterCollectionSectionModel {
+ private List articles;
+ private String title;
+
+ public HelpCenterCollectionSectionModel(
+ List articles,
+ String title
+ ) {
+ this.articles = articles;
+ this.title = title;
+ }
+}
\ No newline at end of file
diff --git a/intercom-plugin/src/android/IntercomBridge.java b/intercom-plugin/src/android/IntercomBridge.java
index a4ac1ff8..45404534 100644
--- a/intercom-plugin/src/android/IntercomBridge.java
+++ b/intercom-plugin/src/android/IntercomBridge.java
@@ -4,10 +4,13 @@
import android.content.Intent;
import android.util.Log;
+import com.google.gson.Gson;
+
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
+import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -18,12 +21,19 @@
import java.util.Map;
import io.intercom.android.sdk.Intercom.Visibility;
-import io.intercom.android.sdk.R;
import io.intercom.android.sdk.api.CordovaHeaderInterceptor;
import io.intercom.android.sdk.api.UserUpdateRequest;
+import io.intercom.android.sdk.helpcenter.api.CollectionContentRequestCallback;
+import io.intercom.android.sdk.helpcenter.api.CollectionRequestCallback;
+import io.intercom.android.sdk.helpcenter.api.HelpCenterArticleSearchResult;
+import io.intercom.android.sdk.helpcenter.api.SearchRequestCallback;
+import io.intercom.android.sdk.helpcenter.collections.HelpCenterCollection;
+import io.intercom.android.sdk.helpcenter.sections.HelpCenterCollectionContent;
+import io.intercom.android.sdk.helpcenter.sections.HelpCenterSection;
import io.intercom.android.sdk.identity.Registration;
import io.intercom.android.sdk.logger.LumberMill;
import io.intercom.android.sdk.push.IntercomPushClient;
+
public class IntercomBridge extends CordovaPlugin {
private static final String CUSTOM_ATTRIBUTES = "custom_attributes";
@@ -60,7 +70,7 @@ private void setUpIntercom() {
try {
Context context = cordova.getActivity().getApplicationContext();
- CordovaHeaderInterceptor.setCordovaVersion(context, "9.0.0");
+ CordovaHeaderInterceptor.setCordovaVersion(context, "10.0.0");
switch (IntercomPushManager.getInstalledModuleType()) {
case FCM: {
@@ -197,6 +207,116 @@ private enum Action {
callbackContext.success();
}
},
+ displayHelpCenterCollections {
+ @Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
+ JSONArray jsonArray = args.optJSONObject(0).optJSONArray("collectionIds");
+ ArrayList filterIds = new ArrayList<>();
+ for (int i = 0; jsonArray != null && i < jsonArray.length(); i++) {
+ try {
+ if(jsonArray.get(i) instanceof String) {
+ filterIds.add(jsonArray.get(i).toString());
+ }
+ } catch (Exception ignored) {}
+ }
+ Intercom.client().displayHelpCenterCollections(filterIds);
+ callbackContext.success();
+ }
+ },
+ fetchHelpCenterCollections {
+ @Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
+ Intercom.client().fetchHelpCenterCollections(new CollectionRequestCallback() {
+ @Override
+ public void onComplete(@NotNull List list) {
+ ArrayList responseModel = new ArrayList<>();
+ for (HelpCenterCollection helpCenterCollection : list) {
+ String summary = helpCenterCollection.getSummary();
+ if (summary.isEmpty()) {
+ summary = null;
+ }
+ responseModel.add(
+ new HelpCenterCollectionModel(
+ helpCenterCollection.getId(),
+ summary,
+ helpCenterCollection.getTitle()
+ )
+ );
+ }
+ String json = new Gson().toJson(responseModel);
+ callbackContext.success(json);
+ }
+
+ @Override
+ public void onError(int i) {
+ callbackContext.error(i);
+ }
+
+ @Override
+ public void onFailure() {
+ callbackContext.error("");
+ }
+ });
+ }
+ },
+ fetchHelpCenterCollection {
+ @Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
+ String collectionId = args.optString(0);
+ Intercom.client().fetchHelpCenterCollection(collectionId, new CollectionContentRequestCallback() {
+ @Override
+ public void onComplete(@NotNull HelpCenterCollectionContent helpCenterCollectionContent) {
+ ArrayList sectionModels = new ArrayList<>();
+ for (HelpCenterSection helpCenterSection : helpCenterCollectionContent.getHelpCenterSections()) {
+ sectionModels.add(
+ new HelpCenterCollectionSectionModel(
+ helpCenterSection.getHelpCenterArticles(),
+ helpCenterSection.getTitle()
+ )
+ );
+ }
+ HelpCenterCollectionContentModel responseModel = new HelpCenterCollectionContentModel(
+ helpCenterCollectionContent.getCollectionId(),
+ helpCenterCollectionContent.getHelpCenterArticles(),
+ sectionModels,
+ helpCenterCollectionContent.getSummary(),
+ helpCenterCollectionContent.getTitle()
+ );
+ String json = new Gson().toJson(responseModel);
+ callbackContext.success(json);
+ }
+
+ @Override
+ public void onError(int i) {
+ callbackContext.error(i);
+ }
+
+ @Override
+ public void onFailure() {
+ callbackContext.error("");
+ }
+ });
+ }
+ },
+ searchHelpCenter {
+ @Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
+ String searchTerm = args.optString(0);
+ Intercom.client().searchHelpCenter(searchTerm, new SearchRequestCallback() {
+ @Override
+ public void onComplete(@NotNull List list) {
+ String json = new Gson().toJson(list);
+ callbackContext.success(json);
+ }
+
+ @Override
+ public void onError(int i) {
+ callbackContext.error(i);
+ }
+
+ @Override
+ public void onFailure() {
+ callbackContext.error("");
+ }
+ });
+ }
+ },
setLauncherVisibility {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
String visibilityString = args.optString(0);
@@ -221,7 +341,7 @@ private enum Action {
},
hideMessenger {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
- Intercom.client().hideMessenger();
+ Intercom.client().hideIntercom();
callbackContext.success();
}
},
@@ -280,7 +400,7 @@ public static Action fromString(String actionAsString) {
try {
action = valueOf(actionAsString);
} catch (NullPointerException ignored) {}
- catch (IllegalArgumentException ignored) {}
+ catch (IllegalArgumentException ignored) {}
return action;
}
diff --git a/intercom-plugin/src/android/intercom.gradle b/intercom-plugin/src/android/intercom.gradle
index e7afa87a..536d9393 100644
--- a/intercom-plugin/src/android/intercom.gradle
+++ b/intercom-plugin/src/android/intercom.gradle
@@ -28,10 +28,10 @@ repositories {
}
dependencies {
- implementation 'io.intercom.android:intercom-sdk-base:9.0.0'
+ implementation 'io.intercom.android:intercom-sdk-base:10.0.1'
if (pushType == 'fcm' || pushType == 'fcm-without-build-plugin') {
implementation 'com.google.firebase:firebase-messaging:20.+'
- implementation 'io.intercom.android:intercom-sdk-fcm:9.0.0'
+ implementation 'io.intercom.android:intercom-sdk-fcm:10.0.1'
}
}
diff --git a/intercom-plugin/src/ios/ICMHelpCenterArticle+DictionaryConversion.h b/intercom-plugin/src/ios/ICMHelpCenterArticle+DictionaryConversion.h
new file mode 100644
index 00000000..992c18bf
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterArticle+DictionaryConversion.h
@@ -0,0 +1,19 @@
+//
+// ICMHelpCenterArticle+DictionaryConversion.h
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "Intercom/Intercom.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ICMHelpCenterArticle (DictionaryConversion)
+
+- (NSDictionary *)toDictionary;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/intercom-plugin/src/ios/ICMHelpCenterArticle+DictionaryConversion.m b/intercom-plugin/src/ios/ICMHelpCenterArticle+DictionaryConversion.m
new file mode 100644
index 00000000..572b01bf
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterArticle+DictionaryConversion.m
@@ -0,0 +1,20 @@
+//
+// ICMHelpCenterArticle+DictionaryConversion.m
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "ICMHelpCenterArticle+DictionaryConversion.h"
+
+@implementation ICMHelpCenterArticle (DictionaryConversion)
+
+- (NSDictionary *)toDictionary {
+ NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
+ [dictionary setValue:self.articleId forKey:@"articleId"];
+ [dictionary setValue:self.title forKey:@"title"];
+ return [dictionary copy];
+}
+
+@end
diff --git a/intercom-plugin/src/ios/ICMHelpCenterArticleSearchResult+DictionaryConversion.h b/intercom-plugin/src/ios/ICMHelpCenterArticleSearchResult+DictionaryConversion.h
new file mode 100644
index 00000000..38626fd7
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterArticleSearchResult+DictionaryConversion.h
@@ -0,0 +1,19 @@
+//
+// ICMHelpCenterArticleSearchResult+DictionaryConversion.h
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "Intercom/Intercom.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ICMHelpCenterArticleSearchResult (DictionaryConversion)
+
+- (NSDictionary *)toDictionary;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/intercom-plugin/src/ios/ICMHelpCenterArticleSearchResult+DictionaryConversion.m b/intercom-plugin/src/ios/ICMHelpCenterArticleSearchResult+DictionaryConversion.m
new file mode 100644
index 00000000..21044b80
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterArticleSearchResult+DictionaryConversion.m
@@ -0,0 +1,22 @@
+//
+// ICMHelpCenterArticleSearchResult+DictionaryConversion.m
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "ICMHelpCenterArticleSearchResult+DictionaryConversion.h"
+
+@implementation ICMHelpCenterArticleSearchResult (DictionaryConversion)
+
+- (NSDictionary *)toDictionary {
+ NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
+ [dictionary setValue:self.articleId forKey:@"articleId"];
+ [dictionary setValue:self.title forKey:@"title"];
+ [dictionary setValue:self.summary forKey:@"summary"];
+ [dictionary setValue:self.matchingSnippet forKey:@"matchingSnippet"];
+ return [dictionary copy];
+}
+
+@end
diff --git a/intercom-plugin/src/ios/ICMHelpCenterCollection+DictionaryConversion.h b/intercom-plugin/src/ios/ICMHelpCenterCollection+DictionaryConversion.h
new file mode 100644
index 00000000..0b32030e
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterCollection+DictionaryConversion.h
@@ -0,0 +1,19 @@
+//
+// ICMHelpCenterCollection+DictionaryConversion.h
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ICMHelpCenterCollection (DictionaryConversion)
+
+- (NSMutableDictionary *)toDictionary;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/intercom-plugin/src/ios/ICMHelpCenterCollection+DictionaryConversion.m b/intercom-plugin/src/ios/ICMHelpCenterCollection+DictionaryConversion.m
new file mode 100644
index 00000000..27a83f2f
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterCollection+DictionaryConversion.m
@@ -0,0 +1,21 @@
+//
+// ICMHelpCenterCollection+DictionaryConversion.m
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "ICMHelpCenterCollection+DictionaryConversion.h"
+
+@implementation ICMHelpCenterCollection (DictionaryConversion)
+
+- (NSDictionary *)toDictionary {
+ NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
+ [dictionary setValue:self.collectionId forKey:@"collectionId"];
+ [dictionary setValue:self.title forKey:@"title"];
+ [dictionary setValue:self.summary forKey:@"summary"];
+ return [dictionary copy];
+}
+
+@end
diff --git a/intercom-plugin/src/ios/ICMHelpCenterCollectionContent+DictionaryConversion.h b/intercom-plugin/src/ios/ICMHelpCenterCollectionContent+DictionaryConversion.h
new file mode 100644
index 00000000..7cdc70db
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterCollectionContent+DictionaryConversion.h
@@ -0,0 +1,19 @@
+//
+// ICMHelpCenterCollectionContent+DictionaryConversion.h
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "Intercom/Intercom.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ICMHelpCenterCollectionContent (DictionaryConversion)
+
+- (NSDictionary *)toDictionary;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/intercom-plugin/src/ios/ICMHelpCenterCollectionContent+DictionaryConversion.m b/intercom-plugin/src/ios/ICMHelpCenterCollectionContent+DictionaryConversion.m
new file mode 100644
index 00000000..cb420bba
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterCollectionContent+DictionaryConversion.m
@@ -0,0 +1,38 @@
+//
+// ICMHelpCenterCollectionContent+DictionaryConversion.m
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "ICMHelpCenterSection+DictionaryConversion.h"
+#import "ICMHelpCenterArticle+DictionaryConversion.h"
+#import "ICMHelpCenterCollectionContent+DictionaryConversion.h"
+
+@implementation ICMHelpCenterCollectionContent (DictionaryConversion)
+
+- (NSDictionary *)toDictionary {
+ NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
+ [dictionary setValue:self.collectionId forKey:@"collectionId"];
+ [dictionary setValue:self.title forKey:@"title"];
+ [dictionary setValue:self.summary forKey:@"summary"];
+
+ NSMutableArray *arrayOfArticleDictionaries = [@[] mutableCopy];
+ for (ICMHelpCenterArticle *article in self.articles) {
+ NSDictionary *articleDictionary = [article toDictionary];
+ [arrayOfArticleDictionaries addObject:articleDictionary];
+ }
+ [dictionary setValue:arrayOfArticleDictionaries forKey:@"articles"];
+
+ NSMutableArray *arrayOfSectionDictionaries = [@[] mutableCopy];
+ for (ICMHelpCenterSection *section in self.sections) {
+ NSDictionary *sectionDictionary = [section toDictionary];
+ [arrayOfSectionDictionaries addObject:sectionDictionary];
+ }
+ [dictionary setValue:arrayOfSectionDictionaries forKey:@"sections"];
+
+ return [dictionary copy];
+}
+
+@end
diff --git a/intercom-plugin/src/ios/ICMHelpCenterSection+DictionaryConversion.h b/intercom-plugin/src/ios/ICMHelpCenterSection+DictionaryConversion.h
new file mode 100644
index 00000000..cec12ed1
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterSection+DictionaryConversion.h
@@ -0,0 +1,19 @@
+//
+// ICMHelpCenterSection+DictionaryConversion.h
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "Intercom/Intercom.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ICMHelpCenterSection (DictionaryConversion)
+
+- (NSDictionary *)toDictionary;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/intercom-plugin/src/ios/ICMHelpCenterSection+DictionaryConversion.m b/intercom-plugin/src/ios/ICMHelpCenterSection+DictionaryConversion.m
new file mode 100644
index 00000000..ce672013
--- /dev/null
+++ b/intercom-plugin/src/ios/ICMHelpCenterSection+DictionaryConversion.m
@@ -0,0 +1,28 @@
+//
+// ICMHelpCenterSection+DictionaryConversion.m
+// Sample
+//
+// Created by Michael McNamara on 25/06/2021.
+// Copyright © 2021 Intercom. All rights reserved.
+//
+
+#import "ICMHelpCenterSection+DictionaryConversion.h"
+#import "ICMHelpCenterArticle+DictionaryConversion.h"
+
+@implementation ICMHelpCenterSection (DictionaryConversion)
+
+- (NSDictionary *)toDictionary {
+ NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
+ [dictionary setValue:self.title forKey:@"title"];
+
+ NSMutableArray *arrayOfArticleDictionaries = [@[] mutableCopy];
+ for (ICMHelpCenterArticle *article in self.articles) {
+ NSDictionary *articleDictionary = [article toDictionary];
+ [arrayOfArticleDictionaries addObject:articleDictionary];
+ }
+ [dictionary setValue:arrayOfArticleDictionaries forKey:@"articles"];
+
+ return [dictionary copy];
+}
+
+@end
diff --git a/intercom-plugin/src/ios/IntercomBridge.h b/intercom-plugin/src/ios/IntercomBridge.h
index 00ac7c6c..6da093d3 100644
--- a/intercom-plugin/src/ios/IntercomBridge.h
+++ b/intercom-plugin/src/ios/IntercomBridge.h
@@ -20,10 +20,14 @@
- (void)displayMessageComposerWithInitialMessage:(CDVInvokedUrlCommand*)command;
- (void)displayConversationsList:(CDVInvokedUrlCommand*)command;
- (void)displayHelpCenter:(CDVInvokedUrlCommand*)command;
+- (void)displayHelpCenterCollections:(CDVInvokedUrlCommand*)command;
+- (void)fetchHelpCenterCollections:(CDVInvokedUrlCommand*)command;
+- (void)fetchHelpCenterCollection:(CDVInvokedUrlCommand*)command;
+- (void)searchHelpCenter:(CDVInvokedUrlCommand*)command;
- (void)setLauncherVisibility:(CDVInvokedUrlCommand*)command;
- (void)setInAppMessageVisibility:(CDVInvokedUrlCommand*)command;
-- (void)hideMessenger:(CDVInvokedUrlCommand*)command;
+- (void)hideIntercom:(CDVInvokedUrlCommand*)command;
- (void)registerForPush:(CDVInvokedUrlCommand*)command;
diff --git a/intercom-plugin/src/ios/IntercomBridge.m b/intercom-plugin/src/ios/IntercomBridge.m
index d71d3460..f16234b5 100644
--- a/intercom-plugin/src/ios/IntercomBridge.m
+++ b/intercom-plugin/src/ios/IntercomBridge.m
@@ -1,5 +1,8 @@
#import "IntercomBridge.h"
#import "AppDelegate+IntercomPush.h"
+#import "ICMHelpCenterCollection+DictionaryConversion.h"
+#import "ICMHelpCenterArticleSearchResult+DictionaryConversion.h"
+#import "ICMHelpCenterCollectionContent+DictionaryConversion.h"
#import
@interface Intercom (Cordoava)
@@ -114,8 +117,64 @@ - (void)displayHelpCenter:(CDVInvokedUrlCommand*)command {
[self sendSuccess:command];
}
-- (void)hideMessenger:(CDVInvokedUrlCommand*)command {
- [Intercom hideMessenger];
+- (void)displayHelpCenterCollections:(CDVInvokedUrlCommand*)command {
+ NSDictionary *args = command.arguments[0];
+ NSArray* collectionIds = args[@"collectionIds"];
+ [Intercom presentHelpCenterCollections:collectionIds];
+ [self sendSuccess:command];
+}
+
+- (void)fetchHelpCenterCollections:(CDVInvokedUrlCommand*)command {
+ [Intercom fetchHelpCenterCollectionsWithCompletion:^(NSArray * _Nullable collections, NSError * _Nullable error) {
+ if (error) {
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsNSInteger:error.code];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ } else {
+ NSMutableArray *array = [[NSMutableArray alloc] init];
+ for (ICMHelpCenterCollection *collection in collections) {
+ [array addObject:[collection toDictionary]];
+ }
+ NSString *jsonString = [self stringValueForDictionaries:(NSArray *)array];
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }
+ }];
+}
+
+- (void)fetchHelpCenterCollection:(CDVInvokedUrlCommand*)command {
+ NSString *collectionId = command.arguments[0];
+ [Intercom fetchHelpCenterCollection:collectionId withCompletion:^(ICMHelpCenterCollectionContent * _Nullable collectionContent, NSError * _Nullable error) {
+ if (error) {
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsNSInteger:error.code];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ } else {
+ NSString *jsonString = [self stringValueForDictionary:[collectionContent toDictionary]];
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }
+ }];
+}
+
+- (void)searchHelpCenter:(CDVInvokedUrlCommand*)command {
+ NSString *searchTerm = command.arguments[0];
+ [Intercom searchHelpCenter:searchTerm withCompletion:^(NSArray * _Nullable articleSearchResults, NSError * _Nullable error) {
+ if (error) {
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsNSInteger:error.code];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ } else {
+ NSMutableArray *array = [[NSMutableArray alloc] init];
+ for (ICMHelpCenterArticleSearchResult *articleSearchResult in articleSearchResults) {
+ [array addObject:[articleSearchResult toDictionary]];
+ }
+ NSString *jsonString = [self stringValueForDictionaries:(NSArray *)array];
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }
+ }];
+}
+
+- (void)hideIntercom:(CDVInvokedUrlCommand*)command {
+ [Intercom hideIntercom];
[self sendSuccess:command];
}
@@ -239,6 +298,31 @@ - (NSString *)stringValueForKey:(NSString *)key inDictionary:(NSDictionary *)dic
return nil;
}
+- (NSString *)stringValueForDictionaries:(NSArray *)dictionaries {
+ NSError *error;
+ NSString *jsonString;
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionaries options:0 error:&error];
+ if (!jsonData) {
+ NSLog(@"Got an error: %@", error);
+ } else {
+ jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+ }
+ return jsonString;
+}
+
+
+- (NSString *)stringValueForDictionary:(NSDictionary *)dictionary {
+ NSError *error;
+ NSString *jsonString;
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];
+ if (!jsonData) {
+ NSLog(@"Got an error: %@", error);
+ } else {
+ jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+ }
+ return jsonString;
+}
+
- (NSNumber *)numberValueForKey:(NSString *)key inDictionary:(NSDictionary *)dictionary {
NSNumber *value = dictionary[key];
if ([value isKindOfClass:[NSNumber class]]) {
diff --git a/intercom-plugin/www/intercom.js b/intercom-plugin/www/intercom.js
index f367b0ca..ec48a5dc 100644
--- a/intercom-plugin/www/intercom.js
+++ b/intercom-plugin/www/intercom.js
@@ -51,6 +51,22 @@ var intercom = {
cordova.exec(success, error, 'Intercom', 'displayHelpCenter', []);
},
+ fetchHelpCenterCollections: function(success, error) {
+ cordova.exec(success, error, 'Intercom', 'fetchHelpCenterCollections', []);
+ },
+
+ searchHelpCenter: function(searchTerm, success, error) {
+ cordova.exec(success, error, 'Intercom', 'searchHelpCenter', [searchTerm]);
+ },
+
+ fetchHelpCenterCollection: function(collectionId, success, error) {
+ cordova.exec(success, error, 'Intercom', 'fetchHelpCenterCollection', [collectionId]);
+ },
+
+ displayHelpCenterCollections: function(collectionIds, success, error) {
+ cordova.exec(success, error, 'Intercom', 'displayHelpCenterCollections', [collectionIds]);
+ },
+
unreadConversationCount: function(success, error) {
cordova.exec(success, error, 'Intercom', 'unreadConversationCount', []);
},
@@ -66,8 +82,8 @@ var intercom = {
cordova.exec(success, error, 'Intercom', 'setInAppMessageVisibility', [visibility]);
},
- hideMessenger: function(success, error) {
- cordova.exec(success, error, 'Intercom', 'hideMessenger', []);
+ hideIntercom: function(success, error) {
+ cordova.exec(success, error, 'Intercom', 'hideIntercom', []);
},
registerForPush: function(success, error) {