Cohere React Native
cohere-react-native
is a React Native library that allows you to easily integrate the Cohere voice chat widget into your React Native applications. The library provides the CohereProvider, useCohere, and CohereWidget components to help you manage user identification, context, and the rendering of the chat widget.
Installation
To install the cohere-react-native library, use the following command:
npm install cohere-react-native react-native-webview
npx pod-install
Usage
Here's how you can use the CohereProvider
, useCohere
, and CohereWidget
components in your React Native application:
import { CohereProvider, useCohere, CohereWidget } from 'cohere-react-native';
export default function App() {
return (
<CohereProvider apiKey="[EXAMPLE]">
<Cohere />
</CohereProvider>
);
}
const Cohere = () => {
const { identify } = useCohere();
const [open, setOpen] = useState(false);
useEffect(() => {
identify('123', { displayName: 'John Doe' });
}, [identify]);
return open ? (
<CohereWidget
onClose={() => {
setOpen(false);
}}
/>
) : (
<SafeAreaView>
<Button title="Open support" onPress={() => setOpen(true)} />
</SafeAreaView>
);
};
Components
CohereProvider
The CohereProvider
component provides the context for the Cohere integration. It requires the apiKey
prop for authorization and takes in children
to render its child components.
Props:
- apiKey: string: The API key used to authorize the Cohere voice chat widget.
- children: React.ReactNode: The child components to render within the provider.
useCohere
The useCohere hook provides access to the Cohere context and functions. It must be used within a CohereProvider. This hook allows you to access the identify function to provide user identification information.
identify
The identify function is used to provide user identification information to the Cohere voice chat widget. It takes two arguments:
- userId: string: The unique identifier for the user.
- options?: UserAttrs: An optional object containing additional user attributes such as displayName, email, and any other custom attributes.
CohereWidget
The CohereWidget component renders the Cohere voice chat widget. It requires the onClose prop which is a callback function that gets called when the chat widget is closed by the user.
Props:
- onClose: () => void: The callback function to be called when the chat widget is closed.
License
cohere-react-native is licensed under the MIT License. See the LICENSE file for more information.