Skip to content

Commit

Permalink
Update plugin for new Intercom Messenger (#62)
Browse files Browse the repository at this point in the history
* Update plugin for new Intercom Messenger

* Update CHANGELOG.md
  • Loading branch information
jtreanor authored Jul 26, 2016
1 parent 03a1195 commit 7953d10
Show file tree
Hide file tree
Showing 155 changed files with 2,036 additions and 339 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Intercom for Cordova/PhoneGap

# 3.0.0 (2016-07-26)

Where is 2.x? We're skipping it. We did this to align the Cordova plugin with our iOS, Android and web counter parts.

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).

* Updated Intercom for iOS to [3.0.3](https://github.com/intercom/intercom-ios/releases/tag/3.0.3).
* Updated Intercom for Android to [3.0.2](https://github.com/intercom/intercom-android/releases/tag/3.0.2).

Added the following methods:
* `intercom.displayMessenger()`
* `intercom.setLauncherVisibility(visibility)`
* `intercom.setInAppMessageVisibility(visibility)`
* `intercom.unreadConversationCount()`

Removed these methods:
* `intercom.setVisibility(visibility)`
* `intercom.setupGCM()`
* `intercom.openGCMMessage()`
* `intercom.setupAPN(token)`
* `intercom.setPreviewPosition(position)`
* `intercom.setPreviewPadding()`

# 1.1.7 (2016-06-02)

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

## 1.0.0 (2015-05-25)

* Initial release of the Intercom plugin for Cordova and PhoneGap.
* Initial release of the Intercom plugin for Cordova and PhoneGap.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To install the plugin in your Cordova app, run the following:

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

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

## Configuring Intercom

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

## How does the in-app messenger work?

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.
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.

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`.

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);`.
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);`.

## Updating a user

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

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

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.
To enable Android push notifications, your [Sender ID](https://developers.google.com/cloud-messaging/gcm#senderid) to your app's `config.xml` as follows:

```
<preference name="intercom-android-sender-id" value="YOUR_SENDER_ID"/>
```

**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._

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

## Copyright

Copyright (c) 2015, Inc. All rights reserved.
Copyright (c) 2016, Inc. All rights reserved.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-intercom",
"version": "1.1.7",
"version": "3.0.0",
"description": "Official Cordova/PhoneGap plugin for Intercom",
"cordova": {
"id": "cordova-plugin-intercom",
Expand Down
11 changes: 5 additions & 6 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<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">
<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">
<name>Intercom</name>
<author>Intercom</author>
<license>MIT License</license>
Expand Down Expand Up @@ -32,9 +32,8 @@
</feature>
</config-file>

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

<framework src="Foundation.framework" />
<framework src="UIKit.framework" />
Expand All @@ -52,9 +51,9 @@

<platform name="android">
<source-file src="src/android/IntercomBridge.java" target-dir="src/io/intercom/android/sdk" />
<source-file src="src/android/IntercomGCMManager.java" target-dir="src/io/intercom/android/sdk" />
<source-file src="src/android/CordovaHeaderInterceptor.java" target-dir="src/io/intercom/android/sdk" />

<framework src="src/android/intercom.gradle" custom="true" type="gradleReference" />
<framework src="com.google.android.gms:play-services-gcm:8.+" />
<framework src="src/android/build-extras-intercom.gradle" custom="true" type="gradleReference" />

<config-file target="res/xml/config.xml" parent="/*">
Expand Down
8 changes: 8 additions & 0 deletions src/android/CordovaHeaderInterceptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.intercom.android.sdk.api;
import android.content.Context;

public class CordovaHeaderInterceptor {
public static void setCordovaVersion(Context context, String cordovaVersion) {
HeaderInterceptor.setCordovaVersion(context, cordovaVersion);
}
}
89 changes: 38 additions & 51 deletions src/android/IntercomBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import android.os.Build;

import io.intercom.android.sdk.identity.Registration;
import io.intercom.android.sdk.preview.IntercomPreviewPosition;
import io.intercom.android.sdk.api.HeaderInterceptor;
import io.intercom.android.sdk.api.CordovaHeaderInterceptor;

import io.intercom.android.sdk.Gcm;
import io.intercom.android.sdk.Intercom.Visibility;

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

if (Intercom.client().openGCMMessage(cordova.getActivity().getIntent().getData())) {
cordova.getActivity().getIntent().setData(null);
}
Intercom.client().openGcmMessage();
}
});
}
Expand All @@ -60,8 +60,13 @@ public class IntercomBridge extends CordovaPlugin {
private void setUpIntercom() {
try {
Context context = IntercomBridge.this.cordova.getActivity().getApplicationContext();

CordovaHeaderInterceptor.setCordovaVersion(context, "3.0.0");

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

ApplicationInfo app = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
Bundle bundle = app.metaData;
Expand Down Expand Up @@ -127,80 +132,62 @@ private enum Action {
callbackContext.success();
}
},
displayMessageComposer {
unreadConversationCount {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
Intercom.client().displayMessageComposer();
int count = Intercom.client().getUnreadConversationCount();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, count));
}
},
displayMessenger {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
Intercom.client().displayMessenger();
callbackContext.success();
}
},
displayConversationsList {
displayMessageComposer {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
Intercom.client().displayConversationsList();
Intercom.client().displayMessageComposer();
callbackContext.success();
}
},
updateUser {
displayConversationsList {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
Map<String, Object> attributes = IntercomBridge.mapFromJSON(args.optJSONObject(0));
Intercom.client().updateUser(attributes);
Intercom.client().displayConversationsList();
callbackContext.success();
}
},
setVisibility {
setLauncherVisibility {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
String visibilityString = args.optString(0);
int visibility = Intercom.VISIBLE;
Visibility visibility = Intercom.VISIBLE;
if ("GONE".equals(visibilityString)) {
visibility = Intercom.GONE;
}
Intercom.client().setVisibility(visibility);
callbackContext.success();
}
},
setPreviewPosition {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
String previewString = args.optString(0);
Intercom.client().setPreviewPosition(IntercomPreviewPosition.toPresentationModeEnum(previewString));
Intercom.client().setLauncherVisibility(visibility);
callbackContext.success();
}
},
setPreviewPadding {
setInAppMessageVisibility {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
callbackContext.error("[Intercom-Cordova] ERROR: Tried to set preview padding. This is only available on iOS.");
}
},
setupGCM {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
String registrationId = args.optString(0);

int resourceId = -1; //Don't use the app icon in lollipop as it doesn't work nicely
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
resourceId = cordova.getActivity().getApplicationContext().getApplicationInfo().icon;
String visibilityString = args.optString(0);
Visibility visibility = Intercom.VISIBLE;
if ("GONE".equals(visibilityString)) {
visibility = Intercom.GONE;
}
Intercom.client().setupGCM(registrationId, resourceId);
Intercom.client().setInAppMessageVisibility(visibility);
callbackContext.success();
}
},
openGCMMessage {
updateUser {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
Intercom.client().openGCMMessage(cordova.getActivity().getIntent());
Map<String, Object> attributes = IntercomBridge.mapFromJSON(args.optJSONObject(0));
Intercom.client().updateUser(attributes);
callbackContext.success();
}
},
registerForPush {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
String senderId = args.optString(0);
if (senderId == null) {
callbackContext.error("[Intercom-Cordova] ERROR: Tried to setup GCM with no sender Id.");
} else {
IntercomGCMManager.setUpPush(senderId, cordova.getActivity().getApplicationContext());
callbackContext.success();
}
}
},
setupAPN {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
callbackContext.error("[Intercom-Cordova] ERROR: Tried to setup iOS push notifications on Android. Use setupGCM instead.");
//This doesn't need to do anything on Android
}
},
unknown {
Expand Down
Loading

0 comments on commit 7953d10

Please sign in to comment.