Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/capacitor-community/intercom

Enable Intercom for Capacitor apps
https://github.com/capacitor-community/intercom

angular capacitor intercom ionic plugin

Last synced: 19 days ago
JSON representation

Enable Intercom for Capacitor apps

Awesome Lists containing this project

README

        



Capacitor Intercom


@capacitor-community/intercom



Capacitor community plugin for enabling Intercom capabilities









## Sponsors









Chatness AI


## Maintainers

| Maintainer | GitHub | Social |
| ------------ | --------------------------------------- | ----------------------------------------- |
| Stewan Silva | [stewones](https://github.com/stewones) | [@stewones](https://twitter.com/stewones) |

## Installation

Using npm:

```bash
npm install @capacitor-community/intercom
```

Using yarn:

```bash
yarn add @capacitor-community/intercom
```

Sync native files:

```bash
npx cap sync
```

## Usage

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

- `ionic start my-cap-app --capacitor`
- `cd my-cap-app`
- `npm install —-save @capacitor-community/intercom`
- `mkdir www && touch www/index.html`
- `npx cap add ios`
- add intercom keys to capacitor's configuration file

```
{

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

}
```

- `npx cap open ios`
- sign your app at xcode (general tab)

> 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

- `ionic start my-cap-app --capacitor`
- `cd my-cap-app`
- `npm install —-save @capacitor-community/intercom`
- `mkdir www && touch www/index.html`
- `npx cap add android`
- add intercom keys to capacitor's configuration file

```
{

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

}
```

- `npx cap open 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.

## 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](/CHANGELOG.md) for more info.

## Breaking changes from Capacitor v2 to v3

- `UserUpdateOptions` option type becomes `IntercomUserUpdateOptions`
- `IntercomPlugin` configuration key becomes `Intercom`
- `android-apiKey` config key becomes `androidApiKey`
- `android-appId` config key becomes `androidAppId`
- `ios-apiKey` config key becomes `iosApiKey`
- `ios-appId` config key becomes `iosAppId`
- [Switch from CAPBridge to ApplicationDelegateProxy](https://capacitorjs.com/docs/updating/3-0#switch-from-capbridge-to-applicationdelegateproxy-in-application-events) in application events
- remove the whole onCreate initialization from your app's `MainActivity.java`

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

## License

MIT

## Example

- https://github.com/capacitor-community/intercom/blob/master/example

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/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](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!