Skip to content

Commit 688bcd2

Browse files
Merge pull request #15 from intercom/feature/help-center-fetch-methods
Feature/help center fetch methods
2 parents b36a277 + 4d29665 commit 688bcd2

File tree

12 files changed

+357
-115
lines changed

12 files changed

+357
-115
lines changed

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Push Notifications](#ios-push-notifications)
2424
- [Push notification deep links support](#ios-push-notification-deep-links-support)
2525
- [Common methods](#methods)
26+
- [Types](#types)
2627
- [Usage](#usage)
2728
- [Troubleshooting](#troubleshooting)
2829
- [Author](#author)
@@ -684,6 +685,46 @@ Present the help center with specific collections only .
684685

685686
`Promise<boolean>`
686687

688+
___
689+
### `Intercom.fetchHelpCenterCollections()`
690+
691+
Fetch a list of all Collections.
692+
693+
694+
### Returns
695+
`Promise<HelpCenterCollectionItem[]>`
696+
697+
698+
___
699+
### `Intercom.fetchHelpCenterCollection(collectionId)`
700+
701+
Get a list of sections/articles for a collection.
702+
703+
### Options
704+
705+
| Type | Type | Required |
706+
| ------- | -------- | -------- |
707+
| collectionId| string |yes |
708+
709+
### Returns
710+
711+
`Promise<HelpCenterCollectionContent>`
712+
713+
___
714+
### `Intercom.searchHelpCenter(searchTerm)`
715+
716+
Get a list of articles in the Help Center, filtered by a search term
717+
718+
### Options
719+
720+
| Type | Type | Required |
721+
| ------- | -------- | -------- |
722+
| searchTerm| string |yes |
723+
724+
### Returns
725+
726+
`Promise<HelpCenterArticleSearchResult[]>`
727+
687728
___
688729
### `Intercom.displayArticle(articleId)`
689730

@@ -827,6 +868,41 @@ useEffect(() => {
827868
828869
`EmitterSubscription`
829870
871+
___
872+
### Types
873+
874+
```typescript
875+
type HelpCenterArticle = {
876+
it: string;
877+
title: string;
878+
};
879+
880+
type HelpCenterSection = {
881+
name: string;
882+
articles: HelpCenterArticle;
883+
};
884+
885+
type HelpCenterCollectionItem = {
886+
id: string;
887+
title: string;
888+
summary: string;
889+
};
890+
891+
type HelpCenterCollectionContent = {
892+
id: string;
893+
name: string;
894+
summary: string;
895+
articles: HelpCenterArticle[];
896+
sections: HelpCenterSection[];
897+
};
898+
899+
type HelpCenterArticleSearchResult = {
900+
id: string;
901+
title: string;
902+
matchingSnippet: string;
903+
summary: string;
904+
};
905+
```
830906
___
831907
832908
## Usage

android/src/main/java/com/intercom/reactnative/IntercomModule.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public void onFailure() {
332332
@ReactMethod
333333
public void fetchHelpCenterCollection(String collectionId, Promise promise) {
334334
try {
335-
if (collectionId.equals("") ) {
335+
if (collectionId.equals("")) {
336336
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTION, "collectionID can\'t be empty");
337337
} else {
338338
CollectionContentRequestCallback collectionContentCallback = new CollectionContentRequestCallback() {
@@ -366,33 +366,36 @@ public void onFailure() {
366366

367367
@ReactMethod
368368
public void searchHelpCenter(String searchTerm, Promise promise) {
369-
try {
370-
371-
SearchRequestCallback collectionContentCallback = new SearchRequestCallback() {
372-
@Override
373-
public void onComplete(@NotNull List<HelpCenterArticleSearchResult> helpCenterArticleSearchResult) {
374-
promise.resolve(IntercomHelpCenterHelpers.parseHelpCenterArticleSearchToReadableArray(helpCenterArticleSearchResult));
375-
}
369+
if (searchTerm.equals("")) {
370+
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, "searchTerm can\'t be empty");
371+
} else {
372+
try {
373+
SearchRequestCallback collectionContentCallback = new SearchRequestCallback() {
374+
@Override
375+
public void onComplete(@NotNull List<HelpCenterArticleSearchResult> helpCenterArticleSearchResult) {
376+
promise.resolve(IntercomHelpCenterHelpers.parseHelpCenterArticleSearchToReadableArray(helpCenterArticleSearchResult));
377+
}
376378

377-
@Override
378-
public void onError(int i) {
379-
Log.e(NAME, "searchHelpCenter error");
380-
promise.reject(String.valueOf(i), "searchHelpCenter error");
381-
}
379+
@Override
380+
public void onError(int i) {
381+
Log.e(NAME, "searchHelpCenter error");
382+
promise.reject(String.valueOf(i), "searchHelpCenter error");
383+
}
382384

383-
@Override
384-
public void onFailure() {
385-
Log.e(NAME, "searchHelpCenter failure");
386-
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, "searchHelpCenter failure");
387-
}
388-
};
389-
Log.d(NAME, "searchHelpCenter");
390-
Intercom.client().searchHelpCenter(searchTerm, collectionContentCallback);
385+
@Override
386+
public void onFailure() {
387+
Log.e(NAME, "searchHelpCenter failure");
388+
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, "searchHelpCenter failure");
389+
}
390+
};
391+
Log.d(NAME, "searchHelpCenter");
392+
Intercom.client().searchHelpCenter(searchTerm, collectionContentCallback);
391393

392-
} catch (Exception err) {
393-
Log.e(NAME, "searchHelpCenter error:");
394-
Log.e(NAME, err.toString());
395-
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, err.toString());
394+
} catch (Exception err) {
395+
Log.e(NAME, "searchHelpCenter error:");
396+
Log.e(NAME, err.toString());
397+
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, err.toString());
398+
}
396399
}
397400
}
398401

example/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ CAROUSEL_ID=$CAROUSEL_ID
66
EVENT_NAME=$EVENT_NAME
77
ARTICLE_ID=$ARTICLE_ID
88
USER_NAME=$USER_NAME
9-
SECTION_ID=$SECTION_ID
9+
COLLECTION_ID=$COLLECTION_ID
1010
SEARCH_TERM=$SEARCH_TERM

example/ios/IntercomReactNativeExample/Info.plist

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>NSPhotoLibraryUsageDescription</key>
6-
<string>Send photos to support center</string>
75
<key>CFBundleDevelopmentRegion</key>
86
<string>en</string>
97
<key>CFBundleDisplayName</key>
@@ -37,6 +35,10 @@
3735
</array>
3836
<key>CFBundleVersion</key>
3937
<string>1</string>
38+
<key>IntercomUniversalLinkDomains</key>
39+
<array>
40+
<string>intercom.com</string>
41+
</array>
4042
<key>LSRequiresIPhoneOS</key>
4143
<true/>
4244
<key>NSAppTransportSecurity</key>
@@ -54,6 +56,8 @@
5456
</dict>
5557
<key>NSLocationWhenInUseUsageDescription</key>
5658
<string></string>
59+
<key>NSPhotoLibraryUsageDescription</key>
60+
<string>Send photos to support center</string>
5761
<key>UIBackgroundModes</key>
5862
<array>
5963
<string>remote-notification</string>

example/scripts/generateEnv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ echo EVENT_NAME=$EVENT_NAME >>.env
99
echo ARTICLE_ID=$ARTICLE_ID >>.env
1010
echo USER_NAME=$USER_NAME >>.env
1111
echo SEARCH_TERM=$SEARCH_TERM >>.env
12-
echo SECTION_ID=$SECTION_ID >>.env
12+
echo COLLECTION_ID=$COLLECTION_ID >>.env

ios/Intercom.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
3A6572C897F85E4E8295FC2D /* IntercomEventEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A657CFB9FBFC5F094B4D20D /* IntercomEventEmitter.m */; };
1111
3A6576B390F8276AE2651D35 /* IntercomAttributesBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A6576960DB107666B27C442 /* IntercomAttributesBuilder.m */; };
1212
7D72E2FD26611EAB00A3C250 /* IntercomModule.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* IntercomModule.m */; };
13+
7DAD57C02683B5B5001B040A /* IntercomHelpCenterHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD57BF2683B5B5001B040A /* IntercomHelpCenterHelpers.m */; };
1314
/* End PBXBuildFile section */
1415

1516
/* Begin PBXCopyFilesBuildPhase section */
@@ -30,6 +31,8 @@
3031
3A65761B82D336291D470582 /* IntercomEventEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntercomEventEmitter.h; sourceTree = "<group>"; };
3132
3A6576960DB107666B27C442 /* IntercomAttributesBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IntercomAttributesBuilder.m; sourceTree = "<group>"; };
3233
3A657CFB9FBFC5F094B4D20D /* IntercomEventEmitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IntercomEventEmitter.m; sourceTree = "<group>"; };
34+
7DAD57BF2683B5B5001B040A /* IntercomHelpCenterHelpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IntercomHelpCenterHelpers.m; sourceTree = "<group>"; };
35+
7DAD57C22683B5F0001B040A /* IntercomHelpCenterHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IntercomHelpCenterHelpers.h; sourceTree = "<group>"; };
3336
B3E7B5881CC2AC0600A0062D /* IntercomModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntercomModule.h; sourceTree = "<group>"; };
3437
B3E7B5891CC2AC0600A0062D /* IntercomModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IntercomModule.m; sourceTree = "<group>"; };
3538
/* End PBXFileReference section */
@@ -56,6 +59,8 @@
5659
58B511D21A9E6C8500147676 = {
5760
isa = PBXGroup;
5861
children = (
62+
7DAD57BF2683B5B5001B040A /* IntercomHelpCenterHelpers.m */,
63+
7DAD57C22683B5F0001B040A /* IntercomHelpCenterHelpers.h */,
5964
7D92790D26829806009550EB /* assets */,
6065
B3E7B5881CC2AC0600A0062D /* IntercomModule.h */,
6166
B3E7B5891CC2AC0600A0062D /* IntercomModule.m */,
@@ -131,6 +136,7 @@
131136
isa = PBXSourcesBuildPhase;
132137
buildActionMask = 2147483647;
133138
files = (
139+
7DAD57C02683B5B5001B040A /* IntercomHelpCenterHelpers.m in Sources */,
134140
7D72E2FD26611EAB00A3C250 /* IntercomModule.m in Sources */,
135141
3A6576B390F8276AE2651D35 /* IntercomAttributesBuilder.m in Sources */,
136142
3A6572C897F85E4E8295FC2D /* IntercomEventEmitter.m in Sources */,

ios/IntercomAttributesBuilder.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#import <Foundation/Foundation.h>
2-
3-
@class ICMUserAttributes;
4-
2+
#import <Intercom/Intercom.h>
53

64
@interface IntercomAttributesBuilder : NSObject
75
+ (ICMUserAttributes *)userAttributesForDictionary:(NSDictionary *)attributesDict;
8-
@end
6+
@end

ios/IntercomHelpCenterHelpers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import <Foundation/Foundation.h>
2+
#import <Intercom/Intercom.h>
3+
4+
@interface IntercomHelpCenterHelpers : NSObject
5+
+ (NSMutableArray<NSMutableDictionary *> *)parseCollectionsToArray:(NSArray<ICMHelpCenterCollection *> *)collections;
6+
+ (NSMutableArray<NSMutableDictionary *> *)parseArticlesToArray:(NSArray<ICMHelpCenterArticle *> *)articlesArray;
7+
+ (NSMutableDictionary *)parseHelpCenterCollectionToDictionary:(ICMHelpCenterCollectionContent *)collectionContent;
8+
+ (NSMutableArray<NSMutableDictionary *> *)parseHelpCenterSectionsToDictionary:(NSArray<ICMHelpCenterSection *> *)sectionArray;
9+
+ (NSMutableArray<NSMutableDictionary *> *)parseHelpCenterArticleSearchResultToArray:(NSArray<ICMHelpCenterArticleSearchResult *>*)articleArray;
10+
11+
@end

ios/IntercomHelpCenterHelpers.m

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#import "IntercomHelpCenterHelpers.h"
2+
#import <Intercom/Intercom.h>
3+
4+
@implementation IntercomHelpCenterHelpers
5+
6+
+ (NSMutableArray<NSMutableDictionary *> *)parseCollectionsToArray:(NSArray<ICMHelpCenterCollection *> *)collections {
7+
NSMutableArray<NSMutableDictionary *> *parsedCollections = [NSMutableArray arrayWithCapacity:[collections count]];
8+
9+
for (ICMHelpCenterCollection *collectionObject in collections) {
10+
NSMutableDictionary *item = [NSMutableDictionary dictionary];
11+
[item setValue:[collectionObject collectionId] forKey:@"id"];
12+
[item setValue:[collectionObject title] forKey:@"title"];
13+
[item setValue:[collectionObject summary] forKey:@"summary"];
14+
[parsedCollections addObject:item];
15+
}
16+
return parsedCollections;
17+
}
18+
19+
+ (NSMutableArray<NSMutableDictionary *> *)parseArticlesToArray:(NSArray<ICMHelpCenterArticle *> *)articlesArray {
20+
21+
NSMutableArray *parsedArticles = [NSMutableArray arrayWithCapacity:[articlesArray count]];
22+
for (ICMHelpCenterArticle *articleObject in articlesArray) {
23+
NSMutableDictionary *articleItem = [NSMutableDictionary dictionary];
24+
[articleItem setValue:[articleObject articleId] forKey:@"id"];
25+
[articleItem setValue:[articleObject title] forKey:@"title"];
26+
[parsedArticles addObject:articleItem];
27+
}
28+
29+
return parsedArticles;
30+
}
31+
32+
+ (NSMutableDictionary *)parseHelpCenterCollectionToDictionary:(ICMHelpCenterCollectionContent *)collectionContent {
33+
34+
NSMutableDictionary *item = [NSMutableDictionary dictionary];
35+
[item setValue:[collectionContent collectionId] forKey:@"id"];
36+
[item setValue:[collectionContent title] forKey:@"title"];
37+
[item setValue:[collectionContent summary] forKey:@"summary"];
38+
[item setValue:[self parseArticlesToArray:[collectionContent articles]] forKey:@"articles"];
39+
[item setValue:[self parseHelpCenterSectionsToDictionary:[collectionContent sections]] forKey:@"sections"];
40+
41+
return item;
42+
}
43+
44+
+ (NSMutableArray<NSMutableDictionary *> *)parseHelpCenterSectionsToDictionary:(NSArray<ICMHelpCenterSection *> *)sectionArray {
45+
46+
NSMutableArray *parsedSections = [NSMutableArray arrayWithCapacity:[sectionArray count]];
47+
for (ICMHelpCenterSection *sectionObject in sectionArray) {
48+
NSMutableDictionary *sectionItem = [NSMutableDictionary dictionary];
49+
[sectionItem setValue:[sectionObject title] forKey:@"title"];
50+
[sectionItem setValue:[self parseArticlesToArray:[sectionObject articles]] forKey:@"articles"];
51+
[parsedSections addObject:sectionItem];
52+
}
53+
54+
return parsedSections;
55+
}
56+
57+
+ (NSMutableArray<NSMutableDictionary *> *)parseHelpCenterArticleSearchResultToArray:(NSArray<ICMHelpCenterArticleSearchResult *>*)articleArray {
58+
59+
NSMutableArray *parsedArticles = [NSMutableArray arrayWithCapacity:[articleArray count]];
60+
for (ICMHelpCenterArticleSearchResult *articleObject in articleArray) {
61+
NSMutableDictionary *articleItem = [NSMutableDictionary dictionary];
62+
[articleItem setValue:[articleObject title] forKey:@"title"];
63+
[articleItem setValue:[articleObject articleId] forKey:@"id"];
64+
[articleItem setValue:[articleObject matchingSnippet] forKey:@"matchingSnippet"];
65+
[articleItem setValue:[articleObject summary] forKey:@"summary"];
66+
[parsedArticles addObject:articleItem];
67+
}
68+
69+
return parsedArticles;
70+
}
71+
72+
73+
@end
74+

ios/IntercomModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
+ (void)setDeviceToken:(nonnull NSString *)deviceToken;
66
+ (BOOL)isIntercomPushNotification:(nonnull NSDictionary *)userInfo;
77
+ (void)handleIntercomPushNotification:(nonnull NSDictionary *)userInfo;
8-
+ (NSError *)exceptionToError:(NSException *)exception :(NSString *)code;
8+
- (NSError *)exceptionToError:(NSException *)exception :(NSString *)code :(NSString *)domain;
99

1010
@end

0 commit comments

Comments
 (0)