amalinvest / intercom

Enable Intercom for Capacitor apps

Home Page:https://capacitorjs.com/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


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: 'test@example.com' });
Intercom.registerIdentifiedUser({ userId: 123456, email: 'test@example.com' });

// 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!

About

Enable Intercom for Capacitor apps

https://capacitorjs.com/docs

License:MIT License


Languages

Language:TypeScript 27.7%Language:Java 22.7%Language:Swift 21.7%Language:SCSS 15.4%Language:JavaScript 4.1%Language:Objective-C 3.2%Language:Ruby 2.8%Language:HTML 2.4%