# @sayparlo/react-native

Voice feedback and help requests for Expo and React Native apps, powered by [Parlo](https://sayparlo.com).

Your users tap a button, speak (or type), and the feedback lands in your Parlo inbox, transcribed, summarized and sorted.

## Requirements

- Expo SDK 53 or newer (or a bare React Native app with Expo modules)
- An app added in Parlo: **Sites → Add → Mobile app**, to get its key (`pk_…`)

## Install

```sh
npx expo install @sayparlo/react-native expo-audio expo-application expo-device
```

Declare the microphone in `app.json`, then rebuild your development build:

```json
{
  "expo": {
    "plugins": [["expo-audio", { "microphonePermission": "Allow $(PRODUCT_NAME) to use the microphone for voice feedback." }]]
  }
}
```

## Usage

Wrap your app once, at the root (`App.tsx`, or `app/_layout.tsx` with Expo Router):

```tsx
import { ParloProvider } from '@sayparlo/react-native'

export default function App() {
  return (
    <ParloProvider siteKey="pk_your_key" apiUrl="https://parlo.threading.site" showButton>
      <Navigation />
    </ParloProvider>
  )
}
```

`showButton` displays a floating "Give feedback" button. To open Parlo from your own buttons:

```tsx
import { useParlo } from '@sayparlo/react-native'

function Settings() {
  const parlo = useParlo()
  return (
    <>
      <Button title="Give feedback" onPress={() => parlo.open()} />
      <Button title="Get help" onPress={() => parlo.open({ intent: 'support' })} />
    </>
  )
}
```

## Identify your users

```tsx
const parlo = useParlo()

useEffect(() => {
  parlo.identify(user ? { id: user.id, email: user.email, name: user.name, hash: user.parloHash } : null)
}, [user])
```

`hash` proves the identity: compute it **on your server**, as the HMAC-SHA256 of the user id with the secret shown in Parlo (Sites → your app → Identification). Never ship the secret in the app.

```js
// Node.js, on your server
const hash = createHmac('sha256', PARLO_IDENTITY_SECRET).update(String(user.id)).digest('hex')
```

## Context, screen and version

```tsx
parlo.setContext({ plan: 'pro', account: 'Acme' }) // 20 keys at most: text, number or boolean
parlo.setScreen('Checkout') // shown as the "page" of the feedback
parlo.setVersion('2.4.1') // read from the native build by default
```

With Expo Router, follow the current route:

```tsx
const pathname = usePathname()
useEffect(() => parlo.setScreen(pathname), [pathname])
```

## Screenshots

Install `react-native-view-shot` and pass a capture function: users can then attach a screenshot of the app to their feedback.

```tsx
import { captureScreen } from 'react-native-view-shot'

<ParloProvider siteKey="pk_your_key" captureScreen={() => captureScreen({ format: 'jpg', quality: 0.7 })}>
```

## Props

| Prop | Default | |
| --- | --- | --- |
| `siteKey` | (required) | Key of the app in Parlo |
| `apiUrl` | `https://parlo.threading.site` | Address of Parlo |
| `showButton` | `false` | Floating "Give feedback" button |
| `buttonPosition` | `bottom-right` | Or `bottom-left` |
| `user` | | Signed-in user (same as `identify`) |
| `context` | | Context sent with each feedback |
| `version` | native version | App version |
| `locale` | Parlo setting, then device | `fr`, `en`, `es`, `de`, `it`, `pt`, `nl` |
| `testMode` | `__DEV__` | Marks feedbacks as tests (left out of statistics) |
| `captureScreen` | | Enables screenshots |
| `appId` | bundle id | Shown in the "page" of feedbacks |

Colour, question and language are set in Parlo (Sites → your app → Appearance) and apply without a new release.

## Privacy

The microphone is only requested when the user taps "Speak". No device identifier is collected: feedbacks carry the device model, OS version, app version and what you pass yourself.

## Releasing (maintainers)

1. Bump `version` in `package.json`, merge to `main`.
2. Create a GitHub release with the tag `vX.Y.Z`: the **Publish to npm** workflow publishes it with npm trusted publishing (no token).
