@houseninja/capacitor-intercom
Capacitor plugin for enabling Intercom capabilities
Using npm:
npm install @houseninja/capacitor-intercom
Using yarn:
yarn add @houseninjad/capacitor-intercom
Sync native files:
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 ( ) ;
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 ) ;
} ) ;
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.
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"
}
}
β¦
}
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.
boot ( options : IntercomSettings ) = > Promise < void >
loginUser ( options : { userId ?: string; email ?: string ; } ) = > Promise < void >
Param
Type
options
{ userId?: string; email?: string; }
registerIdentifiedUser(...)
registerIdentifiedUser ( options : { userId ?: string; email ?: string ; } ) = > Promise < void >
Param
Type
options
{ userId?: string; email?: string; }
loginUnidentifiedUser ( ) = > Promise < void >
registerUnidentifiedUser()
registerUnidentifiedUser ( ) = > Promise < void >
updateUser ( options : IntercomUserUpdateOptions ) = > Promise < void >
logout ( ) = > Promise < void >
logEvent ( options : { name : string ; data ?: any; } ) = > Promise < void >
Param
Type
options
{ name: string; data?: any; }
displayMessenger ( ) = > Promise < void >
displayInbox ( ) = > Promise < void >
displayMessageComposer(...)
displayMessageComposer ( options : { message : string ; } ) = > Promise < void >
Param
Type
options
{ message: string; }
displayHelpCenter ( ) = > Promise < void >
displayArticle ( options : { articleId : string ; } ) = > Promise < void >
Param
Type
options
{ articleId: string; }
displayCarousel ( options : { carouselId : string ; } ) = > Promise < void >
Param
Type
options
{ carouselId: string; }
displayLauncher ( ) = > Promise < void >
enableLauncher ( ) = > Promise < void >
displayInAppMessages ( ) = > Promise < void >
enableMessengerPopups()
enableMessengerPopups ( ) = > Promise < void >
hideMessenger ( ) = > Promise < void >
hideLauncher ( ) = > Promise < void >
disableLauncher ( ) = > Promise < void >
hideInAppMessages ( ) = > Promise < void >
disableMessengerPopups()
disableMessengerPopups ( ) = > Promise < void >
setUserHash ( options : { hmac : string ; } ) = > Promise < void >
Param
Type
options
{ hmac: string; }
setBottomPadding ( options : { value : string ; } ) = > Promise < void >
Param
Type
options
{ value: string; }
sendPushTokenToIntercom(...)
sendPushTokenToIntercom ( options : { value : string ; } ) = > Promise < void >
Param
Type
options
{ value: string; }
receivePush ( notification : IntercomPushNotificationData ) = > Promise < void >
unreadConversationCount()
unreadConversationCount ( ) = > Promise < UnreadConversationCount >
Returns: Promise<UnreadConversationCount >
addListener('onUnreadCountChange', ...)
addListener ( eventName : 'onUnreadCountChange' , listenerFunc : UnreadCountChangeListener ) = > Promise < PluginListenerHandle > & PluginListenerHandle
Returns: Promise<PluginListenerHandle > & PluginListenerHandle
addListener('windowWillShow', ...)
addListener ( eventName : 'windowWillShow' , listenerFunc : ( ) = > void ) => Promise < PluginListenerHandle > & PluginListenerHandle
Param
Type
eventName
'windowWillShow'
listenerFunc
() => void
Returns: Promise<PluginListenerHandle > & PluginListenerHandle
addListener('windowDidShow', ...)
addListener ( eventName : 'windowDidShow' , listenerFunc : ( ) = > void ) => Promise < PluginListenerHandle > & PluginListenerHandle
Param
Type
eventName
'windowDidShow'
listenerFunc
() => void
Returns: Promise<PluginListenerHandle > & PluginListenerHandle
addListener('windowWillHide', ...)
addListener ( eventName : 'windowWillHide' , listenerFunc : ( ) = > void ) => Promise < PluginListenerHandle > & PluginListenerHandle
Param
Type
eventName
'windowWillHide'
listenerFunc
() => void
Returns: Promise<PluginListenerHandle > & PluginListenerHandle
addListener('windowDidHide', ...)
addListener ( eventName : 'windowDidHide' , listenerFunc : ( ) = > void ) => Promise < PluginListenerHandle > & PluginListenerHandle
Param
Type
eventName
'windowDidHide'
listenerFunc
() => void
Returns: Promise<PluginListenerHandle > & PluginListenerHandle
addListener('didStartNewConversation', ...)
addListener ( eventName : 'didStartNewConversation' , listenerFunc : ( ) = > void ) => Promise < PluginListenerHandle > & PluginListenerHandle
Param
Type
eventName
'didStartNewConversation'
listenerFunc
() => void
Returns: Promise<PluginListenerHandle > & PluginListenerHandle
removeAllListeners ( ) = > Promise < void >
Prop
Type
app_id
string
custom_launcher_selector
string
alignment
string
vertical_padding
number
horizontal_padding
number
hide_default_launcher
boolean
session_duration
number
action_color
string
background_color
string
email
string
user_id
string
created_at
Date
name
string
phone
string
last_request_at
Date
unsubscribed_from_emails
boolean
language_override
string
utm_campaign
string
utm_content
string
utm_source
string
utm_term
string
avatar
IntercomAvatar
user_hash
string
company
IntercomCompany
companies
IntercomCompany[]
Enables basic storage and retrieval of dates and times.
Method
Signature
Description
toString
() => string
Returns a string representation of a date. The format of the string depends on the locale.
toDateString
() => string
Returns a date as a string value.
toTimeString
() => string
Returns a time as a string value.
toLocaleString
() => string
Returns a value as a string value appropriate to the host environment's current locale.
toLocaleDateString
() => string
Returns a date as a string value appropriate to the host environment's current locale.
toLocaleTimeString
() => string
Returns a time as a string value appropriate to the host environment's current locale.
valueOf
() => number
Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
getTime
() => number
Gets the time value in milliseconds.
getFullYear
() => number
Gets the year, using local time.
getUTCFullYear
() => number
Gets the year using Universal Coordinated Time (UTC).
getMonth
() => number
Gets the month, using local time.
getUTCMonth
() => number
Gets the month of a Date object using Universal Coordinated Time (UTC).
getDate
() => number
Gets the day-of-the-month, using local time.
getUTCDate
() => number
Gets the day-of-the-month, using Universal Coordinated Time (UTC).
getDay
() => number
Gets the day of the week, using local time.
getUTCDay
() => number
Gets the day of the week using Universal Coordinated Time (UTC).
getHours
() => number
Gets the hours in a date, using local time.
getUTCHours
() => number
Gets the hours value in a Date object using Universal Coordinated Time (UTC).
getMinutes
() => number
Gets the minutes of a Date object, using local time.
getUTCMinutes
() => number
Gets the minutes of a Date object using Universal Coordinated Time (UTC).
getSeconds
() => number
Gets the seconds of a Date object, using local time.
getUTCSeconds
() => number
Gets the seconds of a Date object using Universal Coordinated Time (UTC).
getMilliseconds
() => number
Gets the milliseconds of a Date , using local time.
getUTCMilliseconds
() => number
Gets the milliseconds of a Date object using Universal Coordinated Time (UTC).
getTimezoneOffset
() => number
Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC).
setTime
(time: number) => number
Sets the date and time value in the Date object.
setMilliseconds
(ms: number) => number
Sets the milliseconds value in the Date object using local time.
setUTCMilliseconds
(ms: number) => number
Sets the milliseconds value in the Date object using Universal Coordinated Time (UTC).
setSeconds
(sec: number, ms?: number | undefined) => number
Sets the seconds value in the Date object using local time.
setUTCSeconds
(sec: number, ms?: number | undefined) => number
Sets the seconds value in the Date object using Universal Coordinated Time (UTC).
setMinutes
(min: number, sec?: number | undefined, ms?: number | undefined) => number
Sets the minutes value in the Date object using local time.
setUTCMinutes
(min: number, sec?: number | undefined, ms?: number | undefined) => number
Sets the minutes value in the Date object using Universal Coordinated Time (UTC).
setHours
(hours: number, min?: number | undefined, sec?: number | undefined, ms?: number | undefined) => number
Sets the hour value in the Date object using local time.
setUTCHours
(hours: number, min?: number | undefined, sec?: number | undefined, ms?: number | undefined) => number
Sets the hours value in the Date object using Universal Coordinated Time (UTC).
setDate
(date: number) => number
Sets the numeric day-of-the-month value of the Date object using local time.
setUTCDate
(date: number) => number
Sets the numeric day of the month in the Date object using Universal Coordinated Time (UTC).
setMonth
(month: number, date?: number | undefined) => number
Sets the month value in the Date object using local time.
setUTCMonth
(month: number, date?: number | undefined) => number
Sets the month value in the Date object using Universal Coordinated Time (UTC).
setFullYear
(year: number, month?: number | undefined, date?: number | undefined) => number
Sets the year of the Date object using local time.
setUTCFullYear
(year: number, month?: number | undefined, date?: number | undefined) => number
Sets the year value in the Date object using Universal Coordinated Time (UTC).
toUTCString
() => string
Returns a date converted to a string using Universal Coordinated Time (UTC).
toISOString
() => string
Returns a date as a string value in ISO format.
toJSON
(key?: any) => string
Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization.
Prop
Type
type
string
image_url
string
Prop
Type
company_id
string
name
string
created_at
Date
remote_created_at
Date
plan
string
monthly_spend
number
user_count
number
size
number
website
string
industry
string
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
Prop
Type
remove
() => Promise<void>
UnreadCountChangeListener
(state: UnreadConversationCount ): void
MIT
Thanks goes to these wonderful people (emoji key ):
This project follows the all-contributors specification. Contributions of any kind welcome!