UNPKG

@intercom/intercom-react-native

Version:

React Native wrapper to bridge our iOS and Android SDK

119 lines 5.25 kB
import { NativeModules, NativeEventEmitter, Platform } from 'react-native'; const { IntercomModule, IntercomEventEmitter } = NativeModules; export let Visibility = /*#__PURE__*/function (Visibility) { Visibility["GONE"] = "GONE"; Visibility["VISIBLE"] = "VISIBLE"; return Visibility; }({}); export let LogLevel = /*#__PURE__*/function (LogLevel) { LogLevel["ASSERT"] = "ASSERT"; LogLevel["DEBUG"] = "DEBUG"; LogLevel["DISABLED"] = "DISABLED"; LogLevel["ERROR"] = "ERROR"; LogLevel["INFO"] = "INFO"; LogLevel["VERBOSE"] = "VERBOSE"; LogLevel["WARN"] = "WARN"; return LogLevel; }({}); export const IntercomEvents = { IntercomUnreadCountDidChange: IntercomEventEmitter.UNREAD_COUNT_CHANGE_NOTIFICATION, IntercomWindowDidHide: IntercomEventEmitter.WINDOW_DID_HIDE_NOTIFICATION, IntercomWindowDidShow: IntercomEventEmitter.WINDOW_DID_SHOW_NOTIFICATION, IntercomHelpCenterWindowDidShow: IntercomEventEmitter.WINDOW_DID_SHOW_NOTIFICATION, IntercomHelpCenterWindowDidHide: IntercomEventEmitter.WINDOW_DID_HIDE_NOTIFICATION }; export let Space = /*#__PURE__*/function (Space) { Space["home"] = "HOME"; Space["helpCenter"] = "HELP_CENTER"; Space["messages"] = "MESSAGES"; Space["tickets"] = "TICKETS"; return Space; }({}); const Intercom = { loginUnidentifiedUser: () => IntercomModule.loginUnidentifiedUser(), loginUserWithUserAttributes: userAttributes => IntercomModule.loginUserWithUserAttributes(userAttributes), logout: () => IntercomModule.logout(), setUserHash: hash => IntercomModule.setUserHash(hash), updateUser: userAttributes => IntercomModule.updateUser(userAttributes), isUserLoggedIn: () => IntercomModule.isUserLoggedIn(), fetchLoggedInUserAttributes: () => IntercomModule.fetchLoggedInUserAttributes(), logEvent: (eventName, metaData = undefined) => IntercomModule.logEvent(eventName, metaData), fetchHelpCenterCollections: () => IntercomModule.fetchHelpCenterCollections(), fetchHelpCenterCollection: (id = '') => IntercomModule.fetchHelpCenterCollection(id), searchHelpCenter: (term = '') => IntercomModule.searchHelpCenter(term), present: () => IntercomModule.presentIntercom(), presentSpace: space => IntercomModule.presentIntercomSpace(space), presentContent: content => IntercomModule.presentContent(content), presentMessageComposer: (initialMessage = undefined) => IntercomModule.presentMessageComposer(initialMessage), getUnreadConversationCount: () => IntercomModule.getUnreadConversationCount(), hideIntercom: () => IntercomModule.hideIntercom(), setBottomPadding: paddingBottom => IntercomModule.setBottomPadding(paddingBottom), setInAppMessageVisibility: visibility => IntercomModule.setInAppMessageVisibility(visibility), setLauncherVisibility: visibility => IntercomModule.setLauncherVisibility(visibility), setNeedsStatusBarAppearanceUpdate: Platform.select({ ios: IntercomModule.setNeedsStatusBarAppearanceUpdate, default: async () => true }), handlePushMessage: Platform.select({ android: IntercomModule.handlePushMessage, default: async () => true }), sendTokenToIntercom: token => IntercomModule.sendTokenToIntercom(token), setLogLevel: logLevel => IntercomModule.setLogLevel(logLevel), addEventListener: (event, callback) => { event === IntercomEvents.IntercomUnreadCountDidChange && Platform.OS === 'android' && IntercomEventEmitter.startEventListener(); const eventEmitter = new NativeEventEmitter(IntercomEventEmitter); const listener = eventEmitter.addListener(event, callback); const originalRemove = listener.remove; listener.remove = () => { event === IntercomEvents.IntercomUnreadCountDidChange && Platform.OS === 'android' && IntercomEventEmitter.removeEventListener(); originalRemove(); }; return listener; } }; export default Intercom; export let ContentType = /*#__PURE__*/function (ContentType) { ContentType["Article"] = "ARTICLE"; ContentType["Carousel"] = "CAROUSEL"; ContentType["Survey"] = "SURVEY"; ContentType["HelpCenterCollections"] = "HELP_CENTER_COLLECTIONS"; ContentType["Conversation"] = "CONVERSATION"; return ContentType; }({}); export const IntercomContent = { articleWithArticleId(articleId) { let articleContent = {}; articleContent.type = ContentType.Article; articleContent.id = articleId; return articleContent; }, carouselWithCarouselId(carouselId) { let carouselContent = {}; carouselContent.type = ContentType.Carousel; carouselContent.id = carouselId; return carouselContent; }, surveyWithSurveyId(surveyId) { let surveyContent = {}; surveyContent.type = ContentType.Survey; surveyContent.id = surveyId; return surveyContent; }, helpCenterCollectionsWithIds(collectionIds) { let helpCenterCollectionsContent = {}; helpCenterCollectionsContent.type = ContentType.HelpCenterCollections; helpCenterCollectionsContent.ids = collectionIds; return helpCenterCollectionsContent; }, conversationWithConversationId(conversationId) { let conversationContent = {}; conversationContent.type = ContentType.Conversation; conversationContent.id = conversationId; return conversationContent; } }; //# sourceMappingURL=index.js.map