UNPKG

@kustomer/chat-react-native

Version:

Kustomer Chat SDK wrapper for React Native

98 lines (97 loc) 4.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KustomerPushProvider = exports.KustomerKbProvider = exports.KustomerChatProvider = exports.KustomerChat = exports.KustomerAuthProvider = void 0; var _reactNative = require("react-native"); var _types = require("./types"); function getLinkingErrorText(moduleName) { return `The package '@kustomer/chat-react-native' doesn't seem to be linked.\n` + `Looking for module '${moduleName}'. Make sure: \n\n` + _reactNative.Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; } function getLinkingErrorProxy(moduleName) { return new Proxy({}, { get() { // throw new Error(getLinkingErrorText(moduleName)); console.error(new Error(getLinkingErrorText(moduleName))); return null; } }); } const RNKustomerChatProvider = _reactNative.NativeModules.RNKustomerChatProvider ?? getLinkingErrorProxy('RNKustomerChatProvider'); const KustomerChatProvider = exports.KustomerChatProvider = RNKustomerChatProvider; const RNKustomerAuthProvider = _reactNative.NativeModules.RNKustomerAuthProvider ?? getLinkingErrorProxy('RNKustomerAuthProvider'); const KustomerAuthProvider = exports.KustomerAuthProvider = RNKustomerAuthProvider; const RNKustomerPushProvider = _reactNative.NativeModules.RNKustomerPushProvider ?? getLinkingErrorProxy('RNKustomerPushProvider'); const KustomerPushProvider = exports.KustomerPushProvider = RNKustomerPushProvider; const RNKustomerKbProvider = _reactNative.NativeModules.RNKustomerKbProvider ?? getLinkingErrorProxy('RNKustomerKbProvider'); const KustomerKbProvider = exports.KustomerKbProvider = RNKustomerKbProvider; const RNKustomerChat = _reactNative.NativeModules.RNKustomerChat ?? getLinkingErrorProxy('RNKustomerChat'); const KustomerChat = exports.KustomerChat = { ...RNKustomerChat, close(animated = true) { return RNKustomerChat.close(animated); }, configure(apiKey, options = {}) { return RNKustomerChat.configure(apiKey, options).then(() => { if (options?.disablePush || options?.skipFCMPushRegistration) return; try { const firebaseMessaging = require('@react-native-firebase/messaging').default; async function setToken(token) { const v = await _reactNative.Platform.select({ ios: firebaseMessaging().getAPNSToken(), android: Promise.resolve(token) }); RNKustomerChat.setPushToken(v); } _reactNative.Platform.select({ ios: firebaseMessaging().getAPNSToken(), android: firebaseMessaging().getToken() }).then(RNKustomerChat.setPushToken); firebaseMessaging().onTokenRefresh(setToken); firebaseMessaging().onMessage(message => { KustomerChat.onRemoteMessage(message); }); } catch (e) { if (options?.disablePush !== true) console.warn('Kustomer: @react-native-firebase/messaging is not installed. Push notifications will not work.'); return; } }); }, describeCustomer(attributes, customAttributes) { const deprecatedProperties = ['emails', 'phones', 'socials']; for (const key in attributes) { if (deprecatedProperties.includes(key)) { console.warn(`Kustomer: The attribute ${key} is deprecated. Please use shared${key.charAt(0).toUpperCase()}${key.slice(1)} instead.`); } } return RNKustomerChatProvider.describeCustomer({ ...attributes, custom: customAttributes }); }, describeConversation(conversationId, attributes) { return RNKustomerChatProvider.describeConversation(conversationId, attributes); }, isKustomerNotification(message) { return message.data?.name?.includes('kustomer') ?? false; }, show(displayMode = _types.KustomerDisplayMode.default) { return RNKustomerChat.show(displayMode); }, isChatAvailable() { return RNKustomerChat.isChatAvailable ? RNKustomerChat.isChatAvailable() : RNKustomerChatProvider.isChatAvailable(); }, openConversation(conversationId, animated = true) { return _reactNative.Platform.OS === 'ios' ? RNKustomerChat.openConversation(conversationId, animated) : RNKustomerChat.openConversation(conversationId); }, startNewConversation(initialMessage, customDescribe, animated = _reactNative.Platform.OS === 'ios') { return RNKustomerChat.startNewConversation(initialMessage, customDescribe, animated); }, openChatAssistant(chatAssistantId, startDialog, initialMessages, customDescribe, animated = _reactNative.Platform.OS === 'ios') { return RNKustomerChat.openChatAssistant(chatAssistantId, startDialog, initialMessages, customDescribe, animated); } }; //# sourceMappingURL=NativeModules.js.map