Coder Social home page Coder Social logo

tiintercomandroid's Introduction

Intercom android module for Intercom Android SDK version 1.1.20

Integrate Intercom.io with Appcelerator. iOS module available here https://github.com/markive/TiIntercom . Tested with Alloy and 5.1.1GA SDK

Example

var TiIntercom = require('intercom');
TiIntercom.initialize(<API KEY>,<APP ID>);
TiIntercom.startSession("[email protected]");

/lib/intercom.js

var TiIntercom = require('ti.intercom.android');

exports.initialize = function(key, id){
  TiIntercom.initialize({
      api_key : key,
      app_id : id,
  });
}

exports.startSession = function(email) {
  TiIntercom.reset();
  TiIntercom.registerUserWithEmail(email);
};

exports.endSession = function() {
  TiIntercom.reset();
};

exports.openIntercom = function() {
  TiIntercom.presentConversationList();
};

exports.logEventWithNameAndData = function(eventName, data /* 'event_name', { msg: 'hi' } */) {
  TiIntercom.logEventWithNameAndData(eventName, data);
};

exports.updateUserWithAttributes = function(data /* { fname: 'John', lname: 'Doe' } */) {
  TiIntercom.updateUserWithAttributes(data);
};

exports.setDeviceToken = function(token, appicon /* 'device-token', Ti.App.Android.R.drawable.appicon */) {
  TiIntercom.setDeviceToken(token, appicon);
};

IMPORTANT : tiapp.xml changes for Android GCM support

    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <application>
                <service
                    android:name="io.intercom.android.sdk.gcm.GcmIntentService"
                    android:enabled="false" />

                <!-- GCM setup -->
                <receiver
                    android:name="io.intercom.android.sdk.gcm.GcmBroadcastReceiver"
                    android:enabled="false"
                    android:permission="com.google.android.c2dm.permission.SEND" >
                    <intent-filter>
                        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                        <category android:name="io.intercom.intercomsdk.gcm" />
                    </intent-filter>
                </receiver>

                <meta-data
                    android:name="com.google.android.gms.version"
                    android:value="@integer/google_play_services_version" />

            </application>
        </manifest>    
    </android>

IMPORTANT : create hooks folder and intercom.js file in the module for Android GCM support

You need to create a hooks folder with a .js file inside the module directory with the following contents. This makes sure the additional R values are added for intercom during compile. If someone can tell me how to update the ant build script to create this automatically in the compiled dist please let me know otherwise you need to do this manually after compile.

Create the following file if not already included in the distribution:

FILE: /modules/android/ti.intercom.android/XX.XX.XX/hooks/intercom.js

exports.cliVersion = '>=3.X';

exports.init = function(logger, config, cli, appc) {
    cli.on('build.android.aapt', {
        pre: function(data, next) {
            var args = data.args[1],
                i18n = appc.i18n(__dirname),
                __ = i18n.__,
                path = require('path'),
                appDir = path.join(cli.argv['project-dir'], 'app'),
                find = function(items, f) {
                    for (var i = 0; i < items.length; i++) {
                        var item = items[i];
                        if (f(item)) return item;
                    };
                },
                module = false;
            if (args.indexOf('--auto-add-overlay') < 0) {
                args.push('--auto-add-overlay');
            }
            for(var i in cli.tiapp.modules) {
                if (cli.tiapp.modules[i].id == "ti.intercom.android") {
                    module = cli.tiapp.modules[i];
                    break;
                }
            }
            if (!module) {
                logger.error(__('Unable to determine Android Intercom module version.  You must specify the module version specfically in your tiapp.xml'));
                process.exit(1);
            } else {
                var externalLibraries = [{
                    javaClass: 'io.intercom.android.sdk.gcm',
                    resPath: appDir + '/../modules/android/ti.intercom.android/' + module.version + '/platform/android/gcm-res'
                }];
                logger.info(__("Add Intercom GCM External Libraries" + JSON.stringify(externalLibraries)));

                // --extra-packages can be defined just once
                if (args.indexOf('--extra-packages') < 0) {
                    args.push('--extra-packages');
                    args.push('');
                }
                var namespaceIndex = args.indexOf('--extra-packages') + 1;

                externalLibraries.forEach(function(lib) {
                    if (args[namespaceIndex].indexOf(lib.javaClass) < 0) {
                        args[namespaceIndex].length && (args[namespaceIndex] += ':');
                        args[namespaceIndex] += lib.javaClass;
                    }
                    if (args.indexOf(lib.resPath) < 0) {
                        args.push('-S');
                        args.push(lib.resPath);
                    }
                });
                next(null, data);
            }

        }
    });
};

