4.3.0 • Published 3 years ago

@houseninja/capacitor-intercom v4.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Maintainers

MaintainerGitHubSocial
Miles Zimmermanmileszim@mileszim
House Ninjahouseninjadojo

Installation

Using npm:

npm install @houseninja/capacitor-intercom

Using yarn:

yarn add @houseninjad/capacitor-intercom

Sync native files:

npx cap sync

Usage

Web Only

For web, you must run boot({ appId: <app-id> }) to initialize.

import { Intercom } from '@houseninja/capacitor-intercom';

Intercom.boot({
  appId: '12345',
  email: 'test@example.com', // you can set user details on boot:
  userId: '1234',            // see https://developers.intercom.com/installing-intercom/docs/intercom-javascript#intercomboot-intercomsettings
});

Intercom.registerIdentifiedUser({
  email: 'test@example.com', // you can also set user details like the mobile SDKs
  userId: '1234',
});

// show intercom
Intercom.show();

Web, iOS, Android

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

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

// Register an indetified user
await Intercom.registerIdentifiedUser({ userId: 123456 }); // or email or both

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

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

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

// Get Unread Conversation Count
await Intercom.unreadConversationCount();

// Listen for unread conversation count to change
Intercom.addListener('onUnreadCountChange', ({ value }) => {
  console.log('conversation count is: ', value);
});

iOS setup

  • ionic start my-cap-app --capacitor
  • cd my-cap-app
  • npm install —-save @houseninja/capacitor-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 @houseninja/capacitor-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

boot(...)

boot(options: IntercomSettings) => Promise<void>
ParamType
optionsIntercomSettings

loginUser(...)

loginUser(options: { userId?: string; email?: string; }) => Promise<void>
ParamType
options{ userId?: string; email?: string; }

registerIdentifiedUser(...)

registerIdentifiedUser(options: { userId?: string; email?: string; }) => Promise<void>
ParamType
options{ userId?: string; email?: string; }

loginUnidentifiedUser()

loginUnidentifiedUser() => Promise<void>

registerUnidentifiedUser()

registerUnidentifiedUser() => Promise<void>

updateUser(...)

updateUser(options: IntercomUserUpdateOptions) => Promise<void>
ParamType
optionsIntercomUserUpdateOptions

logout()

logout() => Promise<void>

logEvent(...)

logEvent(options: { name: string; data?: any; }) => Promise<void>
ParamType
options{ name: string; data?: any; }

displayMessenger()

displayMessenger() => Promise<void>

show()

show() => Promise<void>

displayInbox()

displayInbox() => Promise<void>

displayMessageComposer(...)

displayMessageComposer(options: { message: string; }) => Promise<void>
ParamType
options{ message: string; }

displayHelpCenter()

displayHelpCenter() => Promise<void>

displayArticle(...)

displayArticle(options: { articleId: string; }) => Promise<void>
ParamType
options{ articleId: string; }

displayCarousel(...)

displayCarousel(options: { carouselId: string; }) => Promise<void>
ParamType
options{ carouselId: string; }

displayLauncher()

displayLauncher() => Promise<void>

enableLauncher()

enableLauncher() => Promise<void>

displayInAppMessages()

displayInAppMessages() => Promise<void>

enableMessengerPopups()

enableMessengerPopups() => Promise<void>

hideMessenger()

hideMessenger() => Promise<void>

hide()

hide() => Promise<void>

hideLauncher()

hideLauncher() => Promise<void>

disableLauncher()

disableLauncher() => Promise<void>

hideInAppMessages()

hideInAppMessages() => Promise<void>

disableMessengerPopups()

disableMessengerPopups() => Promise<void>

setUserHash(...)

setUserHash(options: { hmac: string; }) => Promise<void>
ParamType
options{ hmac: string; }

setBottomPadding(...)

setBottomPadding(options: { value: string; }) => Promise<void>
ParamType
options{ value: string; }

sendPushTokenToIntercom(...)

sendPushTokenToIntercom(options: { value: string; }) => Promise<void>
ParamType
options{ value: string; }

receivePush(...)

receivePush(notification: IntercomPushNotificationData) => Promise<void>
ParamType
notificationIntercomPushNotificationData

unreadConversationCount()

unreadConversationCount() => Promise<UnreadConversationCount>

Returns: Promise<UnreadConversationCount>


addListener('onUnreadCountChange', ...)

