{"id":23445321,"url":"https://github.com/botpress/react-native-example","last_synced_at":"2025-04-09T23:49:05.174Z","repository":{"id":198237702,"uuid":"700043809","full_name":"botpress/react-native-example","owner":"botpress","description":null,"archived":false,"fork":false,"pushed_at":"2023-10-04T15:50:14.000Z","size":355,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T23:49:02.985Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/botpress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-03T20:46:17.000Z","updated_at":"2025-03-12T10:02:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"39310658-5634-40ee-b3c3-c58deb31a531","html_url":"https://github.com/botpress/react-native-example","commit_stats":null,"previous_names":["ptrckbp/botpresscomponent","botpress/react-native-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/botpress%2Freact-native-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/botpress%2Freact-native-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/botpress%2Freact-native-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/botpress%2Freact-native-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/botpress","download_url":"https://codeload.github.com/botpress/react-native-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131457,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-23T19:31:10.107Z","updated_at":"2025-04-09T23:49:05.148Z","avatar_url":"https://github.com/botpress.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Botpress in React Native\n\nThis is a simple example of how to use Botpress in a React Native application. We have two main components: `BpWidget` and `BpIncommingMessagesListener`.\n\n## Installation\n\nTo install the necessary dependencies, run the following command:\n\n```bash\nnpm i\n```\n\n## Running the Application\n\nTo start the application in development mode, run:\n\n```bash\nnpm run start\n```\n\n## Components\n\n### BpWidget\n\nThis component is responsible for rendering the Botpress chat widget in your application. It takes a `botConfig` prop, which is an object containing the configuration for your bot. The `botConfig` object should include the following properties:\n\n- `botId`: The ID of your bot.\n- `hostUrl`: The URL where your bot is hosted.\n- `messagingUrl`: The URL for your bot's messaging service.\n- `clientId`: The client ID for your bot.\n\nThe `BpWidget` component also takes a `onMessage` prop, which is a function that will be called whenever a message is received from the bot.\n\n### BpIncommingMessagesListener\n\nThis component listens for incoming messages from the bot and can be used from anywhere in the bot, while hidden away. It takes the same `botConfig` prop as the `BpWidget` component, as well as an `onMessage` prop. The `onMessage` function will be called whenever a message is received from the bot.\n\n## Using the Components\n\nIn your application, you can use these components as follows:\n\n```jsx\nimport BpWidget from \"./src/BpWidget\";\nimport BpIncommingMessagesListener from \"./src/BpIncommingMessagesListener\";\n\nconst botConfig = {\n  botId: \"your-bot-id\",\n  hostUrl: \"https://your-bot-host-url\",\n  messagingUrl: \"https://your-bot-messaging-url\",\n  clientId: \"your-bot-client-id\",\n};\n\nfunction App() {\n  return (\n    \u003cView\u003e\n      \u003cBpIncommingMessagesListener \n        botConfig={botConfig} \n        onMessage={(message) =\u003e console.log('Received message:', message)}\n      /\u003e\n      \u003cBpWidget \n        botConfig={botConfig} \n        onMessage={(message) =\u003e console.log('Received message:', message)}\n      /\u003e\n    \u003c/View\u003e\n  );\n}\n```\n\n## Interacting with the Bot\n\nThe `BpWidget` component exposes three methods that you can use to interact with the bot:\n\n- `sendEvent(event)`: Sends an event to the bot. The `event` parameter should be an object containing the event data.\n- `sendPayload(payload)`: Sends a payload to the bot. The `payload` parameter should be an object containing the payload data.\n- `mergeConfig(config)`: Merges the given `config` object with the current bot configuration.\n\nYou can call these methods using a ref to the `BpWidget` component:\n\n```jsx\nconst bpWidgetRef = useRef();\n\n// ...\n\n\u003cBpWidget ref={bpWidgetRef} ... /\u003e\n\n// ...\n\nbpWidgetRef.current.sendEvent({ type: 'toggle' });\nbpWidgetRef.current.sendPayload({ type: 'text', text: 'Hello, bot!' });\nbpWidgetRef.current.mergeConfig({ botName: 'New Bot Name' });\n```\n\nThat's it! You now have a fully functional Botpress chat widget in your React Native application.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbotpress%2Freact-native-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbotpress%2Freact-native-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbotpress%2Freact-native-example/lists"}