diff --git a/src/@awesome-cordova-plugins/plugins/intercom/index.ts b/src/@awesome-cordova-plugins/plugins/intercom/index.ts index 8a301c11de..35c25decc5 100644 --- a/src/@awesome-cordova-plugins/plugins/intercom/index.ts +++ b/src/@awesome-cordova-plugins/plugins/intercom/index.ts @@ -5,7 +5,7 @@ import { Injectable } from '@angular/core'; * @name Intercom * @description * This is a plugin that allows your Ionic app to use Intercom for iOS and/or Intercom for Android. - * Follow the offical documentation to setup this plugin correctly: https://developers.intercom.com/docs/cordova-phonegap-configuration + * Follow the offical documentation to setup this plugin correctly: https://developers.intercom.com/installing-intercom/cordova-phonegap/installation * @usage * ```typescript * import { Intercom } from '@awesome-cordova-plugins/intercom/ngx'; @@ -31,229 +31,371 @@ import { Injectable } from '@angular/core'; @Injectable() export class Intercom extends AwesomeCordovaNativePlugin { /** - * Register a identified user - * - * @param options {any} Options - * @returns {Promise} Returns a promise + * Login a user with identifiable information. + * Valid identifiers are `userId` and `email` which must be set in an object. + * @param options The object that contains the user's `email` or `userId`. */ @Cordova() - registerIdentifiedUser(options: any): Promise { + loginUserWithUserAttributes(options: IntercomLoginUserAttributes): Promise { return; } /** - * Register a unidentified user - * - * @param options {any} Options - * @returns {Promise} Returns a promise + * Login a unidentified user. + * This is a user that doesn't have any identifiable information such as a `userId` or `email`. */ @Cordova() - registerUnidentifiedUser(options: any): Promise { + loginUnidentifiedUser(options: { [key: string]: number | string }): Promise { return; } /** - * This resets the Intercom integration's cache of your user's identity and wipes the slate clean. - * - * @returns {Promise} Returns a promise + * Log a user out of their Intercom session. + * This will dismiss any Intercom UI and clear Intercom's local cache. */ @Cordova() - reset(): Promise { + logout(): Promise { return; } /** + * Set `hash` string if you are using Identity Verification for your Intercom workspace. + * @note This should be called before any user login takes place. * - * @returns {Promise} Returns a promise + * Identity Verification helps to make sure that conversations between you and your users are kept private, and that one + * user can't impersonate another. If Identity Verification is enabled for your app, Intercom will sign all requests + * going to the Intercom servers with tokens. It requires your mobile application to have its own server which authenticates the app's users, + * and which can store a secret. + * + * @see More information on Identity Verification can be found {@link https://developers.intercom.com/installing-intercom/cordova-phonegap/identity-verification/ here} + * @param secureHash A HMAC digest of the user ID or email. */ @Cordova() - logout(): Promise { + setUserHash(secureHash: string): Promise { return; } /** + * Update a user in Intercom with data specified in an object. * - * @param secureHash {string} - * @param secureData {any} - * @returns {Promise} Returns a promise - * @deprecated Use setUserHash instead as of Intercom Cordova 4.0.0 and higher https://github.com/intercom/intercom-cordova/blob/master/CHANGELOG.md#400-2017-08-29 + * @param attributes The object with the user data. */ @Cordova() - setSecureMode(secureHash: string, secureData: any): Promise { + updateUser(attributes: IntercomUserAttributes): Promise { return; } /** + * Log an event with a given name and metaData. + * You can log events in Intercom based on user actions in your app. * - * @param secureHash {string} - * @returns {Promise} Returns a promise + * @param eventName The name of the event. + * @param metaData Metadata Objects support a few simple types that Intercom can present on your behalf, + * @see https://developers.intercom.com/docs/references/rest-api/api.intercom.io/Data-Events/data_event/ Intercom API docs */ @Cordova() - setUserHash(secureHash: string): Promise { + logEvent(eventName: string, metaData: IntercomEventMetaData): Promise { return; } /** - * - * @param attributes {any} - * @returns {Promise} Returns a promise + * Present Intercom as a modal overlay in your app. + * The `Home` space is displayed by default. */ @Cordova() - updateUser(attributes: any): Promise { + present(): Promise { return; } /** + * Present an Intercom `space` as a modal overlay in your app + * @see {@link Space} for a list of valid spaces. * - * @param eventName {string} - * @param metaData {any} - * @returns {Promise} Returns a promise + * @param space The Intercom space to be presented. */ @Cordova() - logEvent(eventName: string, metaData: any): Promise { + presentSpace(space: IntercomSpace): Promise { return; } /** + * Present Intercom content. * - * @returns {Promise} Returns a promise + * An IntercomContent object. */ @Cordova() - displayMessenger(): Promise { + presentContent(content: IntercomPresentContent): Promise { return; } /** + * Present the message composer. * - * @returns {Promise} Returns a promise + * @param initialMessage An optional message that is used to pre-populate the composer with some text. */ @Cordova() - displayMessageComposer(): Promise { + presentMessageComposer(initialMessage: string): Promise { return; } /** + * Fetch all Help Center collections. * - * @param initialMessage {string} - * @returns {Promise} Returns a promise + * @return An array of HelpCenterCollection objects. */ @Cordova() - displayMessageComposerWithInitialMessage(initialMessage: string): Promise { + fetchHelpCenterCollections(): Promise { return; } /** + * Fetch the contents of a Help Center collection. + * + * @param collectionId The ID of the Help Center collection. * - * @returns {Promise} Returns a promise + * @return A HelpCenterCollectionContent object. */ @Cordova() - displayConversationsList(): Promise { + fetchHelpCenterCollection(collectionId: string): Promise { return; } /** + * Search the Help Center. * - * @returns {Promise} Returns a promise + * @param searchTerm The search term. + * + * @return An array of HelpCenterArticleSearchResult objects. */ @Cordova() - displayHelpCenter(): Promise { + searchHelpCenter(searchTerm: string): Promise { return; } /** - * - * @returns {Promise} Returns a promise + * Fetch the current number of unread conversations for the logged in User. + * @return The number of unread conversations. */ @Cordova() - unreadConversationCount(): Promise { + unreadConversationCount(): Promise { return; } /** + * Show or hide the Intercom Launcher in your app. + * @note The Launcher is hidden by default. * - * @param visibility {string} - * @returns {Promise} Returns a promise + * @param visibility A boolean indicating if the Intercom Launcher should be visible. */ @Cordova() - setLauncherVisibility(visibility: string): Promise { + setLauncherVisibility(visibility: IntercomVisibility): Promise { return; } /** + * Show or hide the Intercom InApp Messages in your app. + * @note All InApp Messages are visible by default. * - * @param visibility {string} - * @returns {Promise} Returns a promise + * @param visibility A boolean indicating if the InApps should be visible. */ @Cordova() - setInAppMessageVisibility(visibility: string): Promise { + setInAppMessageVisibility(visibility: IntercomVisibility): Promise { return; } /** - * - * @returns {Promise} Returns a promise + * Hide all Intercom windows that are currently displayed. + * This will hide the Messenger, Help Center, Articles, and in-product messages (eg. Mobile Carousels, chats, and posts). */ @Cordova() - hideMessenger(): Promise { + hideIntercom(): Promise { return; } /** - * - * @returns {Promise} Returns a promise + * Set a fixed bottom padding for in app messages and the Intercom Launcher. + * @param bottomPadding The size of the bottom padding in points. */ @Cordova() - registerForPush(): Promise { + setBottomPadding(bottomPadding: number): Promise { return; } /** - * - * @param token {string} - * @returns {Promise} Returns a promise + * Register for push notifications + * @note This function is only available for iOS. */ @Cordova() - sendPushTokenToIntercom(token: string): Promise { + registerForPush(): Promise { return; } /** + * Send a device token to Intercom to enable push notifications to be sent to the User. + * @param token The device token to send to the server. * - * @param carouselId {string} - * @returns {Promise} Returns a promise + * @note This function is only available for Android. */ @Cordova() - displayCarousel(carouselId: string): Promise { + sendPushTokenToIntercom(token: string): Promise { return; } /** - * - * @param articleId {string} - * @returns {Promise} Returns a promise + * @deprecated */ @Cordova() - displayArticle(articleId: string): Promise { + registerIdentifiedUser(options: any): Promise { return; } /** - * - * @param bottomPadding {string | number} - * @returns {Promise} Returns a promise + * @deprecated + */ + @Cordova() + registerUnidentifiedUser(options: any): Promise { + return; + } + + /** + * @deprecated */ @Cordova() - setBottomPadding(bottomPadding: string | number): Promise { + reset(): Promise { return; } /** - * Programmatically display a Survey - * @param surveyId {string} - * @returns {Promise} Returns a promise + * @deprecated + */ + @Cordova() + displayMessenger(): Promise { + return; + } + + /** + * @deprecated + */ + @Cordova() + displayHelpCenter(): Promise { + return; + } + + /** + * @deprecated + */ + @Cordova() + displayMessageComposerWithInitialMessage(initialMessage: string): Promise { + return; + } + + /** + * @deprecated + */ + @Cordova() + displayMessageComposer(): Promise { + return; + } + + /** + * @deprecated + */ + @Cordova() + displayHelpCenterCollections(collectionIds: string[]): Promise { + return; + } + + /** + * @deprecated + */ + @Cordova() + displayCarousel(carouselId: string): Promise { + return; + } + + /** + * @deprecated + */ + @Cordova() + displayArticle(articleId: string): Promise { + return; + } + + /** + * @deprecated */ @Cordova() displaySurvey(surveyId: string): Promise { return; } } + +export enum IntercomVisibility { + VISIBLE = 'VISIBLE', + GONE = 'GONE', +} + +export enum IntercomSpace { + Home = 'HOME', + HelpCenter = 'HELP_CENTER', + Messages = 'MESSAGES', + Tickets = 'TICKETS', +} + +export interface IntercomHelpCenterCollectionContent { + collectionId: string; + title: string; + summary: string; + articles: any[]; + sections: any[]; +} + +export enum IntercomPresentContentType { + Article = 'ARTICLE', + Carousel = 'CAROUSEL', + Survey = 'SURVEY', + HelpCenterCollections = 'HELP_CENTER_COLLECTIONS', + Conversation = 'CONVERSATION', +} + +export type IntercomPresentContent = + | { id: string; type: IntercomPresentContentType } + | { ids: string[]; type: IntercomPresentContentType }; + +export interface IntercomUserAttributes { + email?: string; + user_id?: string; + name?: string; + phone?: string; + language_override?: string; + signed_up_at?: string; + unsubscribed_from_emails?: string; + custom_attributes?: string; + companies?: string[]; +} + +export interface IntercomEventMetaData { + created_at: string; + type?: string; + metadata?: any; + [key: string]: number | string | { [key: string]: number | string }; +} + +export type IntercomLoginUserAttributes = + | { + email: string; + } + | { + userId: string; + } + | { + email: string; + userId: string; + }; + +export interface IntercomHelpCenterArticleSearchResult { + articleId: string; + title: string; + summary: string; + matchingSnippet: string; +}