capacitor-community / intercom

Enable Intercom for Capacitor apps
https://capacitorjs.com/docs
MIT License
60 stars 77 forks source link
angular capacitor intercom ionic plugin


Capacitor Intercom

@capacitor-community/intercom

Capacitor community plugin for enabling Intercom capabilities


Sponsors

Chatness AI

Maintainers

Maintainer GitHub Social
Stewan Silva stewones @stewones

Installation

Using npm:

npm install @capacitor-community/intercom

Using yarn:

yarn add @capacitor-community/intercom

Sync native files:

npx cap sync

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

{
 …
  "plugins": {
   "Intercom": {
      "iosApiKey": "ios_sdk-xxx",
      "iosAppId": "yyy"
    }
  }
…
}

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

{
 …
  "plugins": {
   "Intercom": {
      "androidApiKey": "android_sdk-xxx",
      "androidAppId": "yyy"
    }
  }
…
}

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.

API

* [`loadWithKeys(...)`](#loadwithkeys) * [`registerIdentifiedUser(...)`](#registeridentifieduser) * [`registerUnidentifiedUser()`](#registerunidentifieduser) * [`updateUser(...)`](#updateuser) * [`logout()`](#logout) * [`logEvent(...)`](#logevent) * [`displayMessenger()`](#displaymessenger) * [`displayMessageComposer(...)`](#displaymessagecomposer) * [`displayHelpCenter()`](#displayhelpcenter) * [`hideMessenger()`](#hidemessenger) * [`displayLauncher()`](#displaylauncher) * [`hideLauncher()`](#hidelauncher) * [`displayInAppMessages()`](#displayinappmessages) * [`hideInAppMessages()`](#hideinappmessages) * [`displayCarousel(...)`](#displaycarousel) * [`setUserHash(...)`](#setuserhash) * [`setBottomPadding(...)`](#setbottompadding) * [`sendPushTokenToIntercom(...)`](#sendpushtokentointercom) * [`receivePush(...)`](#receivepush) * [`displayArticle(...)`](#displayarticle) * [`addListener('windowDidShow', ...)`](#addlistenerwindowdidshow-) * [`addListener('windowDidHide', ...)`](#addlistenerwindowdidhide-) * [`removeAllListeners()`](#removealllisteners) * [Interfaces](#interfaces) ### loadWithKeys(...) ```typescript loadWithKeys(options: { appId?: string; apiKeyIOS?: string; apiKeyAndroid?: string; }) => Promise ``` | Param | Type | | ------------- | ---------------------------------------------------------------------------- | | **`options`** | { appId?: string; apiKeyIOS?: string; apiKeyAndroid?: string; } | -------------------- ### registerIdentifiedUser(...) ```typescript registerIdentifiedUser(options: { userId?: string; email?: string; }) => Promise ``` | Param | Type | | ------------- | ------------------------------------------------- | | **`options`** | { userId?: string; email?: string; } | -------------------- ### registerUnidentifiedUser() ```typescript registerUnidentifiedUser() => Promise ``` -------------------- ### updateUser(...) ```typescript updateUser(options: IntercomUserUpdateOptions) => Promise ``` | Param | Type | | ------------- | ------------------------------------------------------------------------------- | | **`options`** | IntercomUserUpdateOptions | -------------------- ### logout() ```typescript logout() => Promise ``` -------------------- ### logEvent(...) ```typescript logEvent(options: { name: string; data?: any; }) => Promise ``` | Param | Type | | ------------- | ------------------------------------------ | | **`options`** | { name: string; data?: any; } | -------------------- ### displayMessenger() ```typescript displayMessenger() => Promise ``` -------------------- ### displayMessageComposer(...) ```typescript displayMessageComposer(options: { message: string; }) => Promise ``` | Param | Type | | ------------- | --------------------------------- | | **`options`** | { message: string; } | -------------------- ### displayHelpCenter() ```typescript displayHelpCenter() => Promise ``` -------------------- ### hideMessenger() ```typescript hideMessenger() => Promise ``` -------------------- ### displayLauncher() ```typescript displayLauncher() => Promise ``` -------------------- ### hideLauncher() ```typescript hideLauncher() => Promise ``` -------------------- ### displayInAppMessages() ```typescript displayInAppMessages() => Promise ``` -------------------- ### hideInAppMessages() ```typescript hideInAppMessages() => Promise ``` -------------------- ### displayCarousel(...) ```typescript displayCarousel(options: { carouselId: string; }) => Promise ``` | Param | Type | | ------------- | ------------------------------------ | | **`options`** | { carouselId: string; } | -------------------- ### setUserHash(...) ```typescript setUserHash(options: { hmac: string; }) => Promise ``` | Param | Type | | ------------- | ------------------------------ | | **`options`** | { hmac: string; } | -------------------- ### setBottomPadding(...) ```typescript setBottomPadding(options: { value: string; }) => Promise ``` | Param | Type | | ------------- | ------------------------------- | | **`options`** | { value: string; } | -------------------- ### sendPushTokenToIntercom(...) ```typescript sendPushTokenToIntercom(options: { value: string; }) => Promise ``` | Param | Type | | ------------- | ------------------------------- | | **`options`** | { value: string; } | -------------------- ### receivePush(...) ```typescript receivePush(notification: IntercomPushNotificationData) => Promise ``` | Param | Type | | ------------------ | ------------------------------------------------------------------------------------- | | **`notification`** | IntercomPushNotificationData | -------------------- ### displayArticle(...) ```typescript displayArticle(options: { articleId: string; }) => Promise ``` | Param | Type | | ------------- | ----------------------------------- | | **`options`** | { articleId: string; } | -------------------- ### addListener('windowDidShow', ...) ```typescript addListener(eventName: 'windowDidShow', listenerFunc: () => void) => Promise ``` | Param | Type | | ------------------ | ---------------------------- | | **`eventName`** | 'windowDidShow' | | **`listenerFunc`** | () => void | **Returns:** Promise<PluginListenerHandle> -------------------- ### addListener('windowDidHide', ...) ```typescript addListener(eventName: 'windowDidHide', listenerFunc: () => void) => Promise ``` | Param | Type | | ------------------ | ---------------------------- | | **`eventName`** | 'windowDidHide' | | **`listenerFunc`** | () => void | **Returns:** Promise<PluginListenerHandle> -------------------- ### removeAllListeners() ```typescript removeAllListeners() => Promise ``` -------------------- ### Interfaces #### IntercomUserUpdateOptions | Prop | Type | | ---------------------- | ------------------------------------ | | **`userId`** | string | | **`email`** | string | | **`name`** | string | | **`phone`** | string | | **`languageOverride`** | string | | **`customAttributes`** | { [key: string]: any; } | #### IntercomPushNotificationData | Prop | Type | | ------------------------------- | ------------------- | | **`conversation_id`** | string | | **`message`** | string | | **`body`** | string | | **`author_name`** | string | | **`image_url`** | string | | **`app_name`** | string | | **`receiver`** | string | | **`conversation_part_type`** | string | | **`intercom_push_type`** | string | | **`uri`** | string | | **`push_only_conversation_id`** | string | | **`instance_id`** | string | | **`title`** | string | | **`priority`** | number | #### PluginListenerHandle | Prop | Type | | ------------ | ----------------------------------------- | | **`remove`** | () => Promise<void> |

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.

Breaking changes from Capacitor v2 to v3

 public class MainActivity extends BridgeActivity {
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        // Initializes the Bridge
-        this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
-            // Additional plugins you've installed go here
-            add(IntercomPlugin.class);
-        }});
-    }
 }

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

💻 🚧

Rami Khafagi

💻

Masahiko Sakakibara

🚧

Dejardin Camille

💻

Mohamed Abdelgwad

🚧

Nathan

🚧

Cecil Wöbker

💻 🚧

Pavlo Pyrig

💻

Ruan

💻

RickJeroen

🚧

reslear

📖

Philipp Matter

💻

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