Skip to content

Commit 7953d10

Browse files
authored
Update plugin for new Intercom Messenger (#62)
* Update plugin for new Intercom Messenger * Update CHANGELOG.md
1 parent 03a1195 commit 7953d10

File tree

155 files changed

+2036
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+2036
-339
lines changed

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Intercom for Cordova/PhoneGap
22

3+
# 3.0.0 (2016-07-26)
4+
5+
Where is 2.x? We're skipping it. We did this to align the Cordova plugin with our iOS, Android and web counter parts.
6+
7+
Our new Messenger is out of beta! 🎉 You can read all about the updated design and new functionality [here](https://www.intercom.io/in-app-messaging).
8+
9+
* Updated Intercom for iOS to [3.0.3](https://github.com/intercom/intercom-ios/releases/tag/3.0.3).
10+
* Updated Intercom for Android to [3.0.2](https://github.com/intercom/intercom-android/releases/tag/3.0.2).
11+
12+
Added the following methods:
13+
* `intercom.displayMessenger()`
14+
* `intercom.setLauncherVisibility(visibility)`
15+
* `intercom.setInAppMessageVisibility(visibility)`
16+
* `intercom.unreadConversationCount()`
17+
18+
Removed these methods:
19+
* `intercom.setVisibility(visibility)`
20+
* `intercom.setupGCM()`
21+
* `intercom.openGCMMessage()`
22+
* `intercom.setupAPN(token)`
23+
* `intercom.setPreviewPosition(position)`
24+
* `intercom.setPreviewPadding()`
25+
326
# 1.1.7 (2016-06-02)
427

528
* Fixed Android crash reported in [#55](https://github.com/intercom/intercom-cordova/issues/55).
@@ -72,4 +95,4 @@
7295

7396
## 1.0.0 (2015-05-25)
7497

75-
* Initial release of the Intercom plugin for Cordova and PhoneGap.
98+
* Initial release of the Intercom plugin for Cordova and PhoneGap.

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To install the plugin in your Cordova app, run the following:
1818

1919
To add the plugin to your PhoneGap app, add the following to your `config.xml`:
2020

21-
<plugin name="cordova-plugin-intercom" version="~1.1.7" />
21+
<plugin name="cordova-plugin-intercom" version="~3.0.0" />
2222

2323
## Configuring Intercom
2424

@@ -145,11 +145,9 @@ Because Intercom listens for life cycle events, there is no need to have this li
145145

146146
## How does the in-app messenger work?
147147

148-
Intercom allows you to send messages to your users while also enabling your users send messages to you. If you have a dedicated button in your app that you wish to hook the new message composer up to, you can control Intercom's messaging UI via the `intercom.displayMessageComposer();` and `intercom.displayConversationsList();` methods.
148+
Intercom allows you to send messages to your users while also enabling your users send messages to you. If you have a dedicated button in your app that you wish to hook the new message composer up to, you can control Intercom's messaging UI via the `intercom.displayMessenger()`, `intercom.displayMessageComposer();`, `intercom.displayConversationsList();` methods.
149149

150-
The position of the message preview can be configured using `intercom.setPreviewPosition(intercom.BOTTOM_RIGHT);`. The possible values are `intercom.BOTTOM_LEFT`, `intercom.BOTTOM_RIGHT`, `intercom.TOP_RIGHT` and `intercom.TOP_LEFT`.
151-
152-
If there is an area of your app where you do not wish your users to receive Intercom messages, you can call `intercom.setVisibility(intercom.GONE);`. To re-enable messages, call `intercom.setVisibility(intercom.VISIBLE);`.
150+
If there is an area of your app where you do not wish your users to receive Intercom messages, you can call `intercom.setInAppMessageVisibility(intercom.GONE);`. To re-enable messages, call `intercom.setInAppMessageVisibility(intercom.VISIBLE);`.
153151

154152
## Updating a user
155153

@@ -191,7 +189,11 @@ Intercom for mobile supports Push Notifications on iOS and Google Cloud Messagin
191189

192190
To enable iOS push notifications, simply call `intercom.registerForPush()`.
193191

194-
To enable Android push notifications, call `intercom.registerForPush('sender_id')`. Where `sender_id` is your [Sender ID](https://developers.google.com/cloud-messaging/gcm#senderid) from the Google Developer Console.
192+
To enable Android push notifications, your [Sender ID](https://developers.google.com/cloud-messaging/gcm#senderid) to your app's `config.xml` as follows:
193+
194+
```
195+
<preference name="intercom-android-sender-id" value="YOUR_SENDER_ID"/>
196+
```
195197

196198
**Note:** _If you use [phonegap-plugin-push](https://github.com/phonegap/phonegap-plugin-push) to support non Intercom push notifications in addition to Intercom's notifications, you must use our fork which is available [here](https://github.com/intercom/phonegap-plugin-push). Install it with: `cordova plugin add https://github.com/intercom/phonegap-plugin-push.git`. We know this is not ideal but unfortunately it is necessary due to the inflexible nature of PushPlugin._
197199

@@ -209,4 +211,4 @@ intercom-cordova is released under the [MIT License](http://www.opensource.org/l
209211

210212
## Copyright
211213

212-
Copyright (c) 2015, Inc. All rights reserved.
214+
Copyright (c) 2016, Inc. All rights reserved.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-intercom",
3-
"version": "1.1.7",
3+
"version": "3.0.0",
44
"description": "Official Cordova/PhoneGap plugin for Intercom",
55
"cordova": {
66
"id": "cordova-plugin-intercom",

plugin.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<plugin id="cordova-plugin-intercom" version="1.1.7" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
2+
<plugin id="cordova-plugin-intercom" version="3.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
33
<name>Intercom</name>
44
<author>Intercom</author>
55
<license>MIT License</license>
@@ -32,9 +32,8 @@
3232
</feature>
3333
</config-file>
3434

35-
<header-file src="src/ios/Intercom.framework/Versions/A/Headers/Intercom.h" />
36-
<source-file src="src/ios/Intercom.framework/Versions/A/Intercom" framework="true" />
37-
<resource-file src="src/ios/Intercom.bundle" />
35+
<framework src="src/ios/Intercom.framework" custom="true" />
36+
<resource-file src="src/ios/Intercom.framework/Resources/Intercom.bundle" />
3837

3938
<framework src="Foundation.framework" />
4039
<framework src="UIKit.framework" />
@@ -52,9 +51,9 @@
5251

5352
<platform name="android">
5453
<source-file src="src/android/IntercomBridge.java" target-dir="src/io/intercom/android/sdk" />
55-
<source-file src="src/android/IntercomGCMManager.java" target-dir="src/io/intercom/android/sdk" />
54+
<source-file src="src/android/CordovaHeaderInterceptor.java" target-dir="src/io/intercom/android/sdk" />
55+
5656
<framework src="src/android/intercom.gradle" custom="true" type="gradleReference" />
57-
<framework src="com.google.android.gms:play-services-gcm:8.+" />
5857
<framework src="src/android/build-extras-intercom.gradle" custom="true" type="gradleReference" />
5958

6059
<config-file target="res/xml/config.xml" parent="/*">
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.intercom.android.sdk.api;
2+
import android.content.Context;
3+
4+
public class CordovaHeaderInterceptor {
5+
public static void setCordovaVersion(Context context, String cordovaVersion) {
6+
HeaderInterceptor.setCordovaVersion(context, cordovaVersion);
7+
}
8+
}

src/android/IntercomBridge.java

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import android.os.Build;
1919

2020
import io.intercom.android.sdk.identity.Registration;
21-
import io.intercom.android.sdk.preview.IntercomPreviewPosition;
22-
import io.intercom.android.sdk.api.HeaderInterceptor;
21+
import io.intercom.android.sdk.api.CordovaHeaderInterceptor;
22+
23+
import io.intercom.android.sdk.Gcm;
24+
import io.intercom.android.sdk.Intercom.Visibility;
2325

2426
import java.util.Map;
2527
import java.util.HashMap;
@@ -33,8 +35,8 @@ public class IntercomBridge extends CordovaPlugin {
3335
cordova.getActivity().runOnUiThread(new Runnable() {
3436
@Override public void run() {
3537
setUpIntercom();
36-
if (Bridge.getApi() != null) {
37-
Bridge.getApi().ping();
38+
if (Injector.get().getApi() != null) {
39+
Injector.get().getApi().ping();
3840
}
3941
}
4042
});
@@ -46,9 +48,7 @@ public class IntercomBridge extends CordovaPlugin {
4648
//We also initialize intercom here just in case it has died. If Intercom is already set up, this won't do anything.
4749
setUpIntercom();
4850

49-
if (Intercom.client().openGCMMessage(cordova.getActivity().getIntent().getData())) {
50-
cordova.getActivity().getIntent().setData(null);
51-
}
51+
Intercom.client().openGcmMessage();
5252
}
5353
});
5454
}
@@ -60,8 +60,13 @@ public class IntercomBridge extends CordovaPlugin {
6060
private void setUpIntercom() {
6161
try {
6262
Context context = IntercomBridge.this.cordova.getActivity().getApplicationContext();
63+
64+
CordovaHeaderInterceptor.setCordovaVersion(context, "3.0.0");
6365

64-
HeaderInterceptor.setCordovaVersion(context, "1.1.7");
66+
String senderId = IntercomBridge.this.preferences.getString("intercom-android-sender-id", null);
67+
if (senderId != null) {
68+
Gcm.cacheSenderId(context, senderId);
69+
}
6570

6671
ApplicationInfo app = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
6772
Bundle bundle = app.metaData;
@@ -127,80 +132,62 @@ private enum Action {
127132
callbackContext.success();
128133
}
129134
},
130-
displayMessageComposer {
135+
unreadConversationCount {
131136
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
132-
Intercom.client().displayMessageComposer();
137+
int count = Intercom.client().getUnreadConversationCount();
138+
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, count));
139+
}
140+
},
141+
displayMessenger {
142+
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
143+
Intercom.client().displayMessenger();
133144
callbackContext.success();
134145
}
135146
},
136-
displayConversationsList {
147+
displayMessageComposer {
137148
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
138-
Intercom.client().displayConversationsList();
149+
Intercom.client().displayMessageComposer();
139150
callbackContext.success();
140151
}
141152
},
142-
updateUser {
153+
displayConversationsList {
143154
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
144-
Map<String, Object> attributes = IntercomBridge.mapFromJSON(args.optJSONObject(0));
145-
Intercom.client().updateUser(attributes);
155+
Intercom.client().displayConversationsList();
146156
callbackContext.success();
147157
}
148158
},
149-
setVisibility {
159+
setLauncherVisibility {
150160
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
151161
String visibilityString = args.optString(0);
152-
int visibility = Intercom.VISIBLE;
162+
Visibility visibility = Intercom.VISIBLE;
153163
if ("GONE".equals(visibilityString)) {
154164
visibility = Intercom.GONE;
155165
}
156-
Intercom.client().setVisibility(visibility);
157-
callbackContext.success();
158-
}
159-
},
160-
setPreviewPosition {
161-
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
162-
String previewString = args.optString(0);
163-
Intercom.client().setPreviewPosition(IntercomPreviewPosition.toPresentationModeEnum(previewString));
166+
Intercom.client().setLauncherVisibility(visibility);
164167
callbackContext.success();
165168
}
166169
},
167-
setPreviewPadding {
170+
setInAppMessageVisibility {
168171
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
169-
callbackContext.error("[Intercom-Cordova] ERROR: Tried to set preview padding. This is only available on iOS.");
170-
}
171-
},
172-
setupGCM {
173-
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
174-
String registrationId = args.optString(0);
175-
176-
int resourceId = -1; //Don't use the app icon in lollipop as it doesn't work nicely
177-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
178-
resourceId = cordova.getActivity().getApplicationContext().getApplicationInfo().icon;
172+
String visibilityString = args.optString(0);
173+
Visibility visibility = Intercom.VISIBLE;
174+
if ("GONE".equals(visibilityString)) {
175+
visibility = Intercom.GONE;
179176
}
180-
Intercom.client().setupGCM(registrationId, resourceId);
177+
Intercom.client().setInAppMessageVisibility(visibility);
181178
callbackContext.success();
182179
}
183180
},
184-
openGCMMessage {
181+
updateUser {
185182
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
186-
Intercom.client().openGCMMessage(cordova.getActivity().getIntent());
183+
Map<String, Object> attributes = IntercomBridge.mapFromJSON(args.optJSONObject(0));
184+
Intercom.client().updateUser(attributes);
187185
callbackContext.success();
188186
}
189187
},
190188
registerForPush {
191189
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
192-
String senderId = args.optString(0);
193-
if (senderId == null) {
194-
callbackContext.error("[Intercom-Cordova] ERROR: Tried to setup GCM with no sender Id.");
195-
} else {
196-
IntercomGCMManager.setUpPush(senderId, cordova.getActivity().getApplicationContext());
197-
callbackContext.success();
198-
}
199-
}
200-
},
201-
setupAPN {
202-
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
203-
callbackContext.error("[Intercom-Cordova] ERROR: Tried to setup iOS push notifications on Android. Use setupGCM instead.");
190+
//This doesn't need to do anything on Android
204191
}
205192
},
206193
unknown {

0 commit comments

Comments
 (0)