Author

Jerod ([email protected])

License

The MIT License (MIT) Copyright © 2015

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

tiintercomandroid's People

Contributors

jerodfritz avatar minhnc avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tiintercomandroid's Issues

3.0 Upgrade

Hi @minhnc . Would you be available to upgrade this module to the latest Intercom SDK? We would be happy to compensate you for your time to help.

  • Jerod

TiIntercom.setDeviceToken fails with `intercom-sdk-gcm module not found. Please add it to your build.gradle.`

First, thanks for creating maintaining this module. It's saved me soooo much time.

Everything is working great except for Push notifications.

After retrieving (via Ti.Cloudpush) a GCM token, calling TiIntercom.setDeviceToken(token, icon) fails with intercom-sdk-gcm module not found. Please add it to your build.gradle.

See below.

I can easily get my hands on Intercom's copy of its intercom-sdk-gcm, but I'm not at all sure where to put it or how to refer to it once I've put it somewhere...

Let me know if there's any info you need, debug or otherwise, or anything you'd like me to try and report to you.

Code

OF.log("XXX require(ti.cloudpush)");
var CloudPush = require('ti.cloudpush');

OF.log("XXX CloudPush.retrieveDeviceToken");
CloudPush.retrieveDeviceToken({
    success : function(e) { 
        OF.log("XXX TiIntercom.setDeviceToken: " + e.deviceToken); 
        TiIntercom.setDeviceToken:(e.deviceToken, Ti.App.Android.R.drawable.appicon);
        OF.log("XXX Done with TiIntercom.setDeviceToken: " + e.deviceToken); 
    },
    error   : function(e) { OF.log("error CloudPush.retrieveDeviceToken: " + e.error); } 
});

Adb output

05-16 14:25:18.312 27305 27327 I TiAPI   :  14:25:18 XXX require(ti.cloudpush)
05-16 14:25:18.375 27305 27327 I TiAPI   :  14:25:18 XXX CloudPush.retrieveDeviceToken
05-16 14:25:18.396 27305 27327 I TiAPI   :  14:25:18 XXX TiIntercom.setDeviceToken: XXXXXXXXXXXXXXXXXXXXXXXX
05-16 14:25:18.399 27305 27327 E Intercom-Android: ERROR: intercom-sdk-gcm module not found. Please add it to your build.gradle
05-16 14:25:18.399 27305 27327 D TiintercomandroidModule: (KrollRuntimeThread) [739,1255] Intercom : setDeviceToken()
05-16 14:25:18.399 27305 27327 I TiAPI   :  14:25:18 XXX Done with TiIntercom.setDeviceToken: XXXXXXXXXXXXXXXXXXXXXXXX

Problem running the module

Hi Centrogram,

I have an issue running this module. I get the following error:


Unable to find explicit activity class (com.myapp/io.intercom.android.sdk.activities.MainActivity); have you declared this activity in your AndroidManifest.xml?

Source: TiIntercom.presentConversaionList();

I'm not sure if this helps, but I definitely can't get this to work: http://stackoverflow.com/questions/3433778/android-content-activitynotfoundexception

Do I need to put anything else in an AndroidManifest.xml inside my App itself? Also I assume I have to include the resources in /platform/android?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.