Skip to content

amalinvest/intercom

Β 
Β 

Repository files navigation


Capacitor Intercom

@capacitor-community/intercom

Capacitor community plugin for enabling Intercom capabilities


Sponsors

Intenseloop

Maintainers

Maintainer GitHub Social
Stewan Silva stewones @stewones

Notice πŸš€

We're starting fresh under an official org. If you were using the previous npm package capacitor-intercom, please update your package.json to @capacitor-community/intercom. Check out changelog for more info.

Installation

Using npm: npm install @capacitor-community/intercom

npm install https://github.com/amalinvest/intercom --save

Using yarn: yarn add @capacitor-community/intercom

yarn add https://github.com/amalinvest/intercom 

Sync native files:

npx cap sync

API

  • registerIdentifiedUser
  • registerUnidentifiedUser
  • updateUser
  • logout
  • logEvent
  • displayMessenger
  • displayMessageComposer
  • displayHelpCenter
  • hideMessenger
  • displayLauncher
  • hideLauncher
  • displayInAppMessages
  • hideInAppMessages
  • displayCarousel
  • setUserHash
  • setBottomPadding

Usage

import { Intercom } from '@capacitor-community/intercom';
import { PushNotifications } from '@capacitor/push-notifications';

// Register for push notifications from Intercom
PushNotifications.register();

// Register an indetified user
Intercom.registerIdentifiedUser({ userId: 123456 });
Intercom.registerIdentifiedUser({ email: '[email protected]' });
Intercom.registerIdentifiedUser({ userId: 123456, email: '[email protected]' });

// Register a log event
Intercom.logEvent({ name: 'my-event', data: { pi: 3.14 } });

// Display the message composer
Intercom.displayMessageComposer({ message: 'Hello there!' });

// Identity Verification
// https://developers.intercom.com/installing-intercom/docs/ios-identity-verification
Intercom.setUserHash({ hmac: 'xyz' });

iOS setup

  • add intercom keys to capacitor's configuration file
{
 …
  "plugins": {
   "Intercom": {
      "iosApiKey": "ios_sdk-xxx",
      "iosAppId": "yyy"
    }
  }
…
}
  • npx cap run ios

Tip: every time you change a native code you may need to clean up the cache (Product > Clean build folder) and then run the app again.

Android setup

  1. Add intercom keys to capacitor's configuration file
{
 …
  "plugins": {
   "Intercom": {
      "androidApiKey": "android_sdk-xxx",
      "androidAppId": "yyy"
    }
  }
…
}
  • npx cap run android

Now you should be set to go. Try to run your client using ionic cap run android --livereload.

Tip: every time you change a native code you may need to clean up the cache (Build > Clean Project | Build > Rebuild Project) and then run the app again.

  1. Add this dependecy to android/app/build.gradle
dependencies {
     implementation 'com.google.firebase:firebase-messaging:20.2.+'
}
  1. Create a new file android/app/src/main/java/com/YOUR_APP/PushNotificationService.java that extends FirebaseMesssagingService if you dont have one already.
package com.YOUR_APP;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.getcapacitor.community.intercom.IntercomPlugin;

public class PushNotificationService extends FirebaseMessagingService {

 @Override
  public void onNewToken(String refreshedToken) {
    IntercomPlugin.sendTokenToIntercom(getApplication(), refreshedToken);
  }

 public void onMessageReceived(RemoteMessage remoteMessage) {
    if (IntercomPlugin.isIntercomPush(remoteMessage)) {
      IntercomPlugin.handleRemotePushMessage(getApplication(), remoteMessage);
   }
  }
} 
  1. Then add the following code to android/app/src/main/AndroidManifest.xml
      <service 
        android:name=".PushNotificationService"
        android:enabled="true"
        android:exported="true">
         <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
         </intent-filter>
      </service>
   </application>
</manifest>

License

MIT

Example

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Stew

πŸ’» πŸ“–

David Seek

πŸ’»

Roman Nikitin

πŸ’»

Anne Tomassoni

πŸ’» πŸ‘€

Maciej Modzelewski

πŸ’»

Oleg Yuzvik

🚧

Gustavo CorrΓͺa Alves

πŸ“–

Jealvia

🚧

Adam Duren

πŸ’» 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

Packages

No packages published

Languages

  • TypeScript 27.7%
  • Java 22.7%
  • Swift 21.7%
  • SCSS 15.4%
  • JavaScript 4.1%
  • Objective-C 3.2%
  • Other 5.2%