@freshworks/react-native-freshdesk-sdk
Version:
React Native wrapper for Freshdesk Android and iOS SDKs
253 lines (166 loc) • 8 kB
Markdown
# Freshdesk React Native Integration — Examples
Worked scenarios for AI agents using the `freshdesk-react-native-integration` skill.
## Example 1 — New app: ask host & locale, file-based secrets
**User prompt:** "Integrate Freshdesk into my new React Native app."
**Mode:** A (greenfield)
**Agent actions:**
1. **Phase 1 — Ask interactively:**
- Host: user provides `acme.freshdesk.com`
- Locale: user provides `en`
- Platforms: both; push: no; JWT: no
2. **Phase 2 — Point to files (do not ask for token in chat):**
- Create `.env` with `FRESHDESK_HOST` and `FRESHDESK_LOCALE` filled; leave `FRESHDESK_TOKEN` and `FRESHDESK_SDK_ID` as placeholders.
- Tell user: "Copy token and SDK ID from Admin → Mobile Chat SDK into `.env`."
- Wait for confirmation.
3. **Phase 4 inventory:**
- Init: no existing code → create `FreshdeskProvider`
- Support button: no → add to Settings screen
- Push: skipped
- JWT: skipped
- Listeners: no → add unread count in provider
4. **Phase 5–6:** `pod install`, build, run diagnostics.
**Expected:** Widget opens; `runtime.sdkInitialized: pass`.
---
## Example 2 — User has existing support button, no push
**User prompt:** "I have a Help button on ProfileScreen — wire Freshdesk there."
**Mode:** A
**Agent actions:**
1. Collect host + locale; credential file paths.
2. Phase 4.2 — **Yes, existing code:** inspect `ProfileScreen.tsx`, find `onPress` handler, wire:
```typescript
await FreshdeskSDK.openSupport();
```
3. Phase 4.1 — **No init code:** add provider at app root.
4. Skip push native wiring (JS init sufficient for in-app widget).
---
## Example 3 — User has FCM service, needs Freshdesk added
**User prompt:** "We already have FirebaseMessagingService — add Freshdesk push."
**Mode:** A or B
**Agent actions:**
1. Phase 4.4 — **Yes, existing FCM code:** open their messaging service.
2. Show Android APIs (native Kotlin, not JS):
```kotlin
FreshdeskSDK.setPushRegistrationToken(token)
if (FreshdeskSDK.isFreshdeskSDKNotification(remoteMessage)) {
FreshdeskSDK.handleFCMNotification(remoteMessage)
}
```
3. Ensure native init in `MainApplication.onCreate()` with `BuildConfig` credentials.
4. Phase 2b — user updates `build.gradle` BuildConfig fields from portal.
5. Run diagnostics; check `push.messagingService`.
---
## Example 4 — Full greenfield with push both platforms
**User prompt:** "Freshdesk with push on Android and iOS, no existing code."
**Mode:** A
**Agent actions:**
1. Host + locale from user; secrets via `.env`, `build.gradle`, `Info.plist`.
2. All Phase 4 areas → **No** → agent creates:
- `FreshdeskProvider`
- Support FAB
- `FreshdeskMessagingService.kt` + `MainApplication` init
- `AppDelegate` init + push forwarding + capabilities
3. Phase 6 diagnostics on real iOS device.
**Pitfall:** JS-only init — push token arrives before JS. Native init mandatory.
---
## Example 5 — JWT enforced, existing auth flow
**User prompt:** "Widget requires JWT; we refresh tokens in AuthContext."
**Mode:** A
**Agent actions:**
1. Phase 1: JWT enforced = yes.
2. Phase 4.3 — **Yes, existing auth:** show APIs:
```typescript
await FreshdeskSDK.initialize({ ..., jwt: initialJwt });
await FreshdeskSDK.authenticateAndUpdate(newJwt); // on refresh
FreshdeskSDK.addUserStateListener(({ state }) => {
if (state === 'authExpired') { /* fetch new jwt */ }
});
await FreshdeskSDK.resetUser(); // on logout
```
3. Wire into their `AuthContext` token refresh and logout.
4. Do not use `setUserProperties` for identity.
---
## Example 6 — Debug init failure
**User prompt:** "Freshdesk won't initialize — FRESHDESK_INVALID_CONFIG."
**Mode:** B
**Agent actions:**
1. Run diagnostics (or inspect env directly).
2. Verify `.env` has non-empty `FRESHDESK_TOKEN`, `FRESHDESK_HOST`, `FRESHDESK_SDK_ID`.
3. Verify `@env` babel plugin and Metro restart after `.env` change.
4. If push: verify `BuildConfig` / `Info.plist` match `.env`.
5. Re-run; expect `config.*` checks pass on iOS.
---
## Example 7 — iOS-only API: addUserCreatedListener
**User prompt:** "Track when Freshdesk creates a new user on iOS."
**Agent actions:**
1. Note from [platform-apis.md](platform-apis.md): `addUserCreatedListener` is **iOS only**.
2. Guard with `Platform.OS === 'ios'` or document Android no-op.
3. Wire listener in provider after init.
---
## Example 8 — Debug: iOS support widget silently does nothing
**User prompt:** "openSupport() doesn't do anything on iOS — no error, nothing opens. Works fine on Android, and sometimes iOS works if I tap the button again."
**Mode:** B
**Agent actions:**
1. Recognize the pattern: `initialize()` resolved, no error, but the very
first call right after fails intermittently, and a retry a moment later
works. This is [platform-apis.md](platform-apis.md)'s documented iOS
`initialize()` settle-delay behavior, not a credentials problem — do
**not** jump straight to re-checking token/host/sdkId.
2. Ask (or check `package.json`) which SDK version is installed. If it
predates the settle-delay fix (check `CHANGELOG.md`), the fix is: upgrade.
3. If already on a version with the fix and this still happens, *then*
treat it as a real bug — run diagnostics, check network reachability to
the host, and don't assume it's this known issue.
4. Do not "fix" this by wrapping every call in a retry loop — that papers
over a timing bug instead of confirming which case it actually is.
---
## Example 9 — Q&A: "How do I open FAQ without chat?"
**User prompt:** "Can I open the knowledge base directly without going through support?"
**Mode:** C (knowledge base)
**Agent actions:**
1. Search [integration-knowledge-base.md](integration-knowledge-base.md) → Opening support & knowledge base.
2. Answer directly:
```typescript
await FreshdeskSDK.initialize({ token, host, sdkId });
await FreshdeskSDK.openKnowledgeBase();
```
3. Note: `openSupport()` opens the support home (chat entry); `openKnowledgeBase()` skips to FAQ/articles.
4. Do not start greenfield workflow unless user asks to wire it in.
---
## Example 11 — Integration complete: output summary + FAQ link
**User prompt:** "Integrate Freshdesk into my app." (after agent finishes wiring)
**Mode:** A — final output
**Agent must output:**
```markdown
## Freshdesk integration summary
### Credentials — you update manually
- `.env` — set FRESHDESK_TOKEN, FRESHDESK_SDK_ID from portal (host/locale already set)
### Files changed
| Area | File | What changed |
|------|------|--------------|
| npm | package.json | Added @freshworks/react-native-freshdesk-sdk |
| JS | src/providers/FreshdeskProvider.tsx | Created init + listeners |
| JS | App.tsx | Wrapped with FreshdeskProvider |
| JS | src/screens/SettingsScreen.tsx | Help button → openSupport() |
### APIs wired
- initialize, openSupport, addUnreadCountListener
### Manual steps for you
1. Fill token and sdkId in `.env`
2. cd ios && pod install && rebuild
3. Open Help, run diagnostics
### Docs & FAQ
- [Integration FAQ](ai/skills/freshdesk-react-native-integration/integration-faq.md)
- [Knowledge base](ai/skills/freshdesk-react-native-integration/integration-knowledge-base.md)
```
---
**User prompt:** "Is Firebase required to use Freshdesk chat in my app?"
**Mode:** C
**Agent actions:**
1. Answer: **No.** Firebase/APNs are only for **push notifications**. In-app support, chat, and KB work with JS `initialize()` only.
2. Mention push is optional and native-only if they ask about notifications later.
---
**User prompt:** "Diagnostics looks incomplete on Android."
**Agent actions:**
1. Explain Android returns wrapper checks; `runtime.diagnostics: skipped` is expected.
2. Enable `debugMode: true` in `initialize()` for Logcat.
3. Use iOS device/simulator for full structured report when needed.
4. Fix wrapper-level failures (`runtime.sdkInitialized`, `push.messagingService`) first.