React Native
Add Kustomer Chat to a React Native app with @kustomer/chat-react-native. Installation for iOS and Android, configure, host-owned attachments, opening the chat UI, events and hooks, identity, push, and the platform differences to know about.
@kustomer/chat-react-native wraps the native iOS and Android SDKs, so your app gets the native chat UI on each platform from one JavaScript API.
Install
Add the package
Shellnpm install @kustomer/chat-react-nativeFor push notifications, also install
@react-native-firebase/appand@react-native-firebase/messaging.iOS
Set the platform in your
Podfileand install pods:ios/Podfileplatform :ios, '15.1'Shellcd ios && pod installAdd usage descriptions for attachments to
Info.plist:NSCameraUsageDescription,NSPhotoLibraryUsageDescription,NSPhotoLibraryAddUsageDescriptionandNSMicrophoneUsageDescription.Android
The Android SDK needs Kotlin 2.2 or later and, on minSdk 24 and 25, core library desugaring:
android/build.gradlebuildscript { ext { kotlinVersion = "2.2.21" } }android/app/build.gradleandroid { compileOptions { coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } } dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5") }The build stops with a clear error if
kotlinVersionis older than 2.2.0 or isn't a fullMAJOR.MINOR.PATCHversion.Configure
App.tsximport { useEffect } from 'react' import KustomerChat from '@kustomer/chat-react-native' export default function App() { useEffect(() => { KustomerChat.configure(KUSTOMER_CHAT_KEY, { brandId: 'YOUR_BRAND_ID' }).catch((e) => console.error('Kustomer configure failed', e), ) }, []) return <Root /> }Use a chat key with only the
org.trackingrole. Callconfigureonce, early.useIsKustomerConfigured()returnstrueonce it's done.Open chat
TSX<Button title="Help" onPress={() => KustomerChat.show()} />
React Native 0.77 on Android
These are needed on React Native 0.77 with AGP 8.7, as in Kustomer's example app:
- In
android/gradle.properties, setreact.internal.disableJavaVersionAlignment=true. - In
android/settings.gradle, override R8 to 8.10.21 or later. - If the build reports a duplicate
META-INF/versions/9/OSGI-INF/MANIFEST.MF, add it topackaging.resources.pickFirsts.
Options
Files in your own storage
If customer files must stay in your storage, for compliance, retention or scanning, take over the paperclip with onAttachmentButtonTapped (6.4.0 or later). The native SDKs then skip their own pickers. Your app picks the file, uploads it to your storage, and reports the result through the completion helpers. On success the SDK registers your URL with Kustomer as an external attachment and sends the message. In a new chat it creates the conversation first.
import KustomerChat, { type KustomerOptions } from '@kustomer/chat-react-native'
import { Image, Platform } from 'react-native'
const options: KustomerOptions = {
// Optional card art: iOS local URI / asset name; Android drawable name
externalAttachmentImage:
Platform.OS === 'ios'
? Image.resolveAssetSource(require('./assets/brand-file.png')).uri
: 'brand_file',
onAttachmentButtonTapped: async ({ conversationId }, completion) => {
try {
const uploaded = await myPickerAndUpload({ conversationId })
completion.onSuccess({
name: uploaded.fileName,
contentType: uploaded.mimeType,
contentLength: uploaded.byteCount,
url: uploaded.httpsUrl,
contentHash: uploaded.sha256Hex, // optional; host-side only, not sent on create
})
} catch (error) {
if (isUserCancel(error)) completion.onCancelled()
else completion.onFailure(error instanceof Error ? error : String(error))
}
},
}
await KustomerChat.configure(KUSTOMER_CHAT_KEY, options)- Prefer the configure callback above. Functions cannot cross the native bridge, so the package strips
onAttachmentButtonTappedfrom the native options object, setsenableHostOwnedAttachments: true, and wires the event plus completion for you. - For event-only wiring, set
enableHostOwnedAttachments: truein the initial configure options and omit the callback. Subscribe toonAttachmentButtonTappedwithuseKustomerEvent/KustomerEventEmitter, then callKustomerChat.completeExternalAttachment(requestId, result)with{ status: 'success', attachment },{ status: 'cancelled' }, or{ status: 'failure', errorMessage: 'upload failed' }(errorMessageis optional). conversationIdmay be missing in a brand-new draft chat.urlmust be an absolutehttpsURL. Name and content type can't be blank;contentLengthmust be a non-negative number.contentHashis accepted for your own integrity checks and isn't sent to Kustomer.- Customers and agents see a card with the file's name instead of a preview. The SDK never downloads your URL and never sends an
Authorizationheader to your host. Agents copy the link and open it in their browser. - On Android, while the Kustomer chat Activity is in the foreground your JS thread may pause (same as
KustomerChat.close). Use Headless JS or a background timer if the handler must keep running while chat is open.
Open the UI
import KustomerChat, { KustomerDisplayMode } from '@kustomer/chat-react-native'
KustomerChat.show()
KustomerChat.show(KustomerDisplayMode.onlyKnowledgeBase)
const conversation = await KustomerChat.startNewConversation(
{ body: 'Where is my order?', direction: 'user' },
{ orderNumberStr: '4417' },
)
await KustomerChat.openConversation('6716a3a9c4e5f60012ab34c1')
KustomerChat.showKbArticle('ARTICLE_ID')
await KustomerChat.close()Don't await show() or the showKb* methods: their promises don't resolve consistently across platforms.
On Android, chat opens as a separate Activity, so your app goes to the background and JavaScript timers pause while it's open.
Other methods on KustomerChat
To create a conversation without opening the UI, use KustomerChatProvider.createConversation:
import { KustomerChatProvider } from '@kustomer/chat-react-native'
const { conversation } = await KustomerChatProvider.createConversation({
firstMessage: 'I need help with my order',
title: 'Order 4417',
customDescribe: { orderNumberStr: '4417' },
})Events
import { useCallback, useState } from 'react'
import { useKustomerEvent } from '@kustomer/chat-react-native'
function UnreadBadge() {
const [count, setCount] = useState(0)
const onTotal = useCallback(({ count }: { count: number }) => setCount(count), [])
useKustomerEvent('onUnreadTotalChange', onTotal)
return count ? <Badge value={count} /> : null
}useKustomerEvent re-subscribes when the callback changes, so wrap it in useCallback. Outside components, use KustomerEventEmitter.addListener(event, cb), which returns a subscription with remove(). Subscribe after configure resolves.
Payloads differ slightly between platforms for onAgentJoined, onAssistantEnded and onSatisfactionEventReceived; read fields defensively.
Identity
const signedIn = await KustomerChat.isLoggedIn('email', user.email)
if (!signedIn) await KustomerChat.logIn(jwtFromYourServer)
await KustomerChat.describeCustomer(
{ sharedPhones: ['+15555550123'] },
{ loyaltyTierStr: 'gold' },
)
// on sign-out
await KustomerChat.logOut()See Customer identity for generating the JWT.
Push notifications
Android uses Firebase Cloud Messaging and is automatic: with @react-native-firebase/messaging installed, configure registers the FCM token, re-registers on refresh, and handles foreground messages. To do it yourself, set skipFCMPushRegistration: true:
import messaging from '@react-native-firebase/messaging'
messaging().getToken().then(KustomerChat.setPushToken)
messaging().onTokenRefresh(KustomerChat.setPushToken)
messaging().onMessage((message) => {
if (KustomerChat.isKustomerNotification(message)) KustomerChat.onRemoteMessage(message)
})setPushToken and onRemoteMessage are Android only.
iOS uses APNs and needs native code in your AppDelegate, the same as the native SDK. The automatic FCM registration only works on Android, so set skipFCMPushRegistration: Platform.OS === 'ios'. See Push notifications.