addListener(eventName: 'onUnreadCountChange', listenerFunc: UnreadCountChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'onUnreadCountChange'
listenerFuncUnreadCountChangeListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('windowWillShow', ...)

addListener(eventName: 'windowWillShow', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'windowWillShow'
listenerFunc() => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('windowDidShow', ...)

addListener(eventName: 'windowDidShow', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'windowDidShow'
listenerFunc() => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('windowWillHide', ...)

addListener(eventName: 'windowWillHide', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'windowWillHide'
listenerFunc() => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('windowDidHide', ...)

addListener(eventName: 'windowDidHide', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'windowDidHide'
listenerFunc() => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('didStartNewConversation', ...)

addListener(eventName: 'didStartNewConversation', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'didStartNewConversation'
listenerFunc() => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


removeAllListeners()

removeAllListeners() => Promise<void>

Interfaces

IntercomSettings

PropType
app_idstring
custom_launcher_selectorstring
alignmentstring
vertical_paddingnumber
horizontal_paddingnumber
hide_default_launcherboolean
session_durationnumber
action_colorstring
background_colorstring
emailstring
user_idstring
created_atDate
namestring
phonestring
last_request_atDate
unsubscribed_from_emailsboolean
language_overridestring
utm_campaignstring
utm_contentstring
utm_sourcestring
utm_termstring
avatarIntercomAvatar
user_hashstring
companyIntercomCompany
companiesIntercomCompany[]

Date

Enables basic storage and retrieval of dates and times.

MethodSignatureDescription
toString() => stringReturns a string representation of a date. The format of the string depends on the locale.
toDateString() => stringReturns a date as a string value.
toTimeString() => stringReturns a time as a string value.
toLocaleString() => stringReturns a value as a string value appropriate to the host environment's current locale.
toLocaleDateString() => stringReturns a date as a string value appropriate to the host environment's current locale.
toLocaleTimeString() => stringReturns a time as a string value appropriate to the host environment's current locale.
valueOf() => numberReturns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
getTime() => numberGets the time value in milliseconds.
getFullYear() => numberGets the year, using local time.
getUTCFullYear() => numberGets the year using Universal Coordinated Time (UTC).
getMonth() => numberGets the month, using local time.
getUTCMonth() => numberGets the month of a Date object using Universal Coordinated Time (UTC).
getDate() => numberGets the day-of-the-month, using local time.
getUTCDate() => numberGets the day-of-the-month, using Universal Coordinated Time (UTC).
getDay() => numberGets the day of the week, using local time.
getUTCDay() => numberGets the day of the week using Universal Coordinated Time (UTC).
getHours() => numberGets the hours in a date, using local time.
getUTCHours() => numberGets the hours value in a Date object using Universal Coordinated Time (UTC).
getMinutes() => numberGets the minutes of a Date object, using local time.
getUTCMinutes() => numberGets the minutes of a Date object using Universal Coordinated Time (UTC).
getSeconds() => numberGets the seconds of a Date object, using local time.
getUTCSeconds() => numberGets the seconds of a Date object using Universal Coordinated Time (UTC).
getMilliseconds() => numberGets the milliseconds of a Date, using local time.
getUTCMilliseconds() => numberGets the milliseconds of a Date object using Universal Coordinated Time (UTC).
getTimezoneOffset() => numberGets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC).
setTime(time: number) => numberSets the date and time value in the Date object.
setMilliseconds(ms: number) => numberSets the milliseconds value in the Date object using local time.
setUTCMilliseconds(ms: number) => numberSets the milliseconds value in the Date object using Universal Coordinated Time (UTC).
setSeconds(sec: number, ms?: number | undefined) => numberSets the seconds value in the Date object using local time.
setUTCSeconds(sec: number, ms?: number | undefined) => numberSets the seconds value in the Date object using Universal Coordinated Time (UTC).
setMinutes(min: number, sec?: number | undefined, ms?: number | undefined) => numberSets the minutes value in the Date object using local time.
setUTCMinutes(min: number, sec?: number | undefined, ms?: number | undefined) => numberSets the minutes value in the Date object using Universal Coordinated Time (UTC).
setHours(hours: number, min?: number | undefined, sec?: number | undefined, ms?: number | undefined) => numberSets the hour value in the Date object using local time.
setUTCHours(hours: number, min?: number | undefined, sec?: number | undefined, ms?: number | undefined) => numberSets the hours value in the Date object using Universal Coordinated Time (UTC).
setDate(date: number) => numberSets the numeric day-of-the-month value of the Date object using local time.
setUTCDate(date: number) => numberSets the numeric day of the month in the Date object using Universal Coordinated Time (UTC).
setMonth(month: number, date?: number | undefined) => numberSets the month value in the Date object using local time.
setUTCMonth(month: number, date?: number | undefined) => numberSets the month value in the Date object using Universal Coordinated Time (UTC).
setFullYear(year: number, month?: number | undefined, date?: number | undefined) => numberSets the year of the Date object using local time.
setUTCFullYear(year: number, month?: number | undefined, date?: number | undefined) => numberSets the year value in the Date object using Universal Coordinated Time (UTC).
toUTCString() => stringReturns a date converted to a string using Universal Coordinated Time (UTC).
toISOString() => stringReturns a date as a string value in ISO format.
toJSON(key?: any) => stringUsed by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization.

IntercomAvatar

PropType
typestring
image_urlstring

IntercomCompany

PropType
company_idstring
namestring
created_atDate
remote_created_atDate
planstring
monthly_spendnumber
user_countnumber
sizenumber
websitestring
industrystring

IntercomUserUpdateOptions

PropType
userIdstring
emailstring
namestring
phonestring
languageOverridestring
customAttributes{ key: string: any; }

IntercomPushNotificationData

PropType
conversation_idstring
messagestring
bodystring
author_namestring
image_urlstring
app_namestring
receiverstring
conversation_part_typestring
intercom_push_typestring
uristring
push_only_conversation_idstring
instance_idstring
titlestring
prioritynumber

UnreadConversationCount

PropType
valuestring

PluginListenerHandle

PropType
remove() => Promise<void>

Type Aliases

UnreadCountChangeListener

(state: UnreadConversationCount): void

License

MIT

Example

Contributors ✨

Thanks goes to these wonderful people (emoji key):

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

4.3.0

3 years ago

4.2.3

3 years ago

4.2.2

3 years ago

4.2.1

3 years ago

4.2.1-beta.0

3 years ago

4.2.0-beta.5

3 years ago

4.2.0-beta.4

3 years ago

4.2.0-beta.3

3 years ago

4.2.0-beta.2

3 years